Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagate_positions isn't well documented #1293

Closed
ningit opened this issue Jun 28, 2023 · 5 comments
Closed

propagate_positions isn't well documented #1293

ningit opened this issue Jun 28, 2023 · 5 comments
Labels
add to docs TODO: Include this information in the docs question

Comments

@ningit
Copy link

ningit commented Jun 28, 2023

Describe the bug

The keyword argument propagate_positions of Lark constructor is not obeyed. The attributes line, column, end_line, and end_column are not available in the Tree objects returned by Lark.parse.

To Reproduce

In the following code, the last two lines produce an AttributeError: 'Tree' object has no attribute 'line', while they should return 1.

import lark

grammar = '''
	%import common.WS
	%ignore WS

	%import common.INT -> NUMBER

	start: expr

	expr: NUMBER
	    | NUMBER "+" NUMBER
'''

parser = lark.Lark(grammar, parser='lalr', propagate_positions=True)
tree = parser.parse('1 + 2')

print(tree.children[0].children[0].line)
print(tree.children[0].line)
print(tree.line)
@erezsh
Copy link
Member

erezsh commented Jun 28, 2023 via email

@ningit
Copy link
Author

ningit commented Jun 29, 2023

Many thanks and sorry. Now I see this is mentioned in the documentation for the constructor of the Tree class.

Anyhow, making explicit that these attributes are available through meta in the documentation of the propagate_positions option itself may avoid confusion and help users.

@erezsh erezsh added question add to docs TODO: Include this information in the docs labels Jun 29, 2023
@erezsh erezsh changed the title propagate_positions does not work propagate_positions ~does not work~ not well documented Jun 29, 2023
@erezsh erezsh changed the title propagate_positions ~does not work~ not well documented propagate_positions ~~does not work~~ not well documented Jun 29, 2023
@erezsh erezsh changed the title propagate_positions ~~does not work~~ not well documented propagate_positions isn't well documented Jun 29, 2023
@erezsh
Copy link
Member

erezsh commented Jun 29, 2023

@ningit I added a PR #1294

@ningit
Copy link
Author

ningit commented Jun 29, 2023

Great, it is now clearer. I think the PR solves the issue.

@erezsh
Copy link
Member

erezsh commented Jul 3, 2023

Great! Added even more explanations too.

@erezsh erezsh closed this as completed Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to docs TODO: Include this information in the docs question
Projects
None yet
Development

No branches or pull requests

2 participants