diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-16 14:44:24 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-16 14:44:24 +0100 |
commit | 1216878f7be20dd0e652fb8cdc395009fdcfae07 (patch) | |
tree | 6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_syntax/src/grammar/expressions | |
parent | 39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff) | |
parent | 61f3a438d3a729a6be941bca1ff4c6a97a33f221 (diff) |
Merge #134
134: Cargo Format run r=kjeremy a=kjeremy
I'm not sure how appreciated this is but I figured I would run `cargo fmt` and see what came up.
I made sure that `cargo test` still passes.
Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/grammar/expressions')
-rw-r--r-- | crates/ra_syntax/src/grammar/expressions/atom.rs | 58 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar/expressions/mod.rs | 53 |
2 files changed, 74 insertions, 37 deletions
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::*; | |||
13 | // let _ = b"e"; | 13 | // let _ = b"e"; |
14 | // let _ = br"f"; | 14 | // let _ = br"f"; |
15 | // } | 15 | // } |
16 | pub(crate) const LITERAL_FIRST: TokenSet = | 16 | pub(crate) const LITERAL_FIRST: TokenSet = token_set![ |
17 | token_set![TRUE_KW, FALSE_KW, INT_NUMBER, FLOAT_NUMBER, BYTE, CHAR, | 17 | TRUE_KW, |
18 | STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; | 18 | FALSE_KW, |
19 | INT_NUMBER, | ||
20 | FLOAT_NUMBER, | ||
21 | BYTE, | ||
22 | CHAR, | ||
23 | STRING, | ||
24 | RAW_STRING, | ||
25 | BYTE_STRING, | ||
26 | RAW_BYTE_STRING | ||
27 | ]; | ||
19 | 28 | ||
20 | pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { | 29 | pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { |
21 | if !p.at_ts(LITERAL_FIRST) { | 30 | if !p.at_ts(LITERAL_FIRST) { |
@@ -26,15 +35,31 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { | |||
26 | Some(m.complete(p, LITERAL)) | 35 | Some(m.complete(p, LITERAL)) |
27 | } | 36 | } |
28 | 37 | ||
29 | pub(super) const ATOM_EXPR_FIRST: TokenSet = | 38 | pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![ |
30 | token_set_union![ | 39 | LITERAL_FIRST, |
31 | LITERAL_FIRST, | 40 | token_set![ |
32 | token_set![L_CURLY, L_PAREN, L_BRACK, PIPE, MOVE_KW, IF_KW, WHILE_KW, MATCH_KW, UNSAFE_KW, | 41 | L_CURLY, |
33 | RETURN_KW, IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, BREAK_KW, CONTINUE_KW, LIFETIME ], | 42 | L_PAREN, |
34 | ]; | 43 | L_BRACK, |
44 | PIPE, | ||
45 | MOVE_KW, | ||
46 | IF_KW, | ||
47 | WHILE_KW, | ||
48 | MATCH_KW, | ||
49 | UNSAFE_KW, | ||
50 | RETURN_KW, | ||
51 | IDENT, | ||
52 | SELF_KW, | ||
53 | SUPER_KW, | ||
54 | CRATE_KW, | ||
55 | COLONCOLON, | ||
56 | BREAK_KW, | ||
57 | CONTINUE_KW, | ||
58 | LIFETIME | ||
59 | ], | ||
60 | ]; | ||
35 | 61 | ||
36 | const EXPR_RECOVERY_SET: TokenSet = | 62 | const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; |
37 | token_set![LET_KW]; | ||
38 | 63 | ||
39 | pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { | 64 | pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { |
40 | match literal(p) { | 65 | match literal(p) { |
@@ -80,7 +105,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark | |||
80 | let m = p.start(); | 105 | let m = p.start(); |
81 | p.bump(); | 106 | p.bump(); |
82 | block_expr(p, Some(m)) | 107 | block_expr(p, Some(m)) |
83 | }, | 108 | } |
84 | L_CURLY => block_expr(p, None), | 109 | L_CURLY => block_expr(p, None), |
85 | RETURN_KW => return_expr(p), | 110 | RETURN_KW => return_expr(p), |
86 | CONTINUE_KW => continue_expr(p), | 111 | CONTINUE_KW => continue_expr(p), |
@@ -119,7 +144,14 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker { | |||
119 | } | 144 | } |
120 | } | 145 | } |
121 | p.expect(R_PAREN); | 146 | p.expect(R_PAREN); |
122 | m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR }) | 147 | m.complete( |
148 | p, | ||
149 | if saw_expr && !saw_comma { | ||
150 | PAREN_EXPR | ||
151 | } else { | ||
152 | TUPLE_EXPR | ||
153 | }, | ||
154 | ) | ||
123 | } | 155 | } |
124 | 156 | ||
125 | // test array_expr | 157 | // 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 @@ | |||
1 | mod atom; | 1 | mod atom; |
2 | 2 | ||
3 | use super::*; | ||
4 | pub(super) use self::atom::{literal, LITERAL_FIRST}; | ||
5 | pub(crate) use self::atom::match_arm_list; | 3 | pub(crate) use self::atom::match_arm_list; |
4 | pub(super) use self::atom::{literal, LITERAL_FIRST}; | ||
5 | use super::*; | ||
6 | 6 | ||
7 | const EXPR_FIRST: TokenSet = LHS_FIRST; | 7 | const EXPR_FIRST: TokenSet = LHS_FIRST; |
8 | 8 | ||
9 | pub(super) fn expr(p: &mut Parser) -> BlockLike { | 9 | pub(super) fn expr(p: &mut Parser) -> BlockLike { |
10 | let r = Restrictions { forbid_structs: false, prefer_stmt: false }; | 10 | let r = Restrictions { |
11 | forbid_structs: false, | ||
12 | prefer_stmt: false, | ||
13 | }; | ||
11 | expr_bp(p, r, 1) | 14 | expr_bp(p, r, 1) |
12 | } | 15 | } |
13 | 16 | ||
14 | pub(super) fn expr_stmt(p: &mut Parser) -> BlockLike { | 17 | pub(super) fn expr_stmt(p: &mut Parser) -> BlockLike { |
15 | let r = Restrictions { forbid_structs: false, prefer_stmt: true }; | 18 | let r = Restrictions { |
19 | forbid_structs: false, | ||
20 | prefer_stmt: true, | ||
21 | }; | ||
16 | expr_bp(p, r, 1) | 22 | expr_bp(p, r, 1) |
17 | } | 23 | } |
18 | 24 | ||
19 | fn expr_no_struct(p: &mut Parser) { | 25 | fn expr_no_struct(p: &mut Parser) { |
20 | let r = Restrictions { forbid_structs: true, prefer_stmt: false }; | 26 | let r = Restrictions { |
27 | forbid_structs: true, | ||
28 | prefer_stmt: false, | ||
29 | }; | ||
21 | expr_bp(p, r, 1); | 30 | expr_bp(p, r, 1); |
22 | } | 31 | } |
23 | 32 | ||
@@ -107,10 +116,8 @@ enum Op { | |||
107 | fn current_op(p: &Parser) -> (u8, Op) { | 116 | fn current_op(p: &Parser) -> (u8, Op) { |
108 | if let Some(t) = p.next3() { | 117 | if let Some(t) = p.next3() { |
109 | match t { | 118 | match t { |
110 | (L_ANGLE, L_ANGLE, EQ) => | 119 | (L_ANGLE, L_ANGLE, EQ) => return (1, Op::Composite(SHLEQ, 3)), |
111 | return (1, Op::Composite(SHLEQ, 3)), | 120 | (R_ANGLE, R_ANGLE, EQ) => return (1, Op::Composite(SHREQ, 3)), |
112 | (R_ANGLE, R_ANGLE, EQ) => | ||
113 | return (1, Op::Composite(SHREQ, 3)), | ||
114 | _ => (), | 121 | _ => (), |
115 | } | 122 | } |
116 | } | 123 | } |
@@ -201,11 +208,10 @@ fn is_block(kind: SyntaxKind) -> bool { | |||
201 | } | 208 | } |
202 | } | 209 | } |
203 | 210 | ||
204 | const LHS_FIRST: TokenSet = | 211 | const LHS_FIRST: TokenSet = token_set_union![ |
205 | token_set_union![ | 212 | token_set![AMP, STAR, EXCL, DOTDOT, MINUS], |
206 | token_set![AMP, STAR, EXCL, DOTDOT, MINUS], | 213 | atom::ATOM_EXPR_FIRST, |
207 | atom::ATOM_EXPR_FIRST, | 214 | ]; |
208 | ]; | ||
209 | 215 | ||
210 | fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { | 216 | fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { |
211 | let m; | 217 | let m; |
@@ -265,11 +271,13 @@ fn postfix_expr(p: &mut Parser, r: Restrictions, mut lhs: CompletedMarker) -> Co | |||
265 | // } | 271 | // } |
266 | L_PAREN if allow_calls => call_expr(p, lhs), | 272 | L_PAREN if allow_calls => call_expr(p, lhs), |
267 | L_BRACK if allow_calls => index_expr(p, lhs), | 273 | L_BRACK if allow_calls => index_expr(p, lhs), |
268 | DOT if p.nth(1) == IDENT => if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON { | 274 | DOT if p.nth(1) == IDENT => { |
269 | method_call_expr(p, lhs) | 275 | if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON { |
270 | } else { | 276 | method_call_expr(p, lhs) |
271 | field_expr(p, lhs) | 277 | } else { |
272 | }, | 278 | field_expr(p, lhs) |
279 | } | ||
280 | } | ||
273 | DOT if p.nth(1) == INT_NUMBER => field_expr(p, lhs), | 281 | DOT if p.nth(1) == INT_NUMBER => field_expr(p, lhs), |
274 | // test postfix_range | 282 | // test postfix_range |
275 | // fn foo() { let x = 1..; } | 283 | // fn foo() { let x = 1..; } |
@@ -318,10 +326,7 @@ fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | |||
318 | // y.bar::<T>(1, 2,); | 326 | // y.bar::<T>(1, 2,); |
319 | // } | 327 | // } |
320 | fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | 328 | fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { |
321 | assert!( | 329 | assert!(p.at(DOT) && p.nth(1) == IDENT && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON)); |
322 | p.at(DOT) && p.nth(1) == IDENT | ||
323 | && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON) | ||
324 | ); | ||
325 | let m = lhs.precede(p); | 330 | let m = lhs.precede(p); |
326 | p.bump(); | 331 | p.bump(); |
327 | name_ref(p); | 332 | name_ref(p); |
@@ -410,7 +415,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { | |||
410 | items::macro_call_after_excl(p); | 415 | items::macro_call_after_excl(p); |
411 | m.complete(p, MACRO_CALL) | 416 | m.complete(p, MACRO_CALL) |
412 | } | 417 | } |
413 | _ => m.complete(p, PATH_EXPR) | 418 | _ => m.complete(p, PATH_EXPR), |
414 | } | 419 | } |
415 | } | 420 | } |
416 | 421 | ||