Created
July 11, 2013 15:21
-
-
Save cognominal/5976412 to your computer and use it in GitHub Desktop.
calling .parse in a TOP action causes problems
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
use Test; | |
grammar P { token TOP { a } } | |
class P::A { method TOP ($/) { } } | |
sub a { P.parse: 'a', :actions(P::A); } | |
ok P.parse('a', :actions(P::A)) eq 'a', 'call to parse'; | |
grammar G { token TOP { a } } | |
class G::A { method TOP($/) { a() } } | |
ok G.parse('a', :actions(G::A)) eq 'a', 'indirect call to parse within a parse'; | |
class G::B { method TOP($/) { P.parse: 'a', :actions(P::A); } } | |
ok try { G.parse('a', :actions(G::B)) } eq 'a', 'direct call to parse within a parse'; | |
G.parse('a', :actions(G::B)); # same but without a 'try {}' | |
=begin END | |
ok 1 - call to parse | |
ok 2 - indirect call to parse within a parse | |
not ok 3 - direct call to parse within a parse | |
Cannot assign to a readonly variable or a value | |
in method parse at src/gen/CORE.setting:10877 | |
in method TOP at o.p6:13 | |
in any !reduce at src/stage2/QRegex.nqp:667 | |
in any !cursor_pass at src/stage2/QRegex.nqp:631 | |
in regex TOP at o.p6:8 | |
in method parse at src/gen/CORE.setting:10877 | |
in block at o.p6:15 | |
Parsing within a parse causes all sorts of (related?) problems. | |
Seems related to actions. | |
Here is my first attempts at reducing the problem to minimal code. | |
What it does : the Grammar G TOP action calls a parser in grammar P. | |
If I use an indirection, doing the P parser call within the function A, there is no problem. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment