lark icon indicating copy to clipboard operation
lark copied to clipboard

Req: Option to disable "grammar module name prefixing"

Open davidmcnabnz opened this issue 10 months ago • 1 comments

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.

davidmcnabnz avatar Aug 14 '23 20:08 davidmcnabnz