Closed ningit closed 1 year ago
It's tree.meta
On Wed, 28 Jun 2023 at 21:31, ningit @.***> wrote:
Describe the bug
The keyword argument propagate_positions of Lark https://lark-parser.readthedocs.io/en/latest/classes.html#lark.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)
— Reply to this email directly, view it on GitHub https://github.com/lark-parser/lark/issues/1293, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFSSSD4QKACQRQG45TXHXTXNR2ARANCNFSM6AAAAAAZXQB4NU . You are receiving this because you are subscribed to this thread.Message ID: @.***>
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.
@ningit I added a PR https://github.com/lark-parser/lark/pull/1294
Great, it is now clearer. I think the PR solves the issue.
Great! Added even more explanations too.
Describe the bug
The keyword argument
propagate_positions
of Lark constructor is not obeyed. The attributesline
,column
,end_line
, andend_column
are not available in theTree
objects returned byLark.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.