cleaner match and returning

This commit is contained in:
mos 2024-07-28 09:50:12 +02:00
parent 2531b4ac0d
commit 32d068649c
1 changed files with 4 additions and 6 deletions

View File

@ -221,11 +221,11 @@ impl<'a> Parser<'a> {
match *self.peek()? { match *self.peek()? {
Symbol::Eq => { Symbol::Eq => {
self.next(); self.next();
return Ok(Node::new(NodeOp::Assign, vec![lhs, self.parse_expr()?])); Ok(Node::new(NodeOp::Assign, vec![lhs, self.parse_expr()?]))
} }
Symbol::Term => { Symbol::Term => {
self.next(); self.next();
return Ok(lhs); Ok(lhs)
} }
Symbol::Id(_) | Symbol::Int(_) => { Symbol::Id(_) | Symbol::Int(_) => {
loop { loop {
@ -238,12 +238,10 @@ impl<'a> Parser<'a> {
} }
self.expect(Symbol::Term, ParseError::ExpectedTerm)?; self.expect(Symbol::Term, ParseError::ExpectedTerm)?;
self.next(); self.next();
return Ok(lhs); Ok(lhs)
} }
_ => (), _ => Err(ParseError::Eof),
} }
Err(ParseError::Eof)
} }
pub fn parse(&mut self) -> ParseResult<Vec<Node>> { pub fn parse(&mut self) -> ParseResult<Vec<Node>> {