From 85cd3524e28443836658615fe40599bf10a96943 Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Thu, 14 Jan 2021 00:01:50 +0900 Subject: Add support for yiled keyword --- crates/parser/src/grammar/expressions/atom.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/parser/src/grammar/expressions/atom.rs') 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 = T![match], T![unsafe], T![return], + T![yield], T![break], T![continue], T![async], @@ -142,6 +143,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar block_expr_unchecked(p) } T![return] => return_expr(p), + T![yield] => yield_expr(p), T![continue] => continue_expr(p), T![break] => break_expr(p, r), _ => { @@ -508,6 +510,20 @@ fn return_expr(p: &mut Parser) -> CompletedMarker { } m.complete(p, RETURN_EXPR) } +// test yield_expr +// fn foo() { +// yield; +// yield 1; +// } +fn yield_expr(p: &mut Parser) -> CompletedMarker { + assert!(p.at(T![yield])); + let m = p.start(); + p.bump(T![yield]); + if p.at_ts(EXPR_FIRST) { + expr(p); + } + m.complete(p, YIELD_EXPR) +} // test continue_expr // fn foo() { -- cgit v1.2.3