diff options
author | Aleksey Kladov <[email protected]> | 2018-07-31 10:51:00 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-07-31 10:51:00 +0100 |
commit | 66182ed5d5e43962a46492ea41f19f9adeccc9e5 (patch) | |
tree | e27b4a8e46d3e18be7d35fa9ae32b0a7b5e5934b /src | |
parent | ff71cb1f6de07479610fb0f45e740b249e8a01c6 (diff) |
Ref exprs
Diffstat (limited to 'src')
-rw-r--r-- | src/grammar.ron | 1 | ||||
-rw-r--r-- | src/parser/grammar/expressions.rs | 23 | ||||
-rw-r--r-- | src/syntax_kinds/generated.rs | 2 |
3 files changed, 25 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 | ||
28 | pub(super) fn expr(p: &mut Parser) { | 28 | pub(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 | ||
39 | fn 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 | // } | ||
51 | fn 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 | |||
39 | fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> { | 60 | fn 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" }, |