aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grammar.ron1
-rw-r--r--src/grammar/expressions/atom.rs34
-rw-r--r--src/syntax_kinds/generated.rs2
-rw-r--r--tests/data/parser/inline/0076_cond.rs1
-rw-r--r--tests/data/parser/inline/0076_cond.txt42
-rw-r--r--tests/data/parser/inline/0077_while_expr.rs4
-rw-r--r--tests/data/parser/inline/0077_while_expr.txt64
7 files changed, 141 insertions, 7 deletions
diff --git a/src/grammar.ron b/src/grammar.ron
index 8ce5ebc49..9f80b3ebf 100644
--- a/src/grammar.ron
+++ b/src/grammar.ron
@@ -135,6 +135,7 @@ Grammar(
135 "PATH_EXPR", 135 "PATH_EXPR",
136 "LAMBDA_EXPR", 136 "LAMBDA_EXPR",
137 "IF_EXPR", 137 "IF_EXPR",
138 "WHILE_EXPR",
138 "BLOCK_EXPR", 139 "BLOCK_EXPR",
139 "RETURN_EXPR", 140 "RETURN_EXPR",
140 "MATCH_EXPR", 141 "MATCH_EXPR",
diff --git a/src/grammar/expressions/atom.rs b/src/grammar/expressions/atom.rs
index ad654df9e..6a0d47d82 100644
--- a/src/grammar/expressions/atom.rs
+++ b/src/grammar/expressions/atom.rs
@@ -29,7 +29,7 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
29pub(super) const ATOM_EXPR_FIRST: TokenSet = 29pub(super) const ATOM_EXPR_FIRST: TokenSet =
30 token_set_union![ 30 token_set_union![
31 LITERAL_FIRST, 31 LITERAL_FIRST,
32 token_set![L_PAREN, PIPE, MOVE_KW, IF_KW, MATCH_KW, UNSAFE_KW, L_CURLY, RETURN_KW, 32 token_set![L_PAREN, PIPE, MOVE_KW, IF_KW, WHILE_KW, MATCH_KW, UNSAFE_KW, L_CURLY, RETURN_KW,
33 IDENT, SELF_KW, SUPER_KW, COLONCOLON ], 33 IDENT, SELF_KW, SUPER_KW, COLONCOLON ],
34 ]; 34 ];
35 35
@@ -47,6 +47,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
47 PIPE => lambda_expr(p), 47 PIPE => lambda_expr(p),
48 MOVE_KW if la == PIPE => lambda_expr(p), 48 MOVE_KW if la == PIPE => lambda_expr(p),
49 IF_KW => if_expr(p), 49 IF_KW => if_expr(p),
50 WHILE_KW => while_expr(p),
50 MATCH_KW => match_expr(p), 51 MATCH_KW => match_expr(p),
51 UNSAFE_KW if la == L_CURLY => block_expr(p), 52 UNSAFE_KW if la == L_CURLY => block_expr(p),
52 L_CURLY => block_expr(p), 53 L_CURLY => block_expr(p),
@@ -97,7 +98,8 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
97fn if_expr(p: &mut Parser) -> CompletedMarker { 98fn if_expr(p: &mut Parser) -> CompletedMarker {
98 assert!(p.at(IF_KW)); 99 assert!(p.at(IF_KW));
99 let m = p.start(); 100 let m = p.start();
100 if_head(p); 101 p.bump();
102 cond(p);
101 block(p); 103 block(p);
102 if p.at(ELSE_KW) { 104 if p.at(ELSE_KW) {
103 p.bump(); 105 p.bump();
@@ -110,10 +112,28 @@ fn if_expr(p: &mut Parser) -> CompletedMarker {
110 m.complete(p, IF_EXPR) 112 m.complete(p, IF_EXPR)
111} 113}
112 114
113fn if_head(p: &mut Parser) { 115// test while_expr
114 assert!(p.at(IF_KW)); 116// fn foo() {
117// while true {};
118// while let Some(x) = it.next() {};
119// }
120fn while_expr(p: &mut Parser) -> CompletedMarker {
121 assert!(p.at(WHILE_KW));
122 let m = p.start();
115 p.bump(); 123 p.bump();
116 expr_no_struct(p); 124 cond(p);
125 block(p);
126 m.complete(p, WHILE_EXPR)
127}
128
129// test cond
130// fn foo() { if let Some(_) = None {} }
131fn cond(p: &mut Parser) {
132 if p.eat(LET_KW) {
133 patterns::pattern(p);
134 p.expect(EQ);
135 }
136 expr_no_struct(p)
117} 137}
118 138
119// test match_expr 139// test match_expr
@@ -152,8 +172,8 @@ fn match_arm(p: &mut Parser) {
152 break; 172 break;
153 } 173 }
154 } 174 }
155 if p.at(IF_KW) { 175 if p.eat(IF_KW) {
156 if_head(p) 176 expr_no_struct(p);
157 } 177 }
158 p.expect(FAT_ARROW); 178 p.expect(FAT_ARROW);
159 expr(p); 179 expr(p);
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index 7bdd0267c..1d3d3b9c1 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -125,6 +125,7 @@ pub enum SyntaxKind {
125 PATH_EXPR, 125 PATH_EXPR,
126 LAMBDA_EXPR, 126 LAMBDA_EXPR,
127 IF_EXPR, 127 IF_EXPR,
128 WHILE_EXPR,
128 BLOCK_EXPR, 129 BLOCK_EXPR,
129 RETURN_EXPR, 130 RETURN_EXPR,
130 MATCH_EXPR, 131 MATCH_EXPR,
@@ -343,6 +344,7 @@ impl SyntaxKind {
343 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" }, 344 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" },
344 LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" }, 345 LAMBDA_EXPR => &SyntaxInfo { name: "LAMBDA_EXPR" },
345 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" }, 346 IF_EXPR => &SyntaxInfo { name: "IF_EXPR" },
347 WHILE_EXPR => &SyntaxInfo { name: "WHILE_EXPR" },
346 BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" }, 348 BLOCK_EXPR => &SyntaxInfo { name: "BLOCK_EXPR" },
347 RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" }, 349 RETURN_EXPR => &SyntaxInfo { name: "RETURN_EXPR" },
348 MATCH_EXPR => &SyntaxInfo { name: "MATCH_EXPR" }, 350 MATCH_EXPR => &SyntaxInfo { name: "MATCH_EXPR" },
diff --git a/tests/data/parser/inline/0076_cond.rs b/tests/data/parser/inline/0076_cond.rs
new file mode 100644
index 000000000..fdb37ee6f
--- /dev/null
+++ b/tests/data/parser/inline/0076_cond.rs
@@ -0,0 +1 @@
fn foo() { if let Some(_) = None {} }
diff --git a/tests/data/parser/inline/0076_cond.txt b/tests/data/parser/inline/0076_cond.txt
new file mode 100644
index 000000000..22eed8458
--- /dev/null
+++ b/tests/data/parser/inline/0076_cond.txt
@@ -0,0 +1,42 @@
1FILE@[0; 38)
2 FN_ITEM@[0; 38)
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_EXPR@[9; 38)
12 L_CURLY@[9; 10)
13 IF_EXPR@[10; 36)
14 WHITESPACE@[10; 11)
15 IF_KW@[11; 13)
16 WHITESPACE@[13; 14)
17 LET_KW@[14; 17)
18 TUPLE_PAT@[17; 26)
19 PATH@[17; 22)
20 PATH_SEGMENT@[17; 22)
21 NAME_REF@[17; 22)
22 WHITESPACE@[17; 18)
23 IDENT@[18; 22) "Some"
24 L_PAREN@[22; 23)
25 PLACEHOLDER_PAT@[23; 24)
26 UNDERSCORE@[23; 24)
27 R_PAREN@[24; 25)
28 WHITESPACE@[25; 26)
29 EQ@[26; 27)
30 PATH_EXPR@[27; 33)
31 PATH@[27; 33)
32 PATH_SEGMENT@[27; 33)
33 NAME_REF@[27; 33)
34 WHITESPACE@[27; 28)
35 IDENT@[28; 32) "None"
36 WHITESPACE@[32; 33)
37 BLOCK_EXPR@[33; 36)
38 L_CURLY@[33; 34)
39 R_CURLY@[34; 35)
40 WHITESPACE@[35; 36)
41 R_CURLY@[36; 37)
42 WHITESPACE@[37; 38)
diff --git a/tests/data/parser/inline/0077_while_expr.rs b/tests/data/parser/inline/0077_while_expr.rs
new file mode 100644
index 000000000..293046a04
--- /dev/null
+++ b/tests/data/parser/inline/0077_while_expr.rs
@@ -0,0 +1,4 @@
1fn foo() {
2 while true {};
3 while let Some(x) = it.next() {};
4}
diff --git a/tests/data/parser/inline/0077_while_expr.txt b/tests/data/parser/inline/0077_while_expr.txt
new file mode 100644
index 000000000..447b4b880
--- /dev/null
+++ b/tests/data/parser/inline/0077_while_expr.txt
@@ -0,0 +1,64 @@
1FILE@[0; 70)
2 FN_ITEM@[0; 70)
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_EXPR@[9; 70)
12 L_CURLY@[9; 10)
13 EXPR_STMT@[10; 34)
14 WHILE_EXPR@[10; 28)
15 WHITESPACE@[10; 15)
16 WHILE_KW@[15; 20)
17 LITERAL@[20; 26)
18 WHITESPACE@[20; 21)
19 TRUE_KW@[21; 25)
20 WHITESPACE@[25; 26)
21 BLOCK_EXPR@[26; 28)
22 L_CURLY@[26; 27)
23 R_CURLY@[27; 28)
24 SEMI@[28; 29)
25 WHITESPACE@[29; 34)
26 EXPR_STMT@[34; 68)
27 WHILE_EXPR@[34; 66)
28 WHILE_KW@[34; 39)
29 WHITESPACE@[39; 40)
30 LET_KW@[40; 43)
31 TUPLE_PAT@[43; 52)
32 PATH@[43; 48)
33 PATH_SEGMENT@[43; 48)
34 NAME_REF@[43; 48)
35 WHITESPACE@[43; 44)
36 IDENT@[44; 48) "Some"
37 L_PAREN@[48; 49)
38 BIND_PAT@[49; 50)
39 NAME@[49; 50)
40 IDENT@[49; 50) "x"
41 R_PAREN@[50; 51)
42 WHITESPACE@[51; 52)
43 EQ@[52; 53)
44 METHOD_CALL_EXPR@[53; 64)
45 PATH_EXPR@[53; 56)
46 PATH@[53; 56)
47 PATH_SEGMENT@[53; 56)
48 NAME_REF@[53; 56)
49 WHITESPACE@[53; 54)
50 IDENT@[54; 56) "it"
51 DOT@[56; 57)
52 NAME_REF@[57; 61)
53 IDENT@[57; 61) "next"
54 ARG_LIST@[61; 64)
55 L_PAREN@[61; 62)
56 R_PAREN@[62; 63)
57 WHITESPACE@[63; 64)
58 BLOCK_EXPR@[64; 66)
59 L_CURLY@[64; 65)
60 R_CURLY@[65; 66)
61 SEMI@[66; 67)
62 WHITESPACE@[67; 68)
63 R_CURLY@[68; 69)
64 WHITESPACE@[69; 70)