aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grammar.ron1
-rw-r--r--src/grammar/expressions/mod.rs13
-rw-r--r--src/syntax_kinds/generated.rs2
-rw-r--r--tests/data/parser/inline/0087_cast_expr.rs3
-rw-r--r--tests/data/parser/inline/0087_cast_expr.txt29
5 files changed, 48 insertions, 0 deletions
diff --git a/src/grammar.ron b/src/grammar.ron
index ca37eb80b..b525476c2 100644
--- a/src/grammar.ron
+++ b/src/grammar.ron
@@ -162,6 +162,7 @@ Grammar(
162 "METHOD_CALL_EXPR", 162 "METHOD_CALL_EXPR",
163 "FIELD_EXPR", 163 "FIELD_EXPR",
164 "TRY_EXPR", 164 "TRY_EXPR",
165 "CAST_EXPR",
165 166
166 // unary 167 // unary
167 "REF_EXPR", 168 "REF_EXPR",
diff --git a/src/grammar/expressions/mod.rs b/src/grammar/expressions/mod.rs
index e0b4ced74..c137fe654 100644
--- a/src/grammar/expressions/mod.rs
+++ b/src/grammar/expressions/mod.rs
@@ -183,6 +183,7 @@ fn postfix_expr(p: &mut Parser, mut lhs: CompletedMarker) -> CompletedMarker {
183 m.complete(p, RANGE_EXPR) 183 m.complete(p, RANGE_EXPR)
184 } 184 }
185 QUESTION => try_expr(p, lhs), 185 QUESTION => try_expr(p, lhs),
186 AS_KW => cast_expr(p, lhs),
186 _ => break, 187 _ => break,
187 } 188 }
188 } 189 }
@@ -260,6 +261,18 @@ fn try_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
260 m.complete(p, TRY_EXPR) 261 m.complete(p, TRY_EXPR)
261} 262}
262 263
264// test cast_expr
265// fn foo() {
266// 82 as i32;
267// }
268fn cast_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
269 assert!(p.at(AS_KW));
270 let m = lhs.precede(p);
271 p.bump();
272 types::type_(p);
273 m.complete(p, CAST_EXPR)
274}
275
263fn arg_list(p: &mut Parser) { 276fn arg_list(p: &mut Parser) {
264 assert!(p.at(L_PAREN)); 277 assert!(p.at(L_PAREN));
265 let m = p.start(); 278 let m = p.start();
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index 3c5071126..005f4a9dc 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -150,6 +150,7 @@ pub enum SyntaxKind {
150 METHOD_CALL_EXPR, 150 METHOD_CALL_EXPR,
151 FIELD_EXPR, 151 FIELD_EXPR,
152 TRY_EXPR, 152 TRY_EXPR,
153 CAST_EXPR,
153 REF_EXPR, 154 REF_EXPR,
154 DEREF_EXPR, 155 DEREF_EXPR,
155 NOT_EXPR, 156 NOT_EXPR,
@@ -383,6 +384,7 @@ impl SyntaxKind {
383 METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, 384 METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" },
384 FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" }, 385 FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" },
385 TRY_EXPR => &SyntaxInfo { name: "TRY_EXPR" }, 386 TRY_EXPR => &SyntaxInfo { name: "TRY_EXPR" },
387 CAST_EXPR => &SyntaxInfo { name: "CAST_EXPR" },
386 REF_EXPR => &SyntaxInfo { name: "REF_EXPR" }, 388 REF_EXPR => &SyntaxInfo { name: "REF_EXPR" },
387 DEREF_EXPR => &SyntaxInfo { name: "DEREF_EXPR" }, 389 DEREF_EXPR => &SyntaxInfo { name: "DEREF_EXPR" },
388 NOT_EXPR => &SyntaxInfo { name: "NOT_EXPR" }, 390 NOT_EXPR => &SyntaxInfo { name: "NOT_EXPR" },
diff --git a/tests/data/parser/inline/0087_cast_expr.rs b/tests/data/parser/inline/0087_cast_expr.rs
new file mode 100644
index 000000000..3e53d56d6
--- /dev/null
+++ b/tests/data/parser/inline/0087_cast_expr.rs
@@ -0,0 +1,3 @@
1fn foo() {
2 82 as i32;
3}
diff --git a/tests/data/parser/inline/0087_cast_expr.txt b/tests/data/parser/inline/0087_cast_expr.txt
new file mode 100644
index 000000000..78210f0d5
--- /dev/null
+++ b/tests/data/parser/inline/0087_cast_expr.txt
@@ -0,0 +1,29 @@
1FILE@[0; 28)
2 FN_ITEM@[0; 27)
3 FN_KW@[0; 2)
4 WHITESPACE@[2; 3)
5 NAME@[3; 6)
6 IDENT@[3; 6) "foo"
7 PARAM_LIST@[6; 8)
8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9)
11 BLOCK_EXPR@[9; 27)
12 L_CURLY@[9; 10)
13 WHITESPACE@[10; 15)
14 EXPR_STMT@[15; 25)
15 CAST_EXPR@[15; 24)
16 LITERAL@[15; 17)
17 INT_NUMBER@[15; 17) "82"
18 WHITESPACE@[17; 18)
19 AS_KW@[18; 20)
20 WHITESPACE@[20; 21)
21 PATH_TYPE@[21; 24)
22 PATH@[21; 24)
23 PATH_SEGMENT@[21; 24)
24 NAME_REF@[21; 24)
25 IDENT@[21; 24) "i32"
26 SEMI@[24; 25)
27 WHITESPACE@[25; 26)
28 R_CURLY@[26; 27)
29 WHITESPACE@[27; 28)