diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/grammar.ron | 1 | ||||
-rw-r--r-- | src/grammar/expressions/mod.rs | 14 | ||||
-rw-r--r-- | src/syntax_kinds/generated.rs | 2 | ||||
-rw-r--r-- | src/yellow/red.rs | 2 |
4 files changed, 18 insertions, 1 deletions
diff --git a/src/grammar.ron b/src/grammar.ron index a73e4e1f1..1eb76abdd 100644 --- a/src/grammar.ron +++ b/src/grammar.ron | |||
@@ -153,6 +153,7 @@ Grammar( | |||
153 | 153 | ||
154 | // postfix | 154 | // postfix |
155 | "CALL_EXPR", | 155 | "CALL_EXPR", |
156 | "INDEX_EXPR", | ||
156 | "METHOD_CALL_EXPR", | 157 | "METHOD_CALL_EXPR", |
157 | "FIELD_EXPR", | 158 | "FIELD_EXPR", |
158 | "TRY_EXPR", | 159 | "TRY_EXPR", |
diff --git a/src/grammar/expressions/mod.rs b/src/grammar/expressions/mod.rs index 4421a444c..7f3bc78f2 100644 --- a/src/grammar/expressions/mod.rs +++ b/src/grammar/expressions/mod.rs | |||
@@ -147,6 +147,7 @@ fn postfix_expr(p: &mut Parser, mut lhs: CompletedMarker) -> CompletedMarker { | |||
147 | loop { | 147 | loop { |
148 | lhs = match p.current() { | 148 | lhs = match p.current() { |
149 | L_PAREN => call_expr(p, lhs), | 149 | L_PAREN => call_expr(p, lhs), |
150 | L_BRACK => index_expr(p, lhs), | ||
150 | DOT if p.nth(1) == IDENT => if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON { | 151 | DOT if p.nth(1) == IDENT => if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON { |
151 | method_call_expr(p, lhs) | 152 | method_call_expr(p, lhs) |
152 | } else { | 153 | } else { |
@@ -172,6 +173,19 @@ fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | |||
172 | m.complete(p, CALL_EXPR) | 173 | m.complete(p, CALL_EXPR) |
173 | } | 174 | } |
174 | 175 | ||
176 | // test index_expr | ||
177 | // fn foo() { | ||
178 | // x[1][2]; | ||
179 | // } | ||
180 | fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { | ||
181 | assert!(p.at(L_BRACK)); | ||
182 | let m = lhs.precede(p); | ||
183 | p.bump(); | ||
184 | expr(p); | ||
185 | p.expect(R_BRACK); | ||
186 | m.complete(p, INDEX_EXPR) | ||
187 | } | ||
188 | |||
175 | // test method_call_expr | 189 | // test method_call_expr |
176 | // fn foo() { | 190 | // fn foo() { |
177 | // x.foo(); | 191 | // x.foo(); |
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs index fe1a6694c..8855e980e 100644 --- a/src/syntax_kinds/generated.rs +++ b/src/syntax_kinds/generated.rs | |||
@@ -141,6 +141,7 @@ pub enum SyntaxKind { | |||
141 | STRUCT_LIT, | 141 | STRUCT_LIT, |
142 | STRUCT_LIT_FIELD, | 142 | STRUCT_LIT_FIELD, |
143 | CALL_EXPR, | 143 | CALL_EXPR, |
144 | INDEX_EXPR, | ||
144 | METHOD_CALL_EXPR, | 145 | METHOD_CALL_EXPR, |
145 | FIELD_EXPR, | 146 | FIELD_EXPR, |
146 | TRY_EXPR, | 147 | TRY_EXPR, |
@@ -367,6 +368,7 @@ impl SyntaxKind { | |||
367 | STRUCT_LIT => &SyntaxInfo { name: "STRUCT_LIT" }, | 368 | STRUCT_LIT => &SyntaxInfo { name: "STRUCT_LIT" }, |
368 | STRUCT_LIT_FIELD => &SyntaxInfo { name: "STRUCT_LIT_FIELD" }, | 369 | STRUCT_LIT_FIELD => &SyntaxInfo { name: "STRUCT_LIT_FIELD" }, |
369 | CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, | 370 | CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" }, |
371 | INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" }, | ||
370 | METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, | 372 | METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, |
371 | FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" }, | 373 | FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" }, |
372 | TRY_EXPR => &SyntaxInfo { name: "TRY_EXPR" }, | 374 | TRY_EXPR => &SyntaxInfo { name: "TRY_EXPR" }, |
diff --git a/src/yellow/red.rs b/src/yellow/red.rs index 91c4cd77f..f57c4a9b7 100644 --- a/src/yellow/red.rs +++ b/src/yellow/red.rs | |||
@@ -71,7 +71,7 @@ impl RedNode { | |||
71 | match &self.children.read()[idx] { | 71 | match &self.children.read()[idx] { |
72 | Some(child) => return Some(child.into()), | 72 | Some(child) => return Some(child.into()), |
73 | None => (), | 73 | None => (), |
74 | } | 74 | }; |
75 | let green_children = self.green.children(); | 75 | let green_children = self.green.children(); |
76 | let start_offset = self.start_offset() | 76 | let start_offset = self.start_offset() |
77 | + green_children[..idx] | 77 | + green_children[..idx] |