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
|
||||||
@@ -136,7 +137,14 @@ class MidasParser(Parser):
|
|||||||
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