aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grammar.ron1
-rw-r--r--src/parser/grammar/expressions.rs23
-rw-r--r--src/syntax_kinds/generated.rs2
-rw-r--r--tests/data/parser/inline/0044_ref_expr.rs4
-rw-r--r--tests/data/parser/inline/0044_ref_expr.txt54
5 files changed, 83 insertions, 1 deletions
diff --git a/src/grammar.ron b/src/grammar.ron
index f640ccb7b..9383abd19 100644
--- a/src/grammar.ron
+++ b/src/grammar.ron
@@ -126,6 +126,7 @@ Grammar(
126 "TUPLE_EXPR", 126 "TUPLE_EXPR",
127 "PATH_EXPR", 127 "PATH_EXPR",
128 "CALL_EXPR", 128 "CALL_EXPR",
129 "REF_EXPR",
129 130
130 "EXTERN_BLOCK", 131 "EXTERN_BLOCK",
131 "ENUM_VARIANT", 132 "ENUM_VARIANT",
diff --git a/src/parser/grammar/expressions.rs b/src/parser/grammar/expressions.rs
index 7991b1921..4861536f8 100644
--- a/src/parser/grammar/expressions.rs
+++ b/src/parser/grammar/expressions.rs
@@ -26,7 +26,7 @@ pub(super) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
26} 26}
27 27
28pub(super) fn expr(p: &mut Parser) { 28pub(super) fn expr(p: &mut Parser) {
29 let mut lhs = atom_expr(p); 29 let mut lhs = prefix_expr(p);
30 30
31 while let Some(m) = lhs { 31 while let Some(m) = lhs {
32 match p.current() { 32 match p.current() {
@@ -36,6 +36,27 @@ pub(super) fn expr(p: &mut Parser) {
36 } 36 }
37} 37}
38 38
39fn prefix_expr(p: &mut Parser) -> Option<CompletedMarker> {
40 match p.current() {
41 AMPERSAND => Some(ref_expr(p)),
42 _ => atom_expr(p)
43 }
44}
45
46// test ref_expr
47// fn foo() {
48// let _ = &1;
49// let _ = &mut &f();
50// }
51fn ref_expr(p: &mut Parser) -> CompletedMarker {
52 assert!(p.at(AMPERSAND));
53 let m = p.start();
54 p.bump();
55 p.eat(MUT_KW);
56 expr(p);
57 m.complete(p, REF_EXPR)
58}
59
39fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> { 60fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> {
40 match literal(p) { 61 match literal(p) {
41 Some(m) => return Some(m), 62 Some(m) => return Some(m),
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index 986df7814..dc391c4a7 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -117,6 +117,7 @@ pub enum SyntaxKind {
117 TUPLE_EXPR, 117 TUPLE_EXPR,
118 PATH_EXPR, 118 PATH_EXPR,
119 CALL_EXPR, 119 CALL_EXPR,
120 REF_EXPR,
120 EXTERN_BLOCK, 121 EXTERN_BLOCK,
121 ENUM_VARIANT, 122 ENUM_VARIANT,
122 NAMED_FIELD, 123 NAMED_FIELD,
@@ -266,6 +267,7 @@ impl SyntaxKind {
266 TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" }, 267 TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" },
267 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" }, 268 PATH_EXPR => &SyntaxInfo { name: "PATH_EXPR" },
268 CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, 269 CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" },
270 REF_EXPR => &SyntaxInfo { name: "REF_EXPR" },
269 EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, 271 EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" },
270 ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, 272 ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
271 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, 273 NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
diff --git a/tests/data/parser/inline/0044_ref_expr.rs b/tests/data/parser/inline/0044_ref_expr.rs
new file mode 100644
index 000000000..2dac6be95
--- /dev/null
+++ b/tests/data/parser/inline/0044_ref_expr.rs
@@ -0,0 +1,4 @@
1fn foo() {
2 let _ = &1;
3 let _ = &mut &f();
4}
diff --git a/tests/data/parser/inline/0044_ref_expr.txt b/tests/data/parser/inline/0044_ref_expr.txt
new file mode 100644
index 000000000..64388df42
--- /dev/null
+++ b/tests/data/parser/inline/0044_ref_expr.txt
@@ -0,0 +1,54 @@
1FILE@[0; 52)
2 FN_ITEM@[0; 52)
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; 52)
12 L_CURLY@[9; 10)
13 LET_STMT@[10; 31)
14 WHITESPACE@[10; 15)
15 LET_KW@[15; 18)
16 PLACEHOLDER_PAT@[18; 21)
17 WHITESPACE@[18; 19)
18 UNDERSCORE@[19; 20)
19 WHITESPACE@[20; 21)
20 EQ@[21; 22)
21 REF_EXPR@[22; 25)
22 WHITESPACE@[22; 23)
23 AMPERSAND@[23; 24)
24 LITERAL@[24; 25)
25 INT_NUMBER@[24; 25)
26 SEMI@[25; 26)
27 WHITESPACE@[26; 31)
28 LET_STMT@[31; 50)
29 LET_KW@[31; 34)
30 PLACEHOLDER_PAT@[34; 37)
31 WHITESPACE@[34; 35)
32 UNDERSCORE@[35; 36)
33 WHITESPACE@[36; 37)
34 EQ@[37; 38)
35 REF_EXPR@[38; 48)
36 WHITESPACE@[38; 39)
37 AMPERSAND@[39; 40)
38 MUT_KW@[40; 43)
39 REF_EXPR@[43; 48)
40 WHITESPACE@[43; 44)
41 AMPERSAND@[44; 45)
42 CALL_EXPR@[45; 48)
43 PATH_EXPR@[45; 46)
44 PATH@[45; 46)
45 PATH_SEGMENT@[45; 46)
46 NAME_REF@[45; 46)
47 IDENT@[45; 46) "f"
48 ARG_LIST@[46; 48)
49 L_PAREN@[46; 47)
50 R_PAREN@[47; 48)
51 SEMI@[48; 49)
52 WHITESPACE@[49; 50)
53 R_CURLY@[50; 51)
54 WHITESPACE@[51; 52)