Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/parser/src/grammar/expressions/atom.rs')
-rw-r--r--crates/parser/src/grammar/expressions/atom.rs48
1 files changed, 28 insertions, 20 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs
index 54ed5f0ba2..a678c1f3a7 100644
--- a/crates/parser/src/grammar/expressions/atom.rs
+++ b/crates/parser/src/grammar/expressions/atom.rs
@@ -51,6 +51,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
T![const],
T![continue],
T![do],
+ T![gen],
T![for],
T![if],
T![let],
@@ -100,6 +101,8 @@ pub(super) fn atom_expr(
}
T![loop] => loop_expr(p, None),
T![while] => while_expr(p, None),
+ // test try_macro_fallback 2015
+ // fn foo() { try!(Ok(())); }
T![try] => try_block_expr(p, None),
T![match] => match_expr(p),
T![return] => return_expr(p),
@@ -138,15 +141,37 @@ pub(super) fn atom_expr(
// fn f() { const { } }
// fn f() { async { } }
// fn f() { async move { } }
- T![const] | T![unsafe] | T![async] if la == T!['{'] => {
+ T![const] | T![unsafe] | T![async] | T![gen] if la == T!['{'] => {
+ let m = p.start();
+ p.bump_any();
+ stmt_list(p);
+ m.complete(p, BLOCK_EXPR)
+ }
+ // test gen_blocks 2024
+ // pub fn main() {
+ // gen { yield ""; };
+ // async gen { yield ""; };
+ // gen move { yield ""; };
+ // async gen move { yield ""; };
+ // }
+ T![async] if la == T![gen] && p.nth(2) == T!['{'] => {
+ let m = p.start();
+ p.bump(T![async]);
+ p.eat(T![gen]);
+ stmt_list(p);
+ m.complete(p, BLOCK_EXPR)
+ }
+ T![async] | T![gen] if la == T![move] && p.nth(2) == T!['{'] => {
let m = p.start();
p.bump_any();
+ p.bump(T![move]);
stmt_list(p);
m.complete(p, BLOCK_EXPR)
}
- T![async] if la == T![move] && p.nth(2) == T!['{'] => {
+ T![async] if la == T![gen] && p.nth(2) == T![move] && p.nth(3) == T!['{'] => {
let m = p.start();
p.bump(T![async]);
+ p.bump(T![gen]);
p.bump(T![move]);
stmt_list(p);
m.complete(p, BLOCK_EXPR)
@@ -355,6 +380,7 @@ fn closure_expr(p: &mut Parser<'_>) -> CompletedMarker {
p.eat(T![const]);
p.eat(T![static]);
p.eat(T![async]);
+ p.eat(T![gen]);
p.eat(T![move]);
if !p.at(T![|]) {
@@ -743,24 +769,6 @@ fn break_expr(p: &mut Parser<'_>, r: Restrictions) -> CompletedMarker {
fn try_block_expr(p: &mut Parser<'_>, m: Option<Marker>) -> CompletedMarker {
assert!(p.at(T![try]));
let m = m.unwrap_or_else(|| p.start());
- // Special-case `try!` as macro.
- // This is a hack until we do proper edition support
- if p.nth_at(1, T![!]) {
- // test try_macro_fallback
- // fn foo() { try!(Ok(())); }
- let macro_call = p.start();
- let path = p.start();
- let path_segment = p.start();
- let name_ref = p.start();
- p.bump_remap(IDENT);
- name_ref.complete(p, NAME_REF);
- path_segment.complete(p, PATH_SEGMENT);
- path.complete(p, PATH);
- let _block_like = items::macro_call_after_excl(p);
- macro_call.complete(p, MACRO_CALL);
- return m.complete(p, MACRO_EXPR);
- }
-
p.bump(T![try]);
if p.at(T!['{']) {
stmt_list(p);