aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/grammar.ron4
-rw-r--r--crates/libsyntax2/src/grammar/expressions/atom.rs39
-rw-r--r--crates/libsyntax2/src/syntax_kinds/generated.rs12
3 files changed, 54 insertions, 1 deletions
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index 2cec5b3e3..dff88cc4a 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -75,6 +75,8 @@ Grammar(
75 "for", 75 "for",
76 "loop", 76 "loop",
77 "while", 77 "while",
78 "continue",
79 "break",
78 "if", 80 "if",
79 "else", 81 "else",
80 "match", 82 "match",
@@ -161,6 +163,8 @@ Grammar(
161 "IF_EXPR", 163 "IF_EXPR",
162 "WHILE_EXPR", 164 "WHILE_EXPR",
163 "LOOP_EXPR", 165 "LOOP_EXPR",
166 "CONTINUE_EXPR",
167 "BREAK_EXPR",
164 "FOR_EXPR", 168 "FOR_EXPR",
165 "BLOCK_EXPR", 169 "BLOCK_EXPR",
166 "RETURN_EXPR", 170 "RETURN_EXPR",
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}
diff --git a/crates/libsyntax2/src/syntax_kinds/generated.rs b/crates/libsyntax2/src/syntax_kinds/generated.rs
index fc387c93d..82b6c89cf 100644
--- a/crates/libsyntax2/src/syntax_kinds/generated.rs
+++ b/crates/libsyntax2/src/syntax_kinds/generated.rs
@@ -82,6 +82,8 @@ pub enum SyntaxKind {
82 FOR_KW, 82 FOR_KW,
83 LOOP_KW, 83 LOOP_KW,
84 WHILE_KW, 84 WHILE_KW,
85 CONTINUE_KW,
86 BREAK_KW,
85 IF_KW, 87 IF_KW,
86 ELSE_KW, 88 ELSE_KW,
87 MATCH_KW, 89 MATCH_KW,
@@ -157,6 +159,8 @@ pub enum SyntaxKind {
157 IF_EXPR, 159 IF_EXPR,
158 WHILE_EXPR, 160 WHILE_EXPR,
159 LOOP_EXPR, 161 LOOP_EXPR,
162 CONTINUE_EXPR,
163 BREAK_EXPR,
160 FOR_EXPR, 164 FOR_EXPR,
161 BLOCK_EXPR, 165 BLOCK_EXPR,
162 RETURN_EXPR, 166 RETURN_EXPR,
@@ -232,6 +236,8 @@ impl SyntaxKind {
232 | FOR_KW 236 | FOR_KW
233 | LOOP_KW 237 | LOOP_KW
234 | WHILE_KW 238 | WHILE_KW
239 | CONTINUE_KW
240 | BREAK_KW
235 | IF_KW 241 | IF_KW
236 | ELSE_KW 242 | ELSE_KW
237 | MATCH_KW 243 | MATCH_KW
@@ -325,6 +331,8 @@ impl SyntaxKind {
325 FOR_KW => &SyntaxInfo { name: "FOR_KW" }, 331 FOR_KW => &SyntaxInfo { name: "FOR_KW" },
326 LOOP_KW => &SyntaxInfo { name: "LOOP_KW" }, 332 LOOP_KW => &SyntaxInfo { name: "LOOP_KW" },
327 WHILE_KW => &SyntaxInfo { name: "WHILE_KW" }, 333 WHILE_KW => &SyntaxInfo { name: "WHILE_KW" },
334 CONTINUE_KW => &SyntaxInfo { name: "CONTINUE_KW" },
335 BREAK_KW => &SyntaxInfo { name: "BREAK_KW" },
328 IF_KW => &SyntaxInfo { name: "IF_KW" }, 336 IF_KW => &SyntaxInfo { name: "IF_KW" },
329 ELSE_KW => &SyntaxInfo { name: "ELSE_KW" }, 337 ELSE_KW => &SyntaxInfo { name: "ELSE_KW" },
330 MATCH_KW => &SyntaxInfo { name: "MATCH_KW" }, 338 MATCH_KW => &SyntaxInfo { name: "MATCH_KW" },
@@ -400,6 +408,8 @@ impl SyntaxKind {
400 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" }, 408 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" },
401 WHILE_EXPR => &SyntaxInfo { name: "WHILE_EXPR" }, 409 WHILE_EXPR => &SyntaxInfo { name: "WHILE_EXPR" },
402 LOOP_EXPR => &SyntaxInfo { name: "LOOP_EXPR" }, 410 LOOP_EXPR => &SyntaxInfo { name: "LOOP_EXPR" },
411 CONTINUE_EXPR => &SyntaxInfo { name: "CONTINUE_EXPR" },
412 BREAK_EXPR => &SyntaxInfo { name: "BREAK_EXPR" },
403 FOR_EXPR => &SyntaxInfo { name: "FOR_EXPR" }, 413 FOR_EXPR => &SyntaxInfo { name: "FOR_EXPR" },
404 BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" }, 414 BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" },
405 RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" }, 415 RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" },
@@ -475,6 +485,8 @@ impl SyntaxKind {
475 "for" => FOR_KW, 485 "for" => FOR_KW,
476 "loop" => LOOP_KW, 486 "loop" => LOOP_KW,
477 "while" => WHILE_KW, 487 "while" => WHILE_KW,
488 "continue" => CONTINUE_KW,
489 "break" => BREAK_KW,
478 "if" => IF_KW, 490 "if" => IF_KW,
479 "else" => ELSE_KW, 491 "else" => ELSE_KW,
480 "match" => MATCH_KW, 492 "match" => MATCH_KW,