diff options
Diffstat (limited to 'crates/parser/src/grammar/expressions/atom.rs')
-rw-r--r-- | crates/parser/src/grammar/expressions/atom.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index c7a3556a7..093a9890d 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs | |||
@@ -15,8 +15,16 @@ use super::*; | |||
15 | // let _ = b"e"; | 15 | // let _ = b"e"; |
16 | // let _ = br"f"; | 16 | // let _ = br"f"; |
17 | // } | 17 | // } |
18 | pub(crate) const LITERAL_FIRST: TokenSet = | 18 | pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[ |
19 | TokenSet::new(&[TRUE_KW, FALSE_KW, INT_NUMBER, FLOAT_NUMBER, BYTE, CHAR, STRING, BYTE_STRING]); | 19 | T![true], |
20 | T![false], | ||
21 | INT_NUMBER, | ||
22 | FLOAT_NUMBER, | ||
23 | BYTE, | ||
24 | CHAR, | ||
25 | STRING, | ||
26 | BYTE_STRING, | ||
27 | ]); | ||
20 | 28 | ||
21 | pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { | 29 | pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { |
22 | if !p.at_ts(LITERAL_FIRST) { | 30 | if !p.at_ts(LITERAL_FIRST) { |
@@ -42,6 +50,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = | |||
42 | T![match], | 50 | T![match], |
43 | T![unsafe], | 51 | T![unsafe], |
44 | T![return], | 52 | T![return], |
53 | T![yield], | ||
45 | T![break], | 54 | T![break], |
46 | T![continue], | 55 | T![continue], |
47 | T![async], | 56 | T![async], |
@@ -134,6 +143,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
134 | block_expr_unchecked(p) | 143 | block_expr_unchecked(p) |
135 | } | 144 | } |
136 | T![return] => return_expr(p), | 145 | T![return] => return_expr(p), |
146 | T![yield] => yield_expr(p), | ||
137 | T![continue] => continue_expr(p), | 147 | T![continue] => continue_expr(p), |
138 | T![break] => break_expr(p, r), | 148 | T![break] => break_expr(p, r), |
139 | _ => { | 149 | _ => { |
@@ -500,6 +510,20 @@ fn return_expr(p: &mut Parser) -> CompletedMarker { | |||
500 | } | 510 | } |
501 | m.complete(p, RETURN_EXPR) | 511 | m.complete(p, RETURN_EXPR) |
502 | } | 512 | } |
513 | // test yield_expr | ||
514 | // fn foo() { | ||
515 | // yield; | ||
516 | // yield 1; | ||
517 | // } | ||
518 | fn yield_expr(p: &mut Parser) -> CompletedMarker { | ||
519 | assert!(p.at(T![yield])); | ||
520 | let m = p.start(); | ||
521 | p.bump(T![yield]); | ||
522 | if p.at_ts(EXPR_FIRST) { | ||
523 | expr(p); | ||
524 | } | ||
525 | m.complete(p, YIELD_EXPR) | ||
526 | } | ||
503 | 527 | ||
504 | // test continue_expr | 528 | // test continue_expr |
505 | // fn foo() { | 529 | // fn foo() { |