aboutsummaryrefslogtreecommitdiff
path: root/crates/parser/src/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'crates/parser/src/grammar')
-rw-r--r--crates/parser/src/grammar/expressions/atom.rs16
-rw-r--r--crates/parser/src/grammar/paths.rs6
2 files changed, 21 insertions, 1 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs
index d61950b96..093a9890d 100644
--- a/crates/parser/src/grammar/expressions/atom.rs
+++ b/crates/parser/src/grammar/expressions/atom.rs
@@ -50,6 +50,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
50 T![match], 50 T![match],
51 T![unsafe], 51 T![unsafe],
52 T![return], 52 T![return],
53 T![yield],
53 T![break], 54 T![break],
54 T![continue], 55 T![continue],
55 T![async], 56 T![async],
@@ -142,6 +143,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
142 block_expr_unchecked(p) 143 block_expr_unchecked(p)
143 } 144 }
144 T![return] => return_expr(p), 145 T![return] => return_expr(p),
146 T![yield] => yield_expr(p),
145 T![continue] => continue_expr(p), 147 T![continue] => continue_expr(p),
146 T![break] => break_expr(p, r), 148 T![break] => break_expr(p, r),
147 _ => { 149 _ => {
@@ -508,6 +510,20 @@ fn return_expr(p: &mut Parser) -> CompletedMarker {
508 } 510 }
509 m.complete(p, RETURN_EXPR) 511 m.complete(p, RETURN_EXPR)
510} 512}
513// test yield_expr
514// fn foo() {
515// yield;
516// yield 1;
517// }
518fn 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}
511 527
512// test continue_expr 528// test continue_expr
513// fn foo() { 529// fn foo() {
diff --git a/crates/parser/src/grammar/paths.rs b/crates/parser/src/grammar/paths.rs
index 5d297e2d6..b10f48fe1 100644
--- a/crates/parser/src/grammar/paths.rs
+++ b/crates/parser/src/grammar/paths.rs
@@ -82,7 +82,11 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
82 } 82 }
83 // test crate_path 83 // test crate_path
84 // use crate::foo; 84 // use crate::foo;
85 T![self] | T![super] | T![crate] => p.bump_any(), 85 T![self] | T![super] | T![crate] => {
86 let m = p.start();
87 p.bump_any();
88 m.complete(p, NAME_REF);
89 }
86 _ => { 90 _ => {
87 p.err_recover("expected identifier", items::ITEM_RECOVERY_SET); 91 p.err_recover("expected identifier", items::ITEM_RECOVERY_SET);
88 if empty { 92 if empty {