aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-06-19 11:07:37 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-06-19 11:07:37 +0100
commit363f2f394e2c6423388a5e292adcccc38ee1df04 (patch)
treec5e2d9b59ce9985fc62c31b63f1bb778f38536c7 /crates/ra_parser/src/grammar
parent09864b3b217e2ad6ca8630af6faaaefd8d14e860 (diff)
parentd6533994e461dac502672c77ff27c6ca08fdc092 (diff)
Merge #1414
1414: fix: box_syntax/pattern r=matklad a=csmoe Closes #1412 r? @matklad Co-authored-by: csmoe <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar')
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs15
-rw-r--r--crates/ra_parser/src/grammar/patterns.rs3
2 files changed, 18 insertions, 0 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index 725fb99f6..41be283d0 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -74,6 +74,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
74 T![if] => if_expr(p), 74 T![if] => if_expr(p),
75 75
76 T![loop] => loop_expr(p, None), 76 T![loop] => loop_expr(p, None),
77 T![box] => box_expr(p, None),
77 T![for] => for_expr(p, None), 78 T![for] => for_expr(p, None),
78 T![while] => while_expr(p, None), 79 T![while] => while_expr(p, None),
79 T![try] => try_block_expr(p, None), 80 T![try] => try_block_expr(p, None),
@@ -507,3 +508,17 @@ fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
507 block(p); 508 block(p);
508 m.complete(p, TRY_EXPR) 509 m.complete(p, TRY_EXPR)
509} 510}
511
512// test box_expr
513// fn foo() {
514// let x = box 1i32;
515// }
516fn box_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
517 assert!(p.at(T![box]));
518 let m = m.unwrap_or_else(|| p.start());
519 p.bump();
520 if p.at_ts(EXPR_FIRST) {
521 expr(p);
522 }
523 m.complete(p, BOX_EXPR)
524}
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs
index 16ae9da63..46034942a 100644
--- a/crates/ra_parser/src/grammar/patterns.rs
+++ b/crates/ra_parser/src/grammar/patterns.rs
@@ -60,6 +60,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
60 let la1 = p.nth(1); 60 let la1 = p.nth(1);
61 if la0 == T![ref] 61 if la0 == T![ref]
62 || la0 == T![mut] 62 || la0 == T![mut]
63 || la0 == T![box]
63 || (la0 == IDENT && !(la1 == T![::] || la1 == T!['('] || la1 == T!['{'] || la1 == T![!])) 64 || (la0 == IDENT && !(la1 == T![::] || la1 == T!['('] || la1 == T!['{'] || la1 == T![!]))
64 { 65 {
65 return Some(bind_pat(p, true)); 66 return Some(bind_pat(p, true));
@@ -260,9 +261,11 @@ fn pat_list(p: &mut Parser, ket: SyntaxKind) {
260// let ref mut d = (); 261// let ref mut d = ();
261// let e @ _ = (); 262// let e @ _ = ();
262// let ref mut f @ g @ _ = (); 263// let ref mut f @ g @ _ = ();
264// let box i = Box::new(1i32);
263// } 265// }
264fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker { 266fn bind_pat(p: &mut Parser, with_at: bool) -> CompletedMarker {
265 let m = p.start(); 267 let m = p.start();
268 p.eat(T![box]);
266 p.eat(T![ref]); 269 p.eat(T![ref]);
267 p.eat(T![mut]); 270 p.eat(T![mut]);
268 name(p); 271 name(p);