Created
January 25, 2019 21:45
-
-
Save lucs/0f64cd5448ccfb8a94d18285bea34f7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar Goo { | |
rule TOP { <Foo>+ } | |
rule Foo { 'foo' <Num> <Bar>+ } | |
rule Bar { 'bar' <Num>+ } | |
rule Num { \d+ } | |
} | |
class GooActions { | |
method Bar ($/) { | |
say "This Bar is contained in a Foo whose Num is ???"; | |
} | |
} | |
Goo.new.parse( | |
'foo 111 bar 2 3 bar 4 foo 222 bar 5 6', | |
:actions(GooActions.new) | |
); | |
#`( | |
How can I get the Bar action method to see its Foo container | |
rule's Num, to have this printed?: | |
This Bar is contained in a Foo whose Num is 111 | |
This Bar is contained in a Foo whose Num is 111 | |
This Bar is contained in a Foo whose Num is 222 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use a dynamic variable to propagate the desired information down into the nested rules: