From 490d3206331f3bae8c2365e10ab5cf2c0afae61a Mon Sep 17 00:00:00 2001 From: John Date: Mon, 26 Feb 2024 15:37:07 -0600 Subject: [PATCH] parser: allow end of input in binary and indexing operations. This improves robustness and correctness of implementation. --- libconlang/src/parser.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libconlang/src/parser.rs b/libconlang/src/parser.rs index 0af7046..ac1e966 100644 --- a/libconlang/src/parser.rs +++ b/libconlang/src/parser.rs @@ -802,7 +802,7 @@ macro binary($($name:ident {$lower:ident, $op:ident})*) { loop { match self.$op() { 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)?, } } @@ -902,7 +902,7 @@ impl<'t> Parser<'t> { pub fn exprkind_index(&mut self) -> PResult { const PARSING: Parsing = Parsing::Index; 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); }