wip -- start indexing work
This commit is contained in:
@@ -308,7 +308,7 @@ impl<'a> Parser<'a> {
|
||||
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(
|
||||
&mut self,
|
||||
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 {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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)]
|
||||
pub struct MethodCallExpression<'a> {
|
||||
pub object: Box<Spanned<Expression<'a>>>,
|
||||
|
||||
Reference in New Issue
Block a user