lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.62k stars 395 forks source link

Transformer raises AttributeError when a tree is only a token #1394

Closed The-Arx closed 4 months ago

The-Arx commented 4 months ago

Describe the bug

When a token is the outermost layer of a tree, transformer raises AttributeError: 'Token' object has no attribute 'children'.

Here is a simple program causing the bug.


from lark import Lark, Transformer

l = Lark("""?start: INT

            %import common.INT
        """)

class MyTransformer(Transformer):
    def INT(self, value):
        return int(value)

tree = l.parse("123") # Token('INT', '123')

MyTransformer().transform(tree)
erezsh commented 4 months ago

Fixed. Thanks for reporting.