mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
move lambdas
This commit is contained in:
parent
2bbd4c510d
commit
b9189ed2db
7 changed files with 106 additions and 4 deletions
|
@ -69,6 +69,7 @@ Grammar(
|
|||
"type",
|
||||
"ref",
|
||||
"let",
|
||||
"move",
|
||||
],
|
||||
contextual_keywords: [
|
||||
"auto",
|
||||
|
|
|
@ -162,6 +162,7 @@ fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> {
|
|||
let done = match p.current() {
|
||||
L_PAREN => tuple_expr(p),
|
||||
PIPE => lambda_expr(p),
|
||||
MOVE_KW if p.nth(1) == PIPE => lambda_expr(p),
|
||||
IF_KW => if_expr(p),
|
||||
_ => {
|
||||
p.err_and_bump("expected expression");
|
||||
|
@ -184,11 +185,12 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker {
|
|||
// || ();
|
||||
// || -> i32 { 92 };
|
||||
// |x| x;
|
||||
// |x: i32,| x;
|
||||
// move |x: i32,| x;
|
||||
// }
|
||||
fn lambda_expr(p: &mut Parser) -> CompletedMarker {
|
||||
assert!(p.at(PIPE));
|
||||
assert!(p.at(PIPE) || (p.at(MOVE_KW) && p.nth(1) == PIPE));
|
||||
let m = p.start();
|
||||
p.eat(MOVE_KW);
|
||||
params::param_list_opt_types(p);
|
||||
if fn_ret_type(p) {
|
||||
block(p);
|
||||
|
|
|
@ -70,6 +70,7 @@ pub enum SyntaxKind {
|
|||
TYPE_KW,
|
||||
REF_KW,
|
||||
LET_KW,
|
||||
MOVE_KW,
|
||||
AUTO_KW,
|
||||
DEFAULT_KW,
|
||||
UNION_KW,
|
||||
|
@ -235,6 +236,7 @@ impl SyntaxKind {
|
|||
TYPE_KW => &SyntaxInfo { name: "TYPE_KW" },
|
||||
REF_KW => &SyntaxInfo { name: "REF_KW" },
|
||||
LET_KW => &SyntaxInfo { name: "LET_KW" },
|
||||
MOVE_KW => &SyntaxInfo { name: "MOVE_KW" },
|
||||
AUTO_KW => &SyntaxInfo { name: "AUTO_KW" },
|
||||
DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" },
|
||||
UNION_KW => &SyntaxInfo { name: "UNION_KW" },
|
||||
|
@ -359,6 +361,7 @@ impl SyntaxKind {
|
|||
"type" => TYPE_KW,
|
||||
"ref" => REF_KW,
|
||||
"let" => LET_KW,
|
||||
"move" => MOVE_KW,
|
||||
_ => return None,
|
||||
};
|
||||
Some(kw)
|
||||
|
@ -461,6 +464,7 @@ impl SyntaxKind {
|
|||
TYPE_KW => "type",
|
||||
REF_KW => "ref",
|
||||
LET_KW => "let",
|
||||
MOVE_KW => "move",
|
||||
AUTO_KW => "auto",
|
||||
DEFAULT_KW => "default",
|
||||
UNION_KW => "union",
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
fn use struct trait enum impl true false as extern crate
|
||||
mod pub self super in where for loop while if match const
|
||||
static mut type ref let else
|
||||
static mut type ref let else move
|
||||
|
|
|
@ -55,4 +55,6 @@ WHITESPACE 1 " "
|
|||
LET_KW 3 "let"
|
||||
WHITESPACE 1 " "
|
||||
ELSE_KW 4 "else"
|
||||
WHITESPACE 1 " "
|
||||
MOVE_KW 4 "move"
|
||||
WHITESPACE 1 "\n"
|
||||
|
|
|
@ -2,5 +2,5 @@ fn foo() {
|
|||
|| ();
|
||||
|| -> i32 { 92 };
|
||||
|x| x;
|
||||
|x: i32,| x;
|
||||
move |x: i32,| x;
|
||||
}
|
93
tests/data/parser/inline/0066_lambda_expr.txt
Normal file
93
tests/data/parser/inline/0066_lambda_expr.txt
Normal file
|
@ -0,0 +1,93 @@
|
|||
FILE@[0; 79)
|
||||
FN_ITEM@[0; 79)
|
||||
FN_KW@[0; 2)
|
||||
NAME@[2; 6)
|
||||
WHITESPACE@[2; 3)
|
||||
IDENT@[3; 6) "foo"
|
||||
PARAM_LIST@[6; 9)
|
||||
L_PAREN@[6; 7)
|
||||
R_PAREN@[7; 8)
|
||||
WHITESPACE@[8; 9)
|
||||
BLOCK@[9; 79)
|
||||
L_CURLY@[9; 10)
|
||||
EXPR_STMT@[10; 26)
|
||||
LAMBDA_EXPR@[10; 20)
|
||||
PARAM_LIST@[10; 18)
|
||||
WHITESPACE@[10; 15)
|
||||
PIPE@[15; 16)
|
||||
PIPE@[16; 17)
|
||||
WHITESPACE@[17; 18)
|
||||
TUPLE_EXPR@[18; 20)
|
||||
L_PAREN@[18; 19)
|
||||
R_PAREN@[19; 20)
|
||||
SEMI@[20; 21)
|
||||
WHITESPACE@[21; 26)
|
||||
EXPR_STMT@[26; 48)
|
||||
LAMBDA_EXPR@[26; 42)
|
||||
PARAM_LIST@[26; 29)
|
||||
PIPE@[26; 27)
|
||||
PIPE@[27; 28)
|
||||
WHITESPACE@[28; 29)
|
||||
THIN_ARROW@[29; 31)
|
||||
PATH_TYPE@[31; 36)
|
||||
PATH@[31; 36)
|
||||
PATH_SEGMENT@[31; 36)
|
||||
NAME_REF@[31; 36)
|
||||
WHITESPACE@[31; 32)
|
||||
IDENT@[32; 35) "i32"
|
||||
WHITESPACE@[35; 36)
|
||||
BLOCK@[36; 42)
|
||||
L_CURLY@[36; 37)
|
||||
LITERAL@[37; 41)
|
||||
WHITESPACE@[37; 38)
|
||||
INT_NUMBER@[38; 40) "92"
|
||||
WHITESPACE@[40; 41)
|
||||
R_CURLY@[41; 42)
|
||||
SEMI@[42; 43)
|
||||
WHITESPACE@[43; 48)
|
||||
EXPR_STMT@[48; 59)
|
||||
LAMBDA_EXPR@[48; 53)
|
||||
PARAM_LIST@[48; 52)
|
||||
PIPE@[48; 49)
|
||||
PARAM@[49; 50)
|
||||
BIND_PAT@[49; 50)
|
||||
NAME@[49; 50)
|
||||
IDENT@[49; 50) "x"
|
||||
PIPE@[50; 51)
|
||||
WHITESPACE@[51; 52)
|
||||
PATH_EXPR@[52; 53)
|
||||
PATH@[52; 53)
|
||||
PATH_SEGMENT@[52; 53)
|
||||
NAME_REF@[52; 53)
|
||||
IDENT@[52; 53) "x"
|
||||
SEMI@[53; 54)
|
||||
WHITESPACE@[54; 59)
|
||||
EXPR_STMT@[59; 77)
|
||||
LAMBDA_EXPR@[59; 75)
|
||||
MOVE_KW@[59; 63)
|
||||
PARAM_LIST@[63; 74)
|
||||
WHITESPACE@[63; 64)
|
||||
PIPE@[64; 65)
|
||||
PARAM@[65; 71)
|
||||
BIND_PAT@[65; 66)
|
||||
NAME@[65; 66)
|
||||
IDENT@[65; 66) "x"
|
||||
COLON@[66; 67)
|
||||
PATH_TYPE@[67; 71)
|
||||
PATH@[67; 71)
|
||||
PATH_SEGMENT@[67; 71)
|
||||
NAME_REF@[67; 71)
|
||||
WHITESPACE@[67; 68)
|
||||
IDENT@[68; 71) "i32"
|
||||
COMMA@[71; 72)
|
||||
PIPE@[72; 73)
|
||||
WHITESPACE@[73; 74)
|
||||
PATH_EXPR@[74; 75)
|
||||
PATH@[74; 75)
|
||||
PATH_SEGMENT@[74; 75)
|
||||
NAME_REF@[74; 75)
|
||||
IDENT@[74; 75) "x"
|
||||
SEMI@[75; 76)
|
||||
WHITESPACE@[76; 77)
|
||||
R_CURLY@[77; 78)
|
||||
WHITESPACE@[78; 79)
|
Loading…
Reference in a new issue