Allow chaining of array indexing operations.
This commit is contained in:
parent
d8ec7ed141
commit
07e396b3f5
@ -1189,7 +1189,7 @@ fn parse_primary<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Expr, Pa
|
|||||||
|
|
||||||
let mut follow_on = false;
|
let mut follow_on = false;
|
||||||
|
|
||||||
let r = match token {
|
let mut root_expr = match token {
|
||||||
Some((Token::IntegerConstant(x), pos)) => Ok(Expr::IntegerConstant(x, pos)),
|
Some((Token::IntegerConstant(x), pos)) => Ok(Expr::IntegerConstant(x, pos)),
|
||||||
Some((Token::FloatConstant(x), pos)) => Ok(Expr::FloatConstant(x, pos)),
|
Some((Token::FloatConstant(x), pos)) => Ok(Expr::FloatConstant(x, pos)),
|
||||||
Some((Token::CharConstant(c), pos)) => Ok(Expr::CharConstant(c, pos)),
|
Some((Token::CharConstant(c), pos)) => Ok(Expr::CharConstant(c, pos)),
|
||||||
@ -1222,18 +1222,16 @@ fn parse_primary<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Expr, Pa
|
|||||||
}?;
|
}?;
|
||||||
|
|
||||||
if !follow_on {
|
if !follow_on {
|
||||||
return Ok(r);
|
return Ok(root_expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post processing
|
// Tail processing all possible indexing
|
||||||
match input.peek() {
|
while let Some(&(Token::LeftBracket, _)) = input.peek() {
|
||||||
Some(&(Token::LeftBracket, _)) => {
|
input.next();
|
||||||
// Possible indexing
|
root_expr = parse_index_expr(Box::new(root_expr), input)?;
|
||||||
input.next();
|
|
||||||
parse_index_expr(Box::new(r), input)
|
|
||||||
}
|
|
||||||
_ => Ok(r),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(root_expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_unary<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Expr, ParseError> {
|
fn parse_unary<'a>(input: &mut Peekable<TokenIterator<'a>>) -> Result<Expr, ParseError> {
|
||||||
|
Loading…
Reference in New Issue
Block a user