wip -- start indexing work

This commit is contained in:
2025-12-21 00:47:47 -07:00
parent 5dbb0ee2d7
commit 3a8f0e84af
3 changed files with 17 additions and 2 deletions

View File

@@ -13,6 +13,6 @@ lsp-types = { workspace = true }
rust_decimal = { workspace = true } rust_decimal = { workspace = true }
[dev-dependencies] [dev-dependencies]
anyhow = { version = "1.0" } anyhow = { workspace = true }
indoc = { version = "2.0" } indoc = { version = "2.0" }
pretty_assertions = "1" pretty_assertions = "1"

View File

@@ -308,7 +308,7 @@ impl<'a> Parser<'a> {
Ok(Some(lhs)) Ok(Some(lhs))
} }
/// Handles dot notation chains: x.y.z() /// Handles dot notation chains (x.y.z()) and array indexing (x[0])
fn parse_postfix( fn parse_postfix(
&mut self, &mut self,
mut lhs: Spanned<Expression<'a>>, mut lhs: Spanned<Expression<'a>>,
@@ -411,6 +411,9 @@ impl<'a> Parser<'a> {
}), }),
}; };
} }
} else if self_matches_peek!(self, TokenType::Symbol(Symbol::LBracket)) {
// consume the `[` token
self.assign_next()?;
} else { } else {
break; break;
} }

View File

@@ -174,6 +174,18 @@ impl<'a> std::fmt::Display for MemberAccessExpression<'a> {
} }
} }
#[derive(Debug, PartialEq, Eq)]
pub struct MemberIndexingExpression<'a> {
pub object: LiteralOrVariable<'a>,
pub index_of: Box<Spanned<Expression<'a>>>,
}
impl<'a> std::fmt::Display for MemberIndexingExpression<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}[{}]", self.object, self.index_of)
}
}
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct MethodCallExpression<'a> { pub struct MethodCallExpression<'a> {
pub object: Box<Spanned<Expression<'a>>>, pub object: Box<Spanned<Expression<'a>>>,