diff options
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/grammar/expressions.rs | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/parser/grammar/expressions.rs b/src/parser/grammar/expressions.rs index 11bb3436b..3956df568 100644 --- a/src/parser/grammar/expressions.rs +++ b/src/parser/grammar/expressions.rs | |||
@@ -26,11 +26,20 @@ 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 = prefix_expr(p); | 29 | let mut lhs = match prefix_expr(p) { |
30 | Some(lhs) => lhs, | ||
31 | None => return, | ||
32 | }; | ||
30 | 33 | ||
31 | while let Some(m) = lhs { | 34 | loop { |
32 | match p.current() { | 35 | lhs = match p.current() { |
33 | L_PAREN => lhs = Some(call_expr(p, m)), | 36 | L_PAREN => call_expr(p, lhs), |
37 | DOT if p.nth(1) == IDENT => | ||
38 | if p.nth(2) == L_PAREN { | ||
39 | method_call_expr(p, lhs) | ||
40 | } else { | ||
41 | field_expr(p, lhs) | ||
42 | } | ||
34 | _ => break, | 43 | _ => break, |
35 | } | 44 | } |
36 | } | 45 | } |
@@ -95,6 +104,32 @@ fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | |||
95 | m.complete(p, CALL_EXPR) | 104 | m.complete(p, CALL_EXPR) |
96 | } | 105 | } |
97 | 106 | ||
107 | // test method_call_expr | ||
108 | // fn foo() { | ||
109 | // x.foo(); | ||
110 | // y.bar(1, 2,); | ||
111 | // } | ||
112 | fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | ||
113 | assert!(p.at(DOT) && p.nth(1) == IDENT && p.nth(2) == L_PAREN); | ||
114 | let m = lhs.precede(p); | ||
115 | p.bump(); | ||
116 | p.bump(); | ||
117 | arg_list(p); | ||
118 | m.complete(p, METHOD_CALL_EXPR) | ||
119 | } | ||
120 | |||
121 | // test field_expr | ||
122 | // fn foo() { | ||
123 | // x.foo.bar; | ||
124 | // } | ||
125 | fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | ||
126 | assert!(p.at(DOT) && p.nth(1) == IDENT); | ||
127 | let m = lhs.precede(p); | ||
128 | p.bump(); | ||
129 | p.bump(); | ||
130 | m.complete(p, FIELD_EXPR) | ||
131 | } | ||
132 | |||
98 | fn arg_list(p: &mut Parser) { | 133 | fn arg_list(p: &mut Parser) { |
99 | assert!(p.at(L_PAREN)); | 134 | assert!(p.at(L_PAREN)); |
100 | let m = p.start(); | 135 | let m = p.start(); |