parser: check error early

This commit is contained in:
anna 2021-04-26 18:40:57 +02:00
parent 4cc7d17c99
commit 47607a04fb
Signed by: fef
GPG key ID: EC22E476DC2D3D84

View file

@ -25,9 +25,9 @@ impl<'a> Parser<'a> {
), ),
TokenKind::StringLiteral => self.node_result(ident.raw, NodeVal::String(val.raw)), TokenKind::StringLiteral => self.node_result(ident.raw, NodeVal::String(val.raw)),
_ => self.lexer.syntax_error(String::from("Expected a value")), _ => self.lexer.syntax_error(String::from("Expected a value")),
}; }?;
self.require_kind(TokenKind::Semi)?; self.require_kind(TokenKind::Semi)?;
node Ok(node)
} }
fn require_kind(&mut self, kind: TokenKind) -> Result<Token, SyntaxError> { fn require_kind(&mut self, kind: TokenKind) -> Result<Token, SyntaxError> {