If you transform this into
class TestParser < Parslet::Parser
rule(:rule1) {
str('a')
}
rule(:rule2) {
str('b')
}
rule(:rule3) {
( rule1 >> rule2.as(:b1) ) | rule2.as(:b2)
}
rule(:rule4) {
rule3
}
end
it works as it should. Not sure what this says about the original example.
In general, using alternation ('|') is preferrable to using #present?.
Demand that the parser match the most complicated thing first, then
backtrack (on failure) and match something simpler next.
regards,
kaspar
