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/parser/grammar | |
parent | ff71cb1f6de07479610fb0f45e740b249e8a01c6 (diff) |
Ref exprs
Diffstat (limited to 'src/parser/grammar')
-rw-r--r-- | src/parser/grammar/expressions.rs | 23 |
1 files changed, 22 insertions, 1 deletions
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), |