aboutsummaryrefslogtreecommitdiff
path: root/src/parser/grammar
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-31 15:35:54 +0100
committerAleksey Kladov <[email protected]>2018-07-31 15:35:54 +0100
commit9f87c9a3f927d3b7a3cbb92818c45c979ece693b (patch)
tree19096a70ffa38bd53071c910a89a995e54a4b765 /src/parser/grammar
parent9ce7e8110254e8db476c96bce2eecb2d16983159 (diff)
Field expr
Diffstat (limited to 'src/parser/grammar')
-rw-r--r--src/parser/grammar/expressions.rs43
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
28pub(super) fn expr(p: &mut Parser) { 28pub(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// }
112fn 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// }
125fn 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
98fn arg_list(p: &mut Parser) { 133fn 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();