aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/grammar/expressions/atom.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/grammar/expressions/atom.rs')
-rw-r--r--crates/libsyntax2/src/grammar/expressions/atom.rs39
1 files changed, 38 insertions, 1 deletions
diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs
index 57a887f84..9f470d561 100644
--- a/crates/libsyntax2/src/grammar/expressions/atom.rs
+++ b/crates/libsyntax2/src/grammar/expressions/atom.rs
@@ -30,7 +30,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
30 token_set_union![ 30 token_set_union![
31 LITERAL_FIRST, 31 LITERAL_FIRST,
32 token_set![L_PAREN, PIPE, MOVE_KW, IF_KW, WHILE_KW, MATCH_KW, UNSAFE_KW, L_CURLY, RETURN_KW, 32 token_set![L_PAREN, PIPE, MOVE_KW, IF_KW, WHILE_KW, MATCH_KW, UNSAFE_KW, L_CURLY, RETURN_KW,
33 IDENT, SELF_KW, SUPER_KW, COLONCOLON ], 33 IDENT, SELF_KW, SUPER_KW, COLONCOLON, BREAK_KW, CONTINUE_KW ],
34 ]; 34 ];
35 35
36pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { 36pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
@@ -55,6 +55,8 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
55 UNSAFE_KW if la == L_CURLY => block_expr(p), 55 UNSAFE_KW if la == L_CURLY => block_expr(p),
56 L_CURLY => block_expr(p), 56 L_CURLY => block_expr(p),
57 RETURN_KW => return_expr(p), 57 RETURN_KW => return_expr(p),
58 CONTINUE_KW => continue_expr(p),
59 BREAK_KW => break_expr(p),
58 _ => { 60 _ => {
59 p.err_and_bump("expected expression"); 61 p.err_and_bump("expected expression");
60 return None; 62 return None;
@@ -346,3 +348,38 @@ fn return_expr(p: &mut Parser) -> CompletedMarker {
346 } 348 }
347 m.complete(p, RETURN_EXPR) 349 m.complete(p, RETURN_EXPR)
348} 350}
351
352// test continue_expr
353// fn foo() {
354// loop {
355// continue;
356// continue 'l;
357// }
358// }
359fn continue_expr(p: &mut Parser) -> CompletedMarker {
360 assert!(p.at(CONTINUE_KW));
361 let m = p.start();
362 p.bump();
363 p.eat(LIFETIME);
364 m.complete(p, CONTINUE_EXPR)
365}
366
367// test break_expr
368// fn foo() {
369// loop {
370// break;
371// break 'l;
372// break 92;
373// break 'l 92;
374// }
375// }
376fn break_expr(p: &mut Parser) -> CompletedMarker {
377 assert!(p.at(BREAK_KW));
378 let m = p.start();
379 p.bump();
380 p.eat(LIFETIME);
381 if EXPR_FIRST.contains(p.current()) {
382 expr(p);
383 }
384 m.complete(p, BREAK_EXPR)
385}