From 61f3a438d3a729a6be941bca1ff4c6a97a33f221 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Mon, 15 Oct 2018 17:44:23 -0400 Subject: Cargo Format Run `cargo fmt` and ignore generated files --- crates/ra_syntax/src/grammar/expressions/atom.rs | 58 ++++++++++++++++++------ crates/ra_syntax/src/grammar/expressions/mod.rs | 53 ++++++++++++---------- crates/ra_syntax/src/grammar/items/mod.rs | 45 +++++++++--------- crates/ra_syntax/src/grammar/items/traits.rs | 1 - crates/ra_syntax/src/grammar/mod.rs | 31 +++++-------- crates/ra_syntax/src/grammar/params.rs | 13 ++---- crates/ra_syntax/src/grammar/paths.rs | 2 +- crates/ra_syntax/src/grammar/patterns.rs | 22 ++++----- crates/ra_syntax/src/grammar/type_params.rs | 11 ++--- crates/ra_syntax/src/grammar/types.rs | 18 ++++---- 10 files changed, 137 insertions(+), 117 deletions(-) (limited to 'crates/ra_syntax/src/grammar') diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index e21de68c5..11f766d33 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs @@ -13,9 +13,18 @@ use super::*; // let _ = b"e"; // let _ = br"f"; // } -pub(crate) const LITERAL_FIRST: TokenSet = - token_set![TRUE_KW, FALSE_KW, INT_NUMBER, FLOAT_NUMBER, BYTE, CHAR, - STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; +pub(crate) const LITERAL_FIRST: TokenSet = token_set![ + TRUE_KW, + FALSE_KW, + INT_NUMBER, + FLOAT_NUMBER, + BYTE, + CHAR, + STRING, + RAW_STRING, + BYTE_STRING, + RAW_BYTE_STRING +]; pub(crate) fn literal(p: &mut Parser) -> Option { if !p.at_ts(LITERAL_FIRST) { @@ -26,15 +35,31 @@ pub(crate) fn literal(p: &mut Parser) -> Option { Some(m.complete(p, LITERAL)) } -pub(super) const ATOM_EXPR_FIRST: TokenSet = - token_set_union![ - LITERAL_FIRST, - token_set![L_CURLY, L_PAREN, L_BRACK, PIPE, MOVE_KW, IF_KW, WHILE_KW, MATCH_KW, UNSAFE_KW, - RETURN_KW, IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, BREAK_KW, CONTINUE_KW, LIFETIME ], - ]; +pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![ + LITERAL_FIRST, + token_set![ + L_CURLY, + L_PAREN, + L_BRACK, + PIPE, + MOVE_KW, + IF_KW, + WHILE_KW, + MATCH_KW, + UNSAFE_KW, + RETURN_KW, + IDENT, + SELF_KW, + SUPER_KW, + CRATE_KW, + COLONCOLON, + BREAK_KW, + CONTINUE_KW, + LIFETIME + ], +]; -const EXPR_RECOVERY_SET: TokenSet = - token_set![LET_KW]; +const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option { match literal(p) { @@ -80,7 +105,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option block_expr(p, None), RETURN_KW => return_expr(p), CONTINUE_KW => continue_expr(p), @@ -119,7 +144,14 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker { } } p.expect(R_PAREN); - m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR }) + m.complete( + p, + if saw_expr && !saw_comma { + PAREN_EXPR + } else { + TUPLE_EXPR + }, + ) } // test array_expr diff --git a/crates/ra_syntax/src/grammar/expressions/mod.rs b/crates/ra_syntax/src/grammar/expressions/mod.rs index 20e0fa328..60c8602f9 100644 --- a/crates/ra_syntax/src/grammar/expressions/mod.rs +++ b/crates/ra_syntax/src/grammar/expressions/mod.rs @@ -1,23 +1,32 @@ mod atom; -use super::*; -pub(super) use self::atom::{literal, LITERAL_FIRST}; pub(crate) use self::atom::match_arm_list; +pub(super) use self::atom::{literal, LITERAL_FIRST}; +use super::*; const EXPR_FIRST: TokenSet = LHS_FIRST; pub(super) fn expr(p: &mut Parser) -> BlockLike { - let r = Restrictions { forbid_structs: false, prefer_stmt: false }; + let r = Restrictions { + forbid_structs: false, + prefer_stmt: false, + }; expr_bp(p, r, 1) } pub(super) fn expr_stmt(p: &mut Parser) -> BlockLike { - let r = Restrictions { forbid_structs: false, prefer_stmt: true }; + let r = Restrictions { + forbid_structs: false, + prefer_stmt: true, + }; expr_bp(p, r, 1) } fn expr_no_struct(p: &mut Parser) { - let r = Restrictions { forbid_structs: true, prefer_stmt: false }; + let r = Restrictions { + forbid_structs: true, + prefer_stmt: false, + }; expr_bp(p, r, 1); } @@ -107,10 +116,8 @@ enum Op { fn current_op(p: &Parser) -> (u8, Op) { if let Some(t) = p.next3() { match t { - (L_ANGLE, L_ANGLE, EQ) => - return (1, Op::Composite(SHLEQ, 3)), - (R_ANGLE, R_ANGLE, EQ) => - return (1, Op::Composite(SHREQ, 3)), + (L_ANGLE, L_ANGLE, EQ) => return (1, Op::Composite(SHLEQ, 3)), + (R_ANGLE, R_ANGLE, EQ) => return (1, Op::Composite(SHREQ, 3)), _ => (), } } @@ -201,11 +208,10 @@ fn is_block(kind: SyntaxKind) -> bool { } } -const LHS_FIRST: TokenSet = - token_set_union![ - token_set![AMP, STAR, EXCL, DOTDOT, MINUS], - atom::ATOM_EXPR_FIRST, - ]; +const LHS_FIRST: TokenSet = token_set_union![ + token_set![AMP, STAR, EXCL, DOTDOT, MINUS], + atom::ATOM_EXPR_FIRST, +]; fn lhs(p: &mut Parser, r: Restrictions) -> Option { let m; @@ -265,11 +271,13 @@ fn postfix_expr(p: &mut Parser, r: Restrictions, mut lhs: CompletedMarker) -> Co // } L_PAREN if allow_calls => call_expr(p, lhs), L_BRACK if allow_calls => index_expr(p, lhs), - DOT if p.nth(1) == IDENT => if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON { - method_call_expr(p, lhs) - } else { - field_expr(p, lhs) - }, + DOT if p.nth(1) == IDENT => { + if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON { + method_call_expr(p, lhs) + } else { + field_expr(p, lhs) + } + } DOT if p.nth(1) == INT_NUMBER => field_expr(p, lhs), // test postfix_range // fn foo() { let x = 1..; } @@ -318,10 +326,7 @@ fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { // y.bar::(1, 2,); // } fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { - assert!( - p.at(DOT) && p.nth(1) == IDENT - && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON) - ); + assert!(p.at(DOT) && p.nth(1) == IDENT && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON)); let m = lhs.precede(p); p.bump(); name_ref(p); @@ -410,7 +415,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { items::macro_call_after_excl(p); m.complete(p, MACRO_CALL) } - _ => m.complete(p, PATH_EXPR) + _ => m.complete(p, PATH_EXPR), } } diff --git a/crates/ra_syntax/src/grammar/items/mod.rs b/crates/ra_syntax/src/grammar/items/mod.rs index 2567313ab..dc4742bce 100644 --- a/crates/ra_syntax/src/grammar/items/mod.rs +++ b/crates/ra_syntax/src/grammar/items/mod.rs @@ -1,16 +1,15 @@ - mod consts; mod nominal; mod traits; mod use_item; -use super::*; pub(crate) use self::{ - expressions::{named_field_list, match_arm_list}, + expressions::{match_arm_list, named_field_list}, nominal::{enum_variant_list, named_field_def_list}, - traits::{trait_item_list, impl_item_list}, + traits::{impl_item_list, trait_item_list}, use_item::use_tree_list, }; +use super::*; // test mod_contents // fn foo() {} @@ -26,12 +25,14 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { } pub(super) enum ItemFlavor { - Mod, Trait + Mod, + Trait, } -const ITEM_RECOVERY_SET: TokenSet = - token_set![FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, - MOD_KW, PUB_KW, CRATE_KW]; +const ITEM_RECOVERY_SET: TokenSet = token_set![ + FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, + CRATE_KW +]; pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { let m = p.start(); @@ -153,10 +154,12 @@ pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem { traits::impl_item(p); IMPL_ITEM } - _ => return if has_mods { - MaybeItem::Modifiers - } else { - MaybeItem::None + _ => { + return if has_mods { + MaybeItem::Modifiers + } else { + MaybeItem::None + } } }; @@ -194,7 +197,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option { if p.at(SEMI) { p.err_and_bump( "expected item, found `;`\n\ - consider removing this semicolon" + consider removing this semicolon", ); } STRUCT_DEF @@ -227,7 +230,9 @@ fn items_without_modifiers(p: &mut Parser) -> Option { } // test extern_block // extern {} - EXTERN_KW if la == L_CURLY || ((la == STRING || la == RAW_STRING) && p.nth(2) == L_CURLY) => { + EXTERN_KW + if la == L_CURLY || ((la == STRING || la == RAW_STRING) && p.nth(2) == L_CURLY) => + { abi(p); extern_item_list(p); EXTERN_BLOCK @@ -267,10 +272,8 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) { if p.at(L_PAREN) { match flavor { - ItemFlavor::Mod => - params::param_list(p), - ItemFlavor::Trait => - params::param_list_opt_patterns(p), + ItemFlavor::Mod => params::param_list(p), + ItemFlavor::Trait => params::param_list_opt_patterns(p), } } else { p.error("expected function arguments"); @@ -361,7 +364,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { _ => { p.error("expected `{`, `[`, `(`"); BlockLike::NotBlock - }, + } }; flavor @@ -385,9 +388,9 @@ pub(crate) fn token_tree(p: &mut Parser) { return; } R_PAREN | R_BRACK => p.err_and_bump("unmatched brace"), - _ => p.bump() + _ => p.bump(), } - }; + } p.expect(closing_paren_kind); m.complete(p, TOKEN_TREE); } diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs index 5dfdb470c..31258c253 100644 --- a/crates/ra_syntax/src/grammar/items/traits.rs +++ b/crates/ra_syntax/src/grammar/items/traits.rs @@ -128,4 +128,3 @@ pub(crate) fn impl_type(p: &mut Parser) { } types::type_(p); } - diff --git a/crates/ra_syntax/src/grammar/mod.rs b/crates/ra_syntax/src/grammar/mod.rs index 1199ba230..c87564073 100644 --- a/crates/ra_syntax/src/grammar/mod.rs +++ b/crates/ra_syntax/src/grammar/mod.rs @@ -31,28 +31,18 @@ mod type_args; mod type_params; mod types; -use crate::{ - token_set::TokenSet, - parser_api::{Marker, CompletedMarker, Parser}, - SyntaxKind::{self, *}, -}; pub(crate) use self::{ - expressions::{ - block, - }, + expressions::block, items::{ - enum_variant_list, - extern_item_list, - impl_item_list, - match_arm_list, - mod_item_list, - named_field_def_list, - named_field_list, - token_tree, - trait_item_list, - use_tree_list, + enum_variant_list, extern_item_list, impl_item_list, match_arm_list, mod_item_list, + named_field_def_list, named_field_list, token_tree, trait_item_list, use_tree_list, }, }; +use crate::{ + parser_api::{CompletedMarker, Marker, Parser}, + token_set::TokenSet, + SyntaxKind::{self, *}, +}; pub(crate) fn root(p: &mut Parser) { let m = p.start(); @@ -61,7 +51,6 @@ pub(crate) fn root(p: &mut Parser) { m.complete(p, ROOT); } - #[derive(Clone, Copy, PartialEq, Eq)] enum BlockLike { Block, @@ -69,7 +58,9 @@ enum BlockLike { } impl BlockLike { - fn is_block(self) -> bool { self == BlockLike::Block } + fn is_block(self) -> bool { + self == BlockLike::Block + } } fn opt_visibility(p: &mut Parser) { diff --git a/crates/ra_syntax/src/grammar/params.rs b/crates/ra_syntax/src/grammar/params.rs index 903c25939..b71a72ca3 100644 --- a/crates/ra_syntax/src/grammar/params.rs +++ b/crates/ra_syntax/src/grammar/params.rs @@ -61,12 +61,8 @@ fn list_(p: &mut Parser, flavor: Flavor) { m.complete(p, PARAM_LIST); } - const VALUE_PARAMETER_FIRST: TokenSet = - token_set_union![ - patterns::PATTERN_FIRST, - types::TYPE_FIRST, - ]; + token_set_union![patterns::PATTERN_FIRST, types::TYPE_FIRST,]; fn value_parameter(p: &mut Parser, flavor: Flavor) { let m = p.start(); @@ -76,7 +72,7 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) { if p.at(COLON) || flavor.type_required() { types::ascription(p) } - }, + } // test value_parameters_no_patterns // type F = Box; Flavor::OptionalPattern => { @@ -86,13 +82,14 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) { let la3 = p.nth(3); if la0 == IDENT && la1 == COLON || la0 == AMP && la1 == IDENT && la2 == COLON - || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON { + || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON + { patterns::pattern(p); types::ascription(p); } else { types::type_(p); } - }, + } } m.complete(p, PARAM); } diff --git a/crates/ra_syntax/src/grammar/paths.rs b/crates/ra_syntax/src/grammar/paths.rs index b6d44d53a..a35a339cc 100644 --- a/crates/ra_syntax/src/grammar/paths.rs +++ b/crates/ra_syntax/src/grammar/paths.rs @@ -97,7 +97,7 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) { } else { type_args::opt_type_arg_list(p, false) } - }, + } Mode::Expr => type_args::opt_type_arg_list(p, true), } } diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs index 420bae7a7..9d35dbb3d 100644 --- a/crates/ra_syntax/src/grammar/patterns.rs +++ b/crates/ra_syntax/src/grammar/patterns.rs @@ -1,11 +1,10 @@ use super::*; -pub(super) const PATTERN_FIRST: TokenSet = - token_set_union![ - token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE], - expressions::LITERAL_FIRST, - paths::PATH_FIRST, - ]; +pub(super) const PATTERN_FIRST: TokenSet = token_set_union![ + token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE], + expressions::LITERAL_FIRST, + paths::PATH_FIRST, +]; pub(super) fn pattern(p: &mut Parser) { pattern_r(p, PAT_RECOVERY_SET) @@ -29,12 +28,13 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) { const PAT_RECOVERY_SET: TokenSet = token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA]; - fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { let la0 = p.nth(0); let la1 = p.nth(1); - if la0 == REF_KW || la0 == MUT_KW - || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY)) { + if la0 == REF_KW + || la0 == MUT_KW + || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY)) + { return Some(bind_pat(p, true)); } if paths::is_path_start(p) { @@ -87,7 +87,7 @@ fn path_pat(p: &mut Parser) -> CompletedMarker { field_pat_list(p); STRUCT_PAT } - _ => PATH_PAT + _ => PATH_PAT, }; m.complete(p, kind) } @@ -195,7 +195,7 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) { break; } pattern(p) - }, + } } if !p.at(ket) { p.expect(COMMA); diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/grammar/type_params.rs index 79bc95ce4..79f5036b4 100644 --- a/crates/ra_syntax/src/grammar/type_params.rs +++ b/crates/ra_syntax/src/grammar/type_params.rs @@ -72,12 +72,8 @@ pub(super) fn bounds_without_colon(p: &mut Parser) { p.eat(QUESTION); match p.current() { LIFETIME => p.bump(), - FOR_KW => { - types::for_type(p) - } - _ if paths::is_path_start(p) => { - types::path_type(p) - } + FOR_KW => types::for_type(p), + _ if paths::is_path_start(p) => types::path_type(p), _ => break, } if has_paren { @@ -104,7 +100,7 @@ pub(super) fn opt_where_clause(p: &mut Parser) { p.bump(); loop { if !(paths::is_path_start(p) || p.current() == LIFETIME) { - break + break; } where_predicate(p); if p.current() != L_CURLY && p.current() != SEMI { @@ -130,7 +126,6 @@ fn where_predicate(p: &mut Parser) { } else { p.error("expected colon") } - } m.complete(p, WHERE_PRED); } diff --git a/crates/ra_syntax/src/grammar/types.rs b/crates/ra_syntax/src/grammar/types.rs index 27e5b086e..f308aef89 100644 --- a/crates/ra_syntax/src/grammar/types.rs +++ b/crates/ra_syntax/src/grammar/types.rs @@ -1,15 +1,14 @@ use super::*; -pub(super) const TYPE_FIRST: TokenSet = - token_set_union![ - token_set![ - L_PAREN, EXCL, STAR, L_BRACK, AMP, UNDERSCORE, FN_KW, UNSAFE_KW, EXTERN_KW, FOR_KW, IMPL_KW, DYN_KW, L_ANGLE, - ], - paths::PATH_FIRST, - ]; +pub(super) const TYPE_FIRST: TokenSet = token_set_union![ + token_set![ + L_PAREN, EXCL, STAR, L_BRACK, AMP, UNDERSCORE, FN_KW, UNSAFE_KW, EXTERN_KW, FOR_KW, + IMPL_KW, DYN_KW, L_ANGLE, + ], + paths::PATH_FIRST, +]; -const TYPE_RECOVERY_SET: TokenSet = - token_set![R_PAREN, COMMA]; +const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA]; pub(super) fn type_(p: &mut Parser) { match p.current() { @@ -200,7 +199,6 @@ pub(super) fn for_type(p: &mut Parser) { FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), _ if paths::is_path_start(p) => path_type_(p, false), _ => p.error("expected a path"), - } m.complete(p, FOR_TYPE); } -- cgit v1.2.3