aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grammar.ron2
-rw-r--r--src/parser/grammar/items/mod.rs18
-rw-r--r--src/syntax_kinds/generated.rs2
-rw-r--r--tests/data/parser/inline/0045_block.rs4
-rw-r--r--tests/data/parser/inline/0045_block.txt86
5 files changed, 111 insertions, 1 deletions
diff --git a/src/grammar.ron b/src/grammar.ron
index 9383abd19..a8c922040 100644
--- a/src/grammar.ron
+++ b/src/grammar.ron
@@ -146,7 +146,9 @@ Grammar(
146 "NAME_REF", 146 "NAME_REF",
147 "VALUE_PARAMETER", 147 "VALUE_PARAMETER",
148 "BLOCK", 148 "BLOCK",
149
149 "LET_STMT", 150 "LET_STMT",
151 "EXPR_STMT",
150 152
151 "TYPE_PARAM", 153 "TYPE_PARAM",
152 "LIFETIME_PARAM", 154 "LIFETIME_PARAM",
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs
index d059833a0..c88e39596 100644
--- a/src/parser/grammar/items/mod.rs
+++ b/src/parser/grammar/items/mod.rs
@@ -223,6 +223,11 @@ fn fn_item(p: &mut Parser) {
223 fn_ret_type(p); 223 fn_ret_type(p);
224 block(p); 224 block(p);
225 225
226 // test block
227 // fn a() {}
228 // fn b() { let _ = 1; }
229 // fn c() { 1; 2; }
230 // fn d() { 1; 2 }
226 fn block(p: &mut Parser) { 231 fn block(p: &mut Parser) {
227 if !p.at(L_CURLY) { 232 if !p.at(L_CURLY) {
228 p.error("expected block"); 233 p.error("expected block");
@@ -232,7 +237,18 @@ fn fn_item(p: &mut Parser) {
232 while !p.at(EOF) && !p.at(R_CURLY) { 237 while !p.at(EOF) && !p.at(R_CURLY) {
233 match p.current() { 238 match p.current() {
234 LET_KW => let_stmt(p), 239 LET_KW => let_stmt(p),
235 _ => p.err_and_bump("expected statement"), 240 _ => {
241 let expr_stmt = p.start();
242 expressions::expr(p);
243 if p.eat(SEMI) {
244 expr_stmt.complete(p, EXPR_STMT);
245 if p.at(R_CURLY) {
246 break;
247 }
248 } else {
249 expr_stmt.abandon(p);
250 }
251 }
236 } 252 }
237 } 253 }
238 p.expect(R_CURLY); 254 p.expect(R_CURLY);
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index dc391c4a7..c49ad9a59 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -137,6 +137,7 @@ pub enum SyntaxKind {
137 VALUE_PARAMETER, 137 VALUE_PARAMETER,
138 BLOCK, 138 BLOCK,
139 LET_STMT, 139 LET_STMT,
140 EXPR_STMT,
140 TYPE_PARAM, 141 TYPE_PARAM,
141 LIFETIME_PARAM, 142 LIFETIME_PARAM,
142 TYPE_PARAM_LIST, 143 TYPE_PARAM_LIST,
@@ -287,6 +288,7 @@ impl SyntaxKind {
287 VALUE_PARAMETER => &SyntaxInfo { name: "VALUE_PARAMETER" }, 288 VALUE_PARAMETER => &SyntaxInfo { name: "VALUE_PARAMETER" },
288 BLOCK => &SyntaxInfo { name: "BLOCK" }, 289 BLOCK => &SyntaxInfo { name: "BLOCK" },
289 LET_STMT => &SyntaxInfo { name: "LET_STMT" }, 290 LET_STMT => &SyntaxInfo { name: "LET_STMT" },
291 EXPR_STMT => &SyntaxInfo { name: "EXPR_STMT" },
290 TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" }, 292 TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" },
291 LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" }, 293 LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" },
292 TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" }, 294 TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" },
diff --git a/tests/data/parser/inline/0045_block.rs b/tests/data/parser/inline/0045_block.rs
new file mode 100644
index 000000000..81f44c533
--- /dev/null
+++ b/tests/data/parser/inline/0045_block.rs
@@ -0,0 +1,4 @@
1fn a() {}
2fn b() { let _ = 1; }
3fn c() { 1; 2; }
4fn d() { 1; 2 }
diff --git a/tests/data/parser/inline/0045_block.txt b/tests/data/parser/inline/0045_block.txt
new file mode 100644
index 000000000..5a83999c9
--- /dev/null
+++ b/tests/data/parser/inline/0045_block.txt
@@ -0,0 +1,86 @@
1FILE@[0; 65)
2 FN_ITEM@[0; 10)
3 FN_KW@[0; 2)
4 NAME@[2; 4)
5 WHITESPACE@[2; 3)
6 IDENT@[3; 4) "a"
7 PARAM_LIST@[4; 7)
8 L_PAREN@[4; 5)
9 R_PAREN@[5; 6)
10 WHITESPACE@[6; 7)
11 BLOCK@[7; 10)
12 L_CURLY@[7; 8)
13 R_CURLY@[8; 9)
14 WHITESPACE@[9; 10)
15 FN_ITEM@[10; 32)
16 FN_KW@[10; 12)
17 NAME@[12; 14)
18 WHITESPACE@[12; 13)
19 IDENT@[13; 14) "b"
20 PARAM_LIST@[14; 17)
21 L_PAREN@[14; 15)
22 R_PAREN@[15; 16)
23 WHITESPACE@[16; 17)
24 BLOCK@[17; 32)
25 L_CURLY@[17; 18)
26 LET_STMT@[18; 30)
27 WHITESPACE@[18; 19)
28 LET_KW@[19; 22)
29 PLACEHOLDER_PAT@[22; 25)
30 WHITESPACE@[22; 23)
31 UNDERSCORE@[23; 24)
32 WHITESPACE@[24; 25)
33 EQ@[25; 26)
34 LITERAL@[26; 28)
35 WHITESPACE@[26; 27)
36 INT_NUMBER@[27; 28)
37 SEMI@[28; 29)
38 WHITESPACE@[29; 30)
39 R_CURLY@[30; 31)
40 WHITESPACE@[31; 32)
41 FN_ITEM@[32; 49)
42 FN_KW@[32; 34)
43 NAME@[34; 36)
44 WHITESPACE@[34; 35)
45 IDENT@[35; 36) "c"
46 PARAM_LIST@[36; 39)
47 L_PAREN@[36; 37)
48 R_PAREN@[37; 38)
49 WHITESPACE@[38; 39)
50 BLOCK@[39; 49)
51 L_CURLY@[39; 40)
52 EXPR_STMT@[40; 44)
53 LITERAL@[40; 42)
54 WHITESPACE@[40; 41)
55 INT_NUMBER@[41; 42)
56 SEMI@[42; 43)
57 WHITESPACE@[43; 44)
58 EXPR_STMT@[44; 47)
59 LITERAL@[44; 45)
60 INT_NUMBER@[44; 45)
61 SEMI@[45; 46)
62 WHITESPACE@[46; 47)
63 R_CURLY@[47; 48)
64 WHITESPACE@[48; 49)
65 FN_ITEM@[49; 65)
66 FN_KW@[49; 51)
67 NAME@[51; 53)
68 WHITESPACE@[51; 52)
69 IDENT@[52; 53) "d"
70 PARAM_LIST@[53; 56)
71 L_PAREN@[53; 54)
72 R_PAREN@[54; 55)
73 WHITESPACE@[55; 56)
74 BLOCK@[56; 65)
75 L_CURLY@[56; 57)
76 EXPR_STMT@[57; 61)
77 LITERAL@[57; 59)
78 WHITESPACE@[57; 58)
79 INT_NUMBER@[58; 59)
80 SEMI@[59; 60)
81 WHITESPACE@[60; 61)
82 LITERAL@[61; 63)
83 INT_NUMBER@[61; 62)
84 WHITESPACE@[62; 63)
85 R_CURLY@[63; 64)
86 WHITESPACE@[64; 65)