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

Transformer.__default__ not called in tree-less LALR mode #1029

Closed
RoadrunnerWMC opened this issue Nov 6, 2021 · 1 comment
Closed

Transformer.__default__ not called in tree-less LALR mode #1029

RoadrunnerWMC opened this issue Nov 6, 2021 · 1 comment

Comments

@RoadrunnerWMC
Copy link

Describe the bug

The __default__ method on Transformers is never called when using "Tree-less LALR" mode.

To Reproduce

Here's an example based on "ab.lark" from the unit tests. __default__() should be called for every rule here, but when using tree-less LALR mode (change BUILD_TREE to False), it's not called at all.

from lark import Lark, Transformer

BUILD_TREE = True  # Change to False to try tree-less LALR mode

grammar = r"""
    start: expr

    expr: A B
        | A expr B

    A: "a"
    B: "b"

    %import common.WS
    %ignore WS
"""

class AbTransformer(Transformer):
    def __default__(self, data, children, meta):
        print(f'__default__({data!r}, {children!r}, {meta!r})')
        return data

def parse(x):
    if BUILD_TREE:
        parser = Lark(grammar, parser='lalr')
        return AbTransformer().transform(parser.parse(x))
    else:
        parser = Lark(grammar, parser='lalr', transformer=AbTransformer())
        return parser.parse(x)

print(parse('a a a b b b'))  # should print "start"
@erezsh
Copy link
Member

erezsh commented Nov 16, 2021

A fix is ready. See #1036

@erezsh erezsh closed this as completed Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants