From ccab6afabc931ff323a6d0199b157e03f6c3d180 Mon Sep 17 00:00:00 2001 From: bellau Date: Sat, 12 Feb 2022 15:17:10 +0100 Subject: [PATCH 1/7] Fix Immovable generator syntax (static ||) not recognized #11448 --- crates/parser/src/grammar/expressions/atom.rs | 4 ++++ crates/parser/src/grammar/items.rs | 2 +- .../test_data/parser/inline/ok/0106_lambda_expr.rs | 1 + .../parser/inline/ok/0106_lambda_expr.txt | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index 640caa07780..7f9b9768dad 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -74,6 +74,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar T![|] => closure_expr(p), T![move] if la == T![|] => closure_expr(p), T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p), + T![static] if la == T![|] => closure_expr(p), T![if] => if_expr(p), T![loop] => loop_expr(p, None), @@ -234,6 +235,7 @@ fn array_expr(p: &mut Parser) -> CompletedMarker { // async || {}; // move || {}; // async move || {}; +// static || {}; // } fn closure_expr(p: &mut Parser) -> CompletedMarker { assert!( @@ -241,10 +243,12 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker { || (p.at(T![move]) && p.nth(1) == T![|]) || (p.at(T![async]) && p.nth(1) == T![|]) || (p.at(T![async]) && p.nth(1) == T![move] && p.nth(2) == T![|]) + || (p.at(T![static]) && p.nth(1) == T![|]) ); let m = p.start(); p.eat(T![async]); p.eat(T![move]); + p.eat(T![static]); params::param_list_closure(p); if opt_ret_type(p) { // test lambda_ret_block diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 896efaf3757..ab3c8a8a8b5 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -230,7 +230,7 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { IDENT if p.at_contextual_kw(T![macro_rules]) && p.nth(1) == BANG => macro_rules(p, m), T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m), - T![static] => consts::static_(p, m), + T![static] if (la != PIPE ) => consts::static_(p, m), _ => return Err(m), }; diff --git a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs index 0757178239d..4d7d325395d 100644 --- a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs +++ b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs @@ -6,4 +6,5 @@ fn foo() { async || {}; move || {}; async move || {}; + static || {}; } diff --git a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt index 45717889486..0ef0ee59b71 100644 --- a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt +++ b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt @@ -135,6 +135,20 @@ SOURCE_FILE L_CURLY "{" R_CURLY "}" SEMICOLON ";" + WHITESPACE "\n " + EXPR_STMT + CLOSURE_EXPR + STATIC_KW "static" + WHITESPACE " " + PARAM_LIST + PIPE "|" + PIPE "|" + WHITESPACE " " + BLOCK_EXPR + STMT_LIST + L_CURLY "{" + R_CURLY "}" + SEMICOLON ";" WHITESPACE "\n" R_CURLY "}" WHITESPACE "\n" From 1284bc0af32c7bf772150c3e64f8a867d4f533be Mon Sep 17 00:00:00 2001 From: bellau Date: Sat, 12 Feb 2022 15:35:06 +0100 Subject: [PATCH 2/7] Fix styles --- crates/parser/src/grammar/items.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index ab3c8a8a8b5..ac39d470f87 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -230,7 +230,7 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { IDENT if p.at_contextual_kw(T![macro_rules]) && p.nth(1) == BANG => macro_rules(p, m), T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m), - T![static] if (la != PIPE ) => consts::static_(p, m), + T![static] if la != PIPE => consts::static_(p, m), _ => return Err(m), }; From 200860794651c3dcae7dced3de1fe99bea2cd692 Mon Sep 17 00:00:00 2001 From: bellau Date: Sat, 12 Feb 2022 16:07:58 +0100 Subject: [PATCH 3/7] support static move too --- crates/parser/src/grammar/expressions/atom.rs | 6 ++++-- crates/parser/src/grammar/items.rs | 2 +- .../parser/inline/ok/0106_lambda_expr.rs | 1 + .../parser/inline/ok/0106_lambda_expr.txt | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index 7f9b9768dad..76d9b39d385 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -74,7 +74,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar T![|] => closure_expr(p), T![move] if la == T![|] => closure_expr(p), T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p), - T![static] if la == T![|] => closure_expr(p), + T![static] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p), T![if] => if_expr(p), T![loop] => loop_expr(p, None), @@ -236,6 +236,7 @@ fn array_expr(p: &mut Parser) -> CompletedMarker { // move || {}; // async move || {}; // static || {}; +// static move || {}; // } fn closure_expr(p: &mut Parser) -> CompletedMarker { assert!( @@ -244,11 +245,12 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker { || (p.at(T![async]) && p.nth(1) == T![|]) || (p.at(T![async]) && p.nth(1) == T![move] && p.nth(2) == T![|]) || (p.at(T![static]) && p.nth(1) == T![|]) + || (p.at(T![static]) && p.nth(1) == T![move] && p.nth(2) == T![|]) ); let m = p.start(); p.eat(T![async]); - p.eat(T![move]); p.eat(T![static]); + p.eat(T![move]); params::param_list_closure(p); if opt_ret_type(p) { // test lambda_ret_block diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index ac39d470f87..e583ff782b6 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -230,7 +230,7 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { IDENT if p.at_contextual_kw(T![macro_rules]) && p.nth(1) == BANG => macro_rules(p, m), T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m), - T![static] if la != PIPE => consts::static_(p, m), + T![static] if (la != PIPE && la != T![move] ) => consts::static_(p, m), _ => return Err(m), }; diff --git a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs index 4d7d325395d..7d19891259f 100644 --- a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs +++ b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs @@ -7,4 +7,5 @@ fn foo() { move || {}; async move || {}; static || {}; + static move || {}; } diff --git a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt index 0ef0ee59b71..9b4c5d52995 100644 --- a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt +++ b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt @@ -149,6 +149,22 @@ SOURCE_FILE L_CURLY "{" R_CURLY "}" SEMICOLON ";" + WHITESPACE "\n " + EXPR_STMT + CLOSURE_EXPR + STATIC_KW "static" + WHITESPACE " " + MOVE_KW "move" + WHITESPACE " " + PARAM_LIST + PIPE "|" + PIPE "|" + WHITESPACE " " + BLOCK_EXPR + STMT_LIST + L_CURLY "{" + R_CURLY "}" + SEMICOLON ";" WHITESPACE "\n" R_CURLY "}" WHITESPACE "\n" From 3ed19d54db4b85374b13ae06d9a6047d0a26f2d9 Mon Sep 17 00:00:00 2001 From: bellau Date: Sat, 12 Feb 2022 17:31:17 +0100 Subject: [PATCH 4/7] Fix style --- crates/parser/src/grammar/items.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index e583ff782b6..066e809c148 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -230,7 +230,7 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { IDENT if p.at_contextual_kw(T![macro_rules]) && p.nth(1) == BANG => macro_rules(p, m), T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m), - T![static] if (la != PIPE && la != T![move] ) => consts::static_(p, m), + T![static] if (la != PIPE && la != T![move]) => consts::static_(p, m), _ => return Err(m), }; From 0a18a050b50da53145e43fea9b403eec23ca36c7 Mon Sep 17 00:00:00 2001 From: bellau Date: Sun, 13 Feb 2022 09:09:44 +0100 Subject: [PATCH 5/7] fix handle static async and static async move --- crates/parser/src/grammar/expressions/atom.rs | 19 +++++++++-- crates/parser/src/grammar/items.rs | 2 +- .../parser/inline/ok/0106_lambda_expr.rs | 2 ++ .../parser/inline/ok/0106_lambda_expr.txt | 34 +++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index 76d9b39d385..b4d88f8d0ed 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -74,7 +74,14 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar T![|] => closure_expr(p), T![move] if la == T![|] => closure_expr(p), T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p), - T![static] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p), + T![static] + if la == T![|] + || (la == T![move] && p.nth(2) == T![|]) + || (la == T![async] && p.nth(2) == T![|]) + || (la == T![async] && p.nth(2) == T![move] && p.nth(3) == T![|]) => + { + closure_expr(p) + } T![if] => if_expr(p), T![loop] => loop_expr(p, None), @@ -237,6 +244,8 @@ fn array_expr(p: &mut Parser) -> CompletedMarker { // async move || {}; // static || {}; // static move || {}; +// static async || {}; +// static async move || {}; // } fn closure_expr(p: &mut Parser) -> CompletedMarker { assert!( @@ -246,10 +255,15 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker { || (p.at(T![async]) && p.nth(1) == T![move] && p.nth(2) == T![|]) || (p.at(T![static]) && p.nth(1) == T![|]) || (p.at(T![static]) && p.nth(1) == T![move] && p.nth(2) == T![|]) + || (p.at(T![static]) && p.nth(1) == T![async] && p.nth(2) == T![|]) + || (p.at(T![static]) + && p.nth(1) == T![async] + && p.nth(2) == T![move] + && p.nth(3) == T![|]) ); let m = p.start(); - p.eat(T![async]); p.eat(T![static]); + p.eat(T![async]); p.eat(T![move]); params::param_list_closure(p); if opt_ret_type(p) { @@ -257,6 +271,7 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker { // fn main() { || -> i32 { 92 }(); } block_expr(p); } else if p.at_ts(EXPR_FIRST) { + println!("gg"); expr(p); } else { p.error("expected expression"); diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 066e809c148..c9e5d42392e 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -230,7 +230,7 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { IDENT if p.at_contextual_kw(T![macro_rules]) && p.nth(1) == BANG => macro_rules(p, m), T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m), - T![static] if (la != PIPE && la != T![move]) => consts::static_(p, m), + T![static] if (la != PIPE && la != T![move] && la != T![async]) => consts::static_(p, m), _ => return Err(m), }; diff --git a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs index 7d19891259f..d01f9216642 100644 --- a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs +++ b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.rs @@ -8,4 +8,6 @@ fn foo() { async move || {}; static || {}; static move || {}; + static async || {}; + static async move || {}; } diff --git a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt index 9b4c5d52995..bc54b018697 100644 --- a/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt +++ b/crates/parser/test_data/parser/inline/ok/0106_lambda_expr.txt @@ -165,6 +165,40 @@ SOURCE_FILE L_CURLY "{" R_CURLY "}" SEMICOLON ";" + WHITESPACE "\n " + EXPR_STMT + CLOSURE_EXPR + STATIC_KW "static" + WHITESPACE " " + ASYNC_KW "async" + WHITESPACE " " + PARAM_LIST + PIPE "|" + PIPE "|" + WHITESPACE " " + BLOCK_EXPR + STMT_LIST + L_CURLY "{" + R_CURLY "}" + SEMICOLON ";" + WHITESPACE "\n " + EXPR_STMT + CLOSURE_EXPR + STATIC_KW "static" + WHITESPACE " " + ASYNC_KW "async" + WHITESPACE " " + MOVE_KW "move" + WHITESPACE " " + PARAM_LIST + PIPE "|" + PIPE "|" + WHITESPACE " " + BLOCK_EXPR + STMT_LIST + L_CURLY "{" + R_CURLY "}" + SEMICOLON ";" WHITESPACE "\n" R_CURLY "}" WHITESPACE "\n" From dc68b894692d309e71d9b639ac6325a9d1cb67e0 Mon Sep 17 00:00:00 2001 From: bellau Date: Sun, 13 Feb 2022 09:11:35 +0100 Subject: [PATCH 6/7] oops, remove println --- crates/parser/src/grammar/expressions/atom.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index b4d88f8d0ed..53dbbfea754 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -271,7 +271,6 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker { // fn main() { || -> i32 { 92 }(); } block_expr(p); } else if p.at_ts(EXPR_FIRST) { - println!("gg"); expr(p); } else { p.error("expected expression"); From 06452cd102dc78df4e26eeacfb8d0e3cf8a2b711 Mon Sep 17 00:00:00 2001 From: bellau Date: Mon, 14 Feb 2022 07:41:50 +0100 Subject: [PATCH 7/7] Fix style --- crates/parser/src/grammar/expressions/atom.rs | 12 ++++-------- crates/parser/src/grammar/items.rs | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index 53dbbfea754..4b7a1b31fbd 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -72,14 +72,10 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar T!['('] => tuple_expr(p), T!['['] => array_expr(p), T![|] => closure_expr(p), - T![move] if la == T![|] => closure_expr(p), - T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => closure_expr(p), - T![static] - if la == T![|] - || (la == T![move] && p.nth(2) == T![|]) - || (la == T![async] && p.nth(2) == T![|]) - || (la == T![async] && p.nth(2) == T![move] && p.nth(3) == T![|]) => - { + T![static] | T![async] | T![move] if la == T![|] => closure_expr(p), + T![static] | T![async] if la == T![move] && p.nth(2) == T![|] => closure_expr(p), + T![static] if la == T![async] && p.nth(2) == T![|] => closure_expr(p), + T![static] if la == T![async] && p.nth(2) == T![move] && p.nth(3) == T![|] => { closure_expr(p) } T![if] => if_expr(p), diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index c9e5d42392e..36d13cc9773 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -230,7 +230,7 @@ fn opt_item_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { IDENT if p.at_contextual_kw(T![macro_rules]) && p.nth(1) == BANG => macro_rules(p, m), T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m), - T![static] if (la != PIPE && la != T![move] && la != T![async]) => consts::static_(p, m), + T![static] if (la == IDENT || la == T![_] || la == T![mut]) => consts::static_(p, m), _ => return Err(m), };