aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/grammar/expressions/mod.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-10-16 14:44:24 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-10-16 14:44:24 +0100
commit1216878f7be20dd0e652fb8cdc395009fdcfae07 (patch)
tree6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_syntax/src/grammar/expressions/mod.rs
parent39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff)
parent61f3a438d3a729a6be941bca1ff4c6a97a33f221 (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/mod.rs')
-rw-r--r--crates/ra_syntax/src/grammar/expressions/mod.rs53
1 files changed, 29 insertions, 24 deletions
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 @@
1mod atom; 1mod atom;
2 2
3use super::*;
4pub(super) use self::atom::{literal, LITERAL_FIRST};
5pub(crate) use self::atom::match_arm_list; 3pub(crate) use self::atom::match_arm_list;
4pub(super) use self::atom::{literal, LITERAL_FIRST};
5use super::*;
6 6
7const EXPR_FIRST: TokenSet = LHS_FIRST; 7const EXPR_FIRST: TokenSet = LHS_FIRST;
8 8
9pub(super) fn expr(p: &mut Parser) -> BlockLike { 9pub(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
14pub(super) fn expr_stmt(p: &mut Parser) -> BlockLike { 17pub(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
19fn expr_no_struct(p: &mut Parser) { 25fn 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 {
107fn current_op(p: &Parser) -> (u8, Op) { 116fn 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
204const LHS_FIRST: TokenSet = 211const 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
210fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { 216fn 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// }
320fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 328fn 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