aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/grammar/expressions/atom.rs
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-10-15 22:44:23 +0100
committerJeremy A. Kolb <[email protected]>2018-10-16 14:41:10 +0100
commit61f3a438d3a729a6be941bca1ff4c6a97a33f221 (patch)
tree6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_syntax/src/grammar/expressions/atom.rs
parent39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff)
Cargo Format
Run `cargo fmt` and ignore generated files
Diffstat (limited to 'crates/ra_syntax/src/grammar/expressions/atom.rs')
-rw-r--r--crates/ra_syntax/src/grammar/expressions/atom.rs58
1 files changed, 45 insertions, 13 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// }
16pub(crate) const LITERAL_FIRST: TokenSet = 16pub(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
20pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { 29pub(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
29pub(super) const ATOM_EXPR_FIRST: TokenSet = 38pub(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
36const EXPR_RECOVERY_SET: TokenSet = 62const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
37 token_set![LET_KW];
38 63
39pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { 64pub(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