fix(parser): handle extra tokens in Midas parser
This commit is contained in:
@@ -62,6 +62,7 @@ class MidasParser(Parser):
|
|||||||
return self.op_declaration()
|
return self.op_declaration()
|
||||||
if self.match(TokenType.CONSTRAINT):
|
if self.match(TokenType.CONSTRAINT):
|
||||||
return self.constraint_declaration()
|
return self.constraint_declaration()
|
||||||
|
raise self.error(self.peek(), "Unexpected token")
|
||||||
except ParsingError:
|
except ParsingError:
|
||||||
self.synchronize()
|
self.synchronize()
|
||||||
return None
|
return None
|
||||||
@@ -111,7 +112,7 @@ class MidasParser(Parser):
|
|||||||
Returns:
|
Returns:
|
||||||
ConstraintExpr: the parsed type constraint expression
|
ConstraintExpr: the parsed type constraint expression
|
||||||
"""
|
"""
|
||||||
|
|
||||||
left: Expr = self.constraint_value()
|
left: Expr = self.constraint_value()
|
||||||
op: Token = self.constraint_operator()
|
op: Token = self.constraint_operator()
|
||||||
right: Expr = self.constraint_value()
|
right: Expr = self.constraint_value()
|
||||||
@@ -129,14 +130,21 @@ class MidasParser(Parser):
|
|||||||
return LiteralExpr(True)
|
return LiteralExpr(True)
|
||||||
if self.match(TokenType.NONE):
|
if self.match(TokenType.NONE):
|
||||||
return LiteralExpr(None)
|
return LiteralExpr(None)
|
||||||
|
|
||||||
if self.match(TokenType.NUMBER):
|
if self.match(TokenType.NUMBER):
|
||||||
return LiteralExpr(self.previous().value)
|
return LiteralExpr(self.previous().value)
|
||||||
|
|
||||||
raise self.error(self.peek(), "Expected literal")
|
raise self.error(self.peek(), "Expected literal")
|
||||||
|
|
||||||
def constraint_operator(self) -> Token:
|
def constraint_operator(self) -> Token:
|
||||||
if self.match(TokenType.LESS, TokenType.LESS_EQUAL, TokenType.GREATER, TokenType.GREATER_EQUAL, TokenType.EQUAL_EQUAL, TokenType.BANG_EQUAL):
|
if self.match(
|
||||||
|
TokenType.LESS,
|
||||||
|
TokenType.LESS_EQUAL,
|
||||||
|
TokenType.GREATER,
|
||||||
|
TokenType.GREATER_EQUAL,
|
||||||
|
TokenType.EQUAL_EQUAL,
|
||||||
|
TokenType.BANG_EQUAL,
|
||||||
|
):
|
||||||
return self.previous()
|
return self.previous()
|
||||||
raise self.error(self.peek(), "Expected constraint operator")
|
raise self.error(self.peek(), "Expected constraint operator")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user