index expr
This commit is contained in:
parent
8cf962f1f5
commit
80fa861cd6
6 changed files with 54 additions and 1 deletions
|
|
@ -153,6 +153,7 @@ Grammar(
|
|||
|
||||
// postfix
|
||||
"CALL_EXPR",
|
||||
"INDEX_EXPR",
|
||||
"METHOD_CALL_EXPR",
|
||||
"FIELD_EXPR",
|
||||
"TRY_EXPR",
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ fn postfix_expr(p: &mut Parser, mut lhs: CompletedMarker) -> CompletedMarker {
|
|||
loop {
|
||||
lhs = match p.current() {
|
||||
L_PAREN => call_expr(p, lhs),
|
||||
L_BRACK => index_expr(p, lhs),
|
||||
DOT if p.nth(1) == IDENT => if p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON {
|
||||
method_call_expr(p, lhs)
|
||||
} else {
|
||||
|
|
@ -172,6 +173,19 @@ fn call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
|||
m.complete(p, CALL_EXPR)
|
||||
}
|
||||
|
||||
// test index_expr
|
||||
// fn foo() {
|
||||
// x[1][2];
|
||||
// }
|
||||
fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
||||
assert!(p.at(L_BRACK));
|
||||
let m = lhs.precede(p);
|
||||
p.bump();
|
||||
expr(p);
|
||||
p.expect(R_BRACK);
|
||||
m.complete(p, INDEX_EXPR)
|
||||
}
|
||||
|
||||
// test method_call_expr
|
||||
// fn foo() {
|
||||
// x.foo();
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ pub enum SyntaxKind {
|
|||
STRUCT_LIT,
|
||||
STRUCT_LIT_FIELD,
|
||||
CALL_EXPR,
|
||||
INDEX_EXPR,
|
||||
METHOD_CALL_EXPR,
|
||||
FIELD_EXPR,
|
||||
TRY_EXPR,
|
||||
|
|
@ -367,6 +368,7 @@ impl SyntaxKind {
|
|||
STRUCT_LIT => &SyntaxInfo { name: "STRUCT_LIT" },
|
||||
STRUCT_LIT_FIELD => &SyntaxInfo { name: "STRUCT_LIT_FIELD" },
|
||||
CALL_EXPR => &SyntaxInfo { name: "CALL_EXPR" },
|
||||
INDEX_EXPR => &SyntaxInfo { name: "INDEX_EXPR" },
|
||||
METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" },
|
||||
FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" },
|
||||
TRY_EXPR => &SyntaxInfo { name: "TRY_EXPR" },
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ impl RedNode {
|
|||
match &self.children.read()[idx] {
|
||||
Some(child) => return Some(child.into()),
|
||||
None => (),
|
||||
}
|
||||
};
|
||||
let green_children = self.green.children();
|
||||
let start_offset = self.start_offset()
|
||||
+ green_children[..idx]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue