parser: allow end of input in binary and indexing operations.

This improves robustness and correctness of implementation.
This commit is contained in:
John 2024-02-26 15:37:07 -06:00
parent 13995259aa
commit 490d320633

View File

@ -802,7 +802,7 @@ macro binary($($name:ident {$lower:ident, $op:ident})*) {
loop { loop {
match self.$op() { match self.$op() {
Ok(op) => tail.push((op, self.expr_from(Self::$lower)?)), Ok(op) => tail.push((op, self.expr_from(Self::$lower)?)),
Err(Error { reason: Unexpected(_), ..}) => break, Err(Error { reason: Unexpected(_) | EndOfInput, ..}) => break,
Err(e) => Err(e)?, Err(e) => Err(e)?,
} }
} }
@ -902,7 +902,7 @@ impl<'t> Parser<'t> {
pub fn exprkind_index(&mut self) -> PResult<ExprKind> { pub fn exprkind_index(&mut self) -> PResult<ExprKind> {
const PARSING: Parsing = Parsing::Index; const PARSING: Parsing = Parsing::Index;
let head = self.expr_from(Self::exprkind_primary)?; let head = self.expr_from(Self::exprkind_primary)?;
if Type::LBrack != self.peek_type(PARSING)? { if Ok(Type::LBrack) != self.peek_type(PARSING) {
return Ok(head.kind); return Ok(head.kind);
} }