Closed robinsierra closed 4 years ago
The problem seems to be in this part of the grammar:
?stmt: simple_stmt | compound_stmt
?simple_stmt: small_stmt (";" small_stmt)* [";"] _NEWLINE
?small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
When printing the end_line information in parse_tree_builder.py
when it gets assigned shows that the end_line information of the token _NEWLINE
is None, but it is still assigned. Changing the loop
for c in reversed(children):
if isinstance(c, Tree) and c.children and not c.meta.empty:
res.meta.end_line = c.meta.end_line
res.meta.end_column = c.meta.end_column
res.meta.end_pos = c.meta.end_pos
res.meta.empty = False
break
elif isinstance(c, Token) and not c.end_line is None: # This is new
res.meta.end_line = c.end_line
res.meta.end_column = c.end_column
res.meta.end_pos = c.pos_in_stream + len(c.value)
res.meta.empty = False
break
fixes the problem, as it then leaves out tokens where the end_line information is None.
Thanks for reporting it. The latest commit to master
should solve the issue. (the problem was in the lexer all along)
It's working for me. Thanks a lot for fixing it!
You're welcome
When using the current Python 3 example grammar Lark doesn't generate end_line information at the end of a block, e.g., for the last statement in the body of a
for
loop. Example program:If you change
python_parser.py
toand pass to it the python file mentioned before it prints
instead of the correct line numbers, even though propagate_positions is True.