aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-31 22:30:17 +0100
committerAleksey Kladov <[email protected]>2018-07-31 22:30:17 +0100
commitb9189ed2db8cb1934e677a17fcc6282c66306df1 (patch)
tree1456403c6eac7820c6b6760ccc6900326aedc792
parent2bbd4c510d2da5c78f566b28e90548102bb107dc (diff)
move lambdas
-rw-r--r--src/grammar.ron1
-rw-r--r--src/grammar/expressions.rs6
-rw-r--r--src/syntax_kinds/generated.rs4
-rw-r--r--tests/data/lexer/0011_keywords.rs2
-rw-r--r--tests/data/lexer/0011_keywords.txt2
-rw-r--r--tests/data/parser/inline/0066_lambda_expr.rs (renamed from tests/data/parser/inline/0063_lambda_expr.rs)2
-rw-r--r--tests/data/parser/inline/0066_lambda_expr.txt93
7 files changed, 106 insertions, 4 deletions
diff --git a/src/grammar.ron b/src/grammar.ron
index 782771830..b4c121f4d 100644
--- a/src/grammar.ron
+++ b/src/grammar.ron
@@ -69,6 +69,7 @@ Grammar(
69 "type", 69 "type",
70 "ref", 70 "ref",
71 "let", 71 "let",
72 "move",
72 ], 73 ],
73 contextual_keywords: [ 74 contextual_keywords: [
74 "auto", 75 "auto",
diff --git a/src/grammar/expressions.rs b/src/grammar/expressions.rs
index c638e8b99..c0eb0e756 100644
--- a/src/grammar/expressions.rs
+++ b/src/grammar/expressions.rs
@@ -162,6 +162,7 @@ fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> {
162 let done = match p.current() { 162 let done = match p.current() {
163 L_PAREN => tuple_expr(p), 163 L_PAREN => tuple_expr(p),
164 PIPE => lambda_expr(p), 164 PIPE => lambda_expr(p),
165 MOVE_KW if p.nth(1) == PIPE => lambda_expr(p),
165 IF_KW => if_expr(p), 166 IF_KW => if_expr(p),
166 _ => { 167 _ => {
167 p.err_and_bump("expected expression"); 168 p.err_and_bump("expected expression");
@@ -184,11 +185,12 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker {
184// || (); 185// || ();
185// || -> i32 { 92 }; 186// || -> i32 { 92 };
186// |x| x; 187// |x| x;
187// |x: i32,| x; 188// move |x: i32,| x;
188// } 189// }
189fn lambda_expr(p: &mut Parser) -> CompletedMarker { 190fn lambda_expr(p: &mut Parser) -> CompletedMarker {
190 assert!(p.at(PIPE)); 191 assert!(p.at(PIPE) || (p.at(MOVE_KW) && p.nth(1) == PIPE));
191 let m = p.start(); 192 let m = p.start();
193 p.eat(MOVE_KW);
192 params::param_list_opt_types(p); 194 params::param_list_opt_types(p);
193 if fn_ret_type(p) { 195 if fn_ret_type(p) {
194 block(p); 196 block(p);
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index 746316ed5..435be781c 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -70,6 +70,7 @@ pub enum SyntaxKind {
70 TYPE_KW, 70 TYPE_KW,
71 REF_KW, 71 REF_KW,
72 LET_KW, 72 LET_KW,
73 MOVE_KW,
73 AUTO_KW, 74 AUTO_KW,
74 DEFAULT_KW, 75 DEFAULT_KW,
75 UNION_KW, 76 UNION_KW,
@@ -235,6 +236,7 @@ impl SyntaxKind {
235 TYPE_KW => &SyntaxInfo { name: "TYPE_KW" }, 236 TYPE_KW => &SyntaxInfo { name: "TYPE_KW" },
236 REF_KW => &SyntaxInfo { name: "REF_KW" }, 237 REF_KW => &SyntaxInfo { name: "REF_KW" },
237 LET_KW => &SyntaxInfo { name: "LET_KW" }, 238 LET_KW => &SyntaxInfo { name: "LET_KW" },
239 MOVE_KW => &SyntaxInfo { name: "MOVE_KW" },
238 AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, 240 AUTO_KW => &SyntaxInfo { name: "AUTO_KW" },
239 DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, 241 DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" },
240 UNION_KW => &SyntaxInfo { name: "UNION_KW" }, 242 UNION_KW => &SyntaxInfo { name: "UNION_KW" },
@@ -359,6 +361,7 @@ impl SyntaxKind {
359 "type" => TYPE_KW, 361 "type" => TYPE_KW,
360 "ref" => REF_KW, 362 "ref" => REF_KW,
361 "let" => LET_KW, 363 "let" => LET_KW,
364 "move" => MOVE_KW,
362 _ => return None, 365 _ => return None,
363 }; 366 };
364 Some(kw) 367 Some(kw)
@@ -461,6 +464,7 @@ impl SyntaxKind {
461 TYPE_KW => "type", 464 TYPE_KW => "type",
462 REF_KW => "ref", 465 REF_KW => "ref",
463 LET_KW => "let", 466 LET_KW => "let",
467 MOVE_KW => "move",
464 AUTO_KW => "auto", 468 AUTO_KW => "auto",
465 DEFAULT_KW => "default", 469 DEFAULT_KW => "default",
466 UNION_KW => "union", 470 UNION_KW => "union",
diff --git a/tests/data/lexer/0011_keywords.rs b/tests/data/lexer/0011_keywords.rs
index 2a78b5dd2..22b063567 100644
--- a/tests/data/lexer/0011_keywords.rs
+++ b/tests/data/lexer/0011_keywords.rs
@@ -1,3 +1,3 @@
1fn use struct trait enum impl true false as extern crate 1fn use struct trait enum impl true false as extern crate
2mod pub self super in where for loop while if match const 2mod pub self super in where for loop while if match const
3static mut type ref let else 3static mut type ref let else move
diff --git a/tests/data/lexer/0011_keywords.txt b/tests/data/lexer/0011_keywords.txt
index e25d7d4b4..7cfc76716 100644
--- a/tests/data/lexer/0011_keywords.txt
+++ b/tests/data/lexer/0011_keywords.txt
@@ -55,4 +55,6 @@ WHITESPACE 1 " "
55LET_KW 3 "let" 55LET_KW 3 "let"
56WHITESPACE 1 " " 56WHITESPACE 1 " "
57ELSE_KW 4 "else" 57ELSE_KW 4 "else"
58WHITESPACE 1 " "
59MOVE_KW 4 "move"
58WHITESPACE 1 "\n" 60WHITESPACE 1 "\n"
diff --git a/tests/data/parser/inline/0063_lambda_expr.rs b/tests/data/parser/inline/0066_lambda_expr.rs
index 3c30a9209..c20d29751 100644
--- a/tests/data/parser/inline/0063_lambda_expr.rs
+++ b/tests/data/parser/inline/0066_lambda_expr.rs
@@ -2,5 +2,5 @@ fn foo() {
2 || (); 2 || ();
3 || -> i32 { 92 }; 3 || -> i32 { 92 };
4 |x| x; 4 |x| x;
5 |x: i32,| x; 5 move |x: i32,| x;
6} 6}
diff --git a/tests/data/parser/inline/0066_lambda_expr.txt b/tests/data/parser/inline/0066_lambda_expr.txt
new file mode 100644
index 000000000..8c6bc7522
--- /dev/null
+++ b/tests/data/parser/inline/0066_lambda_expr.txt
@@ -0,0 +1,93 @@
1FILE@[0; 79)
2 FN_ITEM@[0; 79)
3 FN_KW@[0; 2)
4 NAME@[2; 6)
5 WHITESPACE@[2; 3)
6 IDENT@[3; 6) "foo"
7 PARAM_LIST@[6; 9)
8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9)
11 BLOCK@[9; 79)
12 L_CURLY@[9; 10)
13 EXPR_STMT@[10; 26)
14 LAMBDA_EXPR@[10; 20)
15 PARAM_LIST@[10; 18)
16 WHITESPACE@[10; 15)
17 PIPE@[15; 16)
18 PIPE@[16; 17)
19 WHITESPACE@[17; 18)
20 TUPLE_EXPR@[18; 20)
21 L_PAREN@[18; 19)
22 R_PAREN@[19; 20)
23 SEMI@[20; 21)
24 WHITESPACE@[21; 26)
25 EXPR_STMT@[26; 48)
26 LAMBDA_EXPR@[26; 42)
27 PARAM_LIST@[26; 29)
28 PIPE@[26; 27)
29 PIPE@[27; 28)
30 WHITESPACE@[28; 29)
31 THIN_ARROW@[29; 31)
32 PATH_TYPE@[31; 36)
33 PATH@[31; 36)
34 PATH_SEGMENT@[31; 36)
35 NAME_REF@[31; 36)
36 WHITESPACE@[31; 32)
37 IDENT@[32; 35) "i32"
38 WHITESPACE@[35; 36)
39 BLOCK@[36; 42)
40 L_CURLY@[36; 37)
41 LITERAL@[37; 41)
42 WHITESPACE@[37; 38)
43 INT_NUMBER@[38; 40) "92"
44 WHITESPACE@[40; 41)
45 R_CURLY@[41; 42)
46 SEMI@[42; 43)
47 WHITESPACE@[43; 48)
48 EXPR_STMT@[48; 59)
49 LAMBDA_EXPR@[48; 53)
50 PARAM_LIST@[48; 52)
51 PIPE@[48; 49)
52 PARAM@[49; 50)
53 BIND_PAT@[49; 50)
54 NAME@[49; 50)
55 IDENT@[49; 50) "x"
56 PIPE@[50; 51)
57 WHITESPACE@[51; 52)
58 PATH_EXPR@[52; 53)
59 PATH@[52; 53)
60 PATH_SEGMENT@[52; 53)
61 NAME_REF@[52; 53)
62 IDENT@[52; 53) "x"
63 SEMI@[53; 54)
64 WHITESPACE@[54; 59)
65 EXPR_STMT@[59; 77)
66 LAMBDA_EXPR@[59; 75)
67 MOVE_KW@[59; 63)
68 PARAM_LIST@[63; 74)
69 WHITESPACE@[63; 64)
70 PIPE@[64; 65)
71 PARAM@[65; 71)
72 BIND_PAT@[65; 66)
73 NAME@[65; 66)
74 IDENT@[65; 66) "x"
75 COLON@[66; 67)
76 PATH_TYPE@[67; 71)
77 PATH@[67; 71)
78 PATH_SEGMENT@[67; 71)
79 NAME_REF@[67; 71)
80 WHITESPACE@[67; 68)
81 IDENT@[68; 71) "i32"
82 COMMA@[71; 72)
83 PIPE@[72; 73)
84 WHITESPACE@[73; 74)
85 PATH_EXPR@[74; 75)
86 PATH@[74; 75)
87 PATH_SEGMENT@[74; 75)
88 NAME_REF@[74; 75)
89 IDENT@[74; 75) "x"
90 SEMI@[75; 76)
91 WHITESPACE@[76; 77)
92 R_CURLY@[77; 78)
93 WHITESPACE@[78; 79)