Default anchoring of .parse method?
pmichaud opened this issue · 2 comments
pmichaud commented
Should TOP (or any other grammar regex) be considered to have implied $-anchors when invoked from .parse? (See RT #77022.) Example:
grammar B { regex TOP { b } };
say B.parse('bcd'); # failed match?
See also discussion at http://irclog.perlgeek.de/perl6/2013-03-06#i_6556613 .
Pm
colomon commented
I don't know what the correct default is, but I think whichever way that goes, there should be a switch to control the behavior:
B.parse('bcd', :anchored); # or maybe
B.parse('bcd', :unanchored); # definitely better name needed here
If nothing else, this will make unit testing of non-TOP regexes much less intrusive:
my $match = ABC::Grammar.parse("g>ecg ec e/f/g/e/ |", :rule<bar>, :anchored);
versus
my $match = ABC::Grammar.parse("g>ecg ec e/f/g/e/ |", :rule<bar-anchored>);