Working on #48 : Fixed ExpressionParser.py
This commit is contained in:
@@ -401,8 +401,8 @@ class BaseExpressionParser(BaseParser):
|
|||||||
def parse_tokens(self, context, parser_input, error_sink):
|
def parse_tokens(self, context, parser_input, error_sink):
|
||||||
def stop():
|
def stop():
|
||||||
return token.type == TokenKind.EOF or \
|
return token.type == TokenKind.EOF or \
|
||||||
paren_count == 0 and token.type == TokenKind.RPAR or \
|
paren_count == 0 and (token.type == TokenKind.RPAR or
|
||||||
self.parse_tokens_stop_condition(token, parser_input)
|
self.parse_tokens_stop_condition(token, parser_input))
|
||||||
|
|
||||||
token = parser_input.token
|
token = parser_input.token
|
||||||
if token.type == TokenKind.EOF:
|
if token.type == TokenKind.EOF:
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class VariableOrNamesParser(BaseExpressionParser):
|
|||||||
pos = parser_input.pos
|
pos = parser_input.pos
|
||||||
for i, token in enumerate(parser_input.as_tokens()):
|
for i, token in enumerate(parser_input.as_tokens()):
|
||||||
if token.type == TokenKind.DOT:
|
if token.type == TokenKind.DOT:
|
||||||
dots_found.append(i)
|
dots_found.append(i + pos)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not (token.type == TokenKind.WHITESPACE or
|
if not (token.type == TokenKind.WHITESPACE or
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ class TestExpressionParser(TestUsingMemoryBasedSheerka):
|
|||||||
("func1(one, 1 + 2, func2(3))", FN("func1(", (")", 1), [(VAR("one"), ", "),
|
("func1(one, 1 + 2, func2(3))", FN("func1(", (")", 1), [(VAR("one"), ", "),
|
||||||
(EXPR("1 + 2"), ", "),
|
(EXPR("1 + 2"), ", "),
|
||||||
FN("func2(", ")", [EXPR("3")])])),
|
FN("func2(", ")", [EXPR("3")])])),
|
||||||
|
("func(var.attr)", FN("func(", ")", [VAR("var.attr")])),
|
||||||
|
("func(var1.attr1 and var2.attr2)", FN("func(", ")", [AND(VAR("var1.attr1"), VAR("var2.attr2"))])),
|
||||||
|
("func(var1.attr1 > var2.attr2)", FN("func(", ")", [GT(VAR("var1.attr1"), VAR("var2.attr2"))])),
|
||||||
|
("func1(var1) and func2(var2)", AND(FN("func1(", ")", [VAR("var1")]), FN("func2(", (")", 1), [VAR("var2")])))
|
||||||
])
|
])
|
||||||
def test_i_can_parse_input(self, expression, expected):
|
def test_i_can_parse_input(self, expression, expected):
|
||||||
sheerka, context, parser, parser_input, error_sink = self.init_parser_with_source(expression)
|
sheerka, context, parser, parser_input, error_sink = self.init_parser_with_source(expression)
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class TestLogicalOperatorParser(TestUsingMemoryBasedSheerka):
|
|||||||
(")", BuiltinConcepts.NOT_FOR_ME, TokenKind.RPAR, 0),
|
(")", BuiltinConcepts.NOT_FOR_ME, TokenKind.RPAR, 0),
|
||||||
("one and two(", BuiltinConcepts.ERROR, TokenKind.LPAR, 11),
|
("one and two(", BuiltinConcepts.ERROR, TokenKind.LPAR, 11),
|
||||||
("one (", BuiltinConcepts.NOT_FOR_ME, TokenKind.LPAR, 4),
|
("one (", BuiltinConcepts.NOT_FOR_ME, TokenKind.LPAR, 4),
|
||||||
("one (and", BuiltinConcepts.ERROR, TokenKind.LPAR, 4),
|
("one (and", BuiltinConcepts.NOT_FOR_ME, TokenKind.LPAR, 4),
|
||||||
("one and two)", BuiltinConcepts.ERROR, TokenKind.RPAR, 11),
|
("one and two)", BuiltinConcepts.ERROR, TokenKind.RPAR, 11),
|
||||||
("one )", BuiltinConcepts.ERROR, TokenKind.RPAR, 4),
|
("one )", BuiltinConcepts.ERROR, TokenKind.RPAR, 4),
|
||||||
("one ) and", BuiltinConcepts.ERROR, TokenKind.RPAR, 4),
|
("one ) and", BuiltinConcepts.ERROR, TokenKind.RPAR, 4),
|
||||||
|
|||||||
Reference in New Issue
Block a user