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

Req: Option to disable "grammar module name prefixing" #1321

Open
davidmcnabnz opened this issue Aug 14, 2023 · 1 comment
Open

Req: Option to disable "grammar module name prefixing" #1321

davidmcnabnz opened this issue Aug 14, 2023 · 1 comment

Comments

@davidmcnabnz
Copy link
Sponsor

Suggestion
Requesting a constructor option to disable the "double underscore" prefixing of targets based on grammar module names.

Consider grammar file main.lark:

%import foo.target_in_foo
...
start: sometarget

sometarget: othertarget
    | target_in_foo

and grammar file foo.lark

target_in_foo: t1 t2 t3 -> target_in_foo

when target_in_foo is fulfilled, the transformer call doesn't seek the method target_in_foo(). Instead, it seeks foo__target_in_foo(). This means that transformer alias methods need to carry the module name of the matched target.

For refactoring of grammar files ie moving targets between files, this adds the burden of also renaming the transformer target methods.

Describe alternatives you've considered
In my transformer class, I have patched around this by adding a __getattr__() shim, which detects the modulename__ prefixes and strips them, returning references for target alias methods that are named without the prefixes.

@erezsh
Copy link
Member

erezsh commented Aug 15, 2023

Have you tried merge_transformers() for solving this use-case?

Read through this: https://github.com/lark-parser/lark/tree/master/examples/composition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants