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 ++++++++++++---------- 2 files changed, 74 insertions(+), 37 deletions(-) (limited to 'crates/ra_syntax/src/grammar/expressions') 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), } } -- cgit v1.2.3