diff options
author | Aleksey Kladov <[email protected]> | 2018-07-31 13:33:51 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-07-31 13:33:51 +0100 |
commit | f843f23abae72ba3bd2920edc2a8635eafb61409 (patch) | |
tree | 34590d26e6c1c510013c103a1787f01e47cf03c7 | |
parent | 580340d1b879a434302d314ef6cd9f4cae0cd57d (diff) |
Type ascription in let
-rw-r--r-- | src/parser/grammar/items/mod.rs | 15 | ||||
-rw-r--r-- | tests/data/parser/inline/0050_let_stmt;.rs | 6 | ||||
-rw-r--r-- | tests/data/parser/inline/0050_let_stmt;.txt | 71 |
3 files changed, 90 insertions, 2 deletions
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index 73fd5235a..00c52dc09 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs | |||
@@ -267,13 +267,24 @@ fn fn_item(p: &mut Parser) { | |||
267 | m.complete(p, BLOCK); | 267 | m.complete(p, BLOCK); |
268 | } | 268 | } |
269 | 269 | ||
270 | // test let_stmt; | ||
271 | // fn foo() { | ||
272 | // let a; | ||
273 | // let b: i32; | ||
274 | // let c = 92; | ||
275 | // let d: i32 = 92; | ||
276 | // } | ||
270 | fn let_stmt(p: &mut Parser) { | 277 | fn let_stmt(p: &mut Parser) { |
271 | assert!(p.at(LET_KW)); | 278 | assert!(p.at(LET_KW)); |
272 | let m = p.start(); | 279 | let m = p.start(); |
273 | p.bump(); | 280 | p.bump(); |
274 | patterns::pattern(p); | 281 | patterns::pattern(p); |
275 | p.expect(EQ); | 282 | if p.eat(COLON) { |
276 | expressions::expr(p); | 283 | types::type_(p); |
284 | } | ||
285 | if p.eat(EQ) { | ||
286 | expressions::expr(p); | ||
287 | } | ||
277 | p.expect(SEMI); | 288 | p.expect(SEMI); |
278 | m.complete(p, LET_STMT); | 289 | m.complete(p, LET_STMT); |
279 | } | 290 | } |
diff --git a/tests/data/parser/inline/0050_let_stmt;.rs b/tests/data/parser/inline/0050_let_stmt;.rs new file mode 100644 index 000000000..0a9af907f --- /dev/null +++ b/tests/data/parser/inline/0050_let_stmt;.rs | |||
@@ -0,0 +1,6 @@ | |||
1 | fn foo() { | ||
2 | let a; | ||
3 | let b: i32; | ||
4 | let c = 92; | ||
5 | let d: i32 = 92; | ||
6 | } | ||
diff --git a/tests/data/parser/inline/0050_let_stmt;.txt b/tests/data/parser/inline/0050_let_stmt;.txt new file mode 100644 index 000000000..b7acf8744 --- /dev/null +++ b/tests/data/parser/inline/0050_let_stmt;.txt | |||
@@ -0,0 +1,71 @@ | |||
1 | FILE@[0; 77) | ||
2 | FN_ITEM@[0; 77) | ||
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; 77) | ||
12 | L_CURLY@[9; 10) | ||
13 | LET_STMT@[10; 26) | ||
14 | WHITESPACE@[10; 15) | ||
15 | LET_KW@[15; 18) | ||
16 | BIND_PAT@[18; 20) | ||
17 | NAME@[18; 20) | ||
18 | WHITESPACE@[18; 19) | ||
19 | IDENT@[19; 20) "a" | ||
20 | SEMI@[20; 21) | ||
21 | WHITESPACE@[21; 26) | ||
22 | LET_STMT@[26; 42) | ||
23 | LET_KW@[26; 29) | ||
24 | BIND_PAT@[29; 31) | ||
25 | NAME@[29; 31) | ||
26 | WHITESPACE@[29; 30) | ||
27 | IDENT@[30; 31) "b" | ||
28 | COLON@[31; 32) | ||
29 | PATH_TYPE@[32; 36) | ||
30 | PATH@[32; 36) | ||
31 | PATH_SEGMENT@[32; 36) | ||
32 | NAME_REF@[32; 36) | ||
33 | WHITESPACE@[32; 33) | ||
34 | IDENT@[33; 36) "i32" | ||
35 | SEMI@[36; 37) | ||
36 | WHITESPACE@[37; 42) | ||
37 | LET_STMT@[42; 58) | ||
38 | LET_KW@[42; 45) | ||
39 | BIND_PAT@[45; 48) | ||
40 | NAME@[45; 48) | ||
41 | WHITESPACE@[45; 46) | ||
42 | IDENT@[46; 47) "c" | ||
43 | WHITESPACE@[47; 48) | ||
44 | EQ@[48; 49) | ||
45 | LITERAL@[49; 52) | ||
46 | WHITESPACE@[49; 50) | ||
47 | INT_NUMBER@[50; 52) | ||
48 | SEMI@[52; 53) | ||
49 | WHITESPACE@[53; 58) | ||
50 | LET_STMT@[58; 75) | ||
51 | LET_KW@[58; 61) | ||
52 | BIND_PAT@[61; 63) | ||
53 | NAME@[61; 63) | ||
54 | WHITESPACE@[61; 62) | ||
55 | IDENT@[62; 63) "d" | ||
56 | COLON@[63; 64) | ||
57 | PATH_TYPE@[64; 69) | ||
58 | PATH@[64; 69) | ||
59 | PATH_SEGMENT@[64; 69) | ||
60 | NAME_REF@[64; 69) | ||
61 | WHITESPACE@[64; 65) | ||
62 | IDENT@[65; 68) "i32" | ||
63 | WHITESPACE@[68; 69) | ||
64 | EQ@[69; 70) | ||
65 | LITERAL@[70; 73) | ||
66 | WHITESPACE@[70; 71) | ||
67 | INT_NUMBER@[71; 73) | ||
68 | SEMI@[73; 74) | ||
69 | WHITESPACE@[74; 75) | ||
70 | R_CURLY@[75; 76) | ||
71 | WHITESPACE@[76; 77) | ||