Fix error reporting in the parser
This commit is contained in:
parent
0df6a263e5
commit
31a59e1de0
@ -286,7 +286,7 @@ def parse_tokens(expression: List[Union[list, str]]) -> Node:
|
|||||||
if len(expression) == 1:
|
if len(expression) == 1:
|
||||||
if not rtypes.is_valid_relation_name(expression[0]):
|
if not rtypes.is_valid_relation_name(expression[0]):
|
||||||
raise ParserException(
|
raise ParserException(
|
||||||
u"'%s' is not a valid relation name" % expression[0])
|
f'{expression[0]!r} is not a valid relation name')
|
||||||
return Variable(expression[0]) #FIXME Move validation in the object
|
return Variable(expression[0]) #FIXME Move validation in the object
|
||||||
|
|
||||||
# Expression from right to left, searching for binary operators
|
# Expression from right to left, searching for binary operators
|
||||||
@ -302,21 +302,20 @@ def parse_tokens(expression: List[Union[list, str]]) -> Node:
|
|||||||
for i in range(len(expression) - 1, -1, -1):
|
for i in range(len(expression) - 1, -1, -1):
|
||||||
if expression[i] in b_operators: # Binary operator
|
if expression[i] in b_operators: # Binary operator
|
||||||
|
|
||||||
|
|
||||||
if len(expression[:i]) == 0:
|
if len(expression[:i]) == 0:
|
||||||
raise ParserException(
|
raise ParserException(
|
||||||
u"Expected left operand for '%s'" % self.name)
|
f'Expected left operand for {expression[i]!r}')
|
||||||
|
|
||||||
if len(expression[i + 1:]) == 0:
|
if len(expression[i + 1:]) == 0:
|
||||||
raise ParserException(
|
raise ParserException(
|
||||||
u"Expected right operand for '%s'" % self.name)
|
f'Expected right operand for {expression[i]!r}')
|
||||||
return Binary(expression[i], parse_tokens(expression[:i]), parse_tokens(expression[i + 1:]))
|
return Binary(expression[i], parse_tokens(expression[:i]), parse_tokens(expression[i + 1:]))
|
||||||
'''Searches for unary operators, parsing from right to left'''
|
'''Searches for unary operators, parsing from right to left'''
|
||||||
for i in range(len(expression) - 1, -1, -1):
|
for i in range(len(expression) - 1, -1, -1):
|
||||||
if expression[i] in u_operators: # Unary operator
|
if expression[i] in u_operators: # Unary operator
|
||||||
if len(expression) <= i + 2:
|
if len(expression) <= i + 2:
|
||||||
raise ParserException(
|
raise ParserException(
|
||||||
u"Expected more tokens in '%s'" % self.name)
|
f'Expected more tokens in {expression[i]!r}')
|
||||||
|
|
||||||
return Unary(
|
return Unary(
|
||||||
expression[i],
|
expression[i],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user