aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grammar.ron1
-rw-r--r--src/grammar/expressions/mod.rs14
-rw-r--r--src/syntax_kinds/generated.rs2
-rw-r--r--src/yellow/red.rs2
-rw-r--r--tests/data/parser/inline/0081_index_expr.rs3
-rw-r--r--tests/data/parser/inline/0081_index_expr.txt33
6 files changed, 54 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// }
180fn 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]
diff --git a/tests/data/parser/inline/0081_index_expr.rs b/tests/data/parser/inline/0081_index_expr.rs
new file mode 100644
index 000000000..b9ba78a6c
--- /dev/null
+++ b/tests/data/parser/inline/0081_index_expr.rs
@@ -0,0 +1,3 @@
1fn foo() {
2 x[1][2];
3}
diff --git a/tests/data/parser/inline/0081_index_expr.txt b/tests/data/parser/inline/0081_index_expr.txt
new file mode 100644
index 000000000..b77f54fb6
--- /dev/null
+++ b/tests/data/parser/inline/0081_index_expr.txt
@@ -0,0 +1,33 @@
1FILE@[0; 26)
2 FN_ITEM@[0; 26)
3 FN_KW@[0; 2)
4 NAME@[2; 6)
5 WHITESPACE@[2; 3)
6 IDENT@[3; 6) "foo"
7 PARAM_LIST@[6; 9)
8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9)
11 BLOCK_EXPR@[9; 26)
12 L_CURLY@[9; 10)
13 EXPR_STMT@[10; 24)
14 INDEX_EXPR@[10; 22)
15 INDEX_EXPR@[10; 19)
16 PATH_EXPR@[10; 16)
17 PATH@[10; 16)
18 PATH_SEGMENT@[10; 16)
19 NAME_REF@[10; 16)
20 WHITESPACE@[10; 15)
21 IDENT@[15; 16) "x"
22 L_BRACK@[16; 17)
23 LITERAL@[17; 18)
24 INT_NUMBER@[17; 18) "1"
25 R_BRACK@[18; 19)
26 L_BRACK@[19; 20)
27 LITERAL@[20; 21)
28 INT_NUMBER@[20; 21) "2"
29 R_BRACK@[21; 22)
30 SEMI@[22; 23)
31 WHITESPACE@[23; 24)
32 R_CURLY@[24; 25)
33 WHITESPACE@[25; 26)