Last active
April 11, 2018 21:00
-
-
Save ronaldxs/c6fc4545962c015ae659e47bac8c84f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 v6; | |
my token param-x { | |
<[ab]>+ { say <matched word only> } || | |
[ \w+ { say <after first word> } '=' \w+ ] | |
} | |
my token param-y { | |
[ \w+ {say 'after first word'} '=' {say <after equals> } \w+ ] || | |
<[ab]>+ | |
} | |
say 'These should not backtrack and match but do:'; | |
say so 'a=b' ~~ /<param-x>/; | |
say so 'a' ~~ /<param-y>/; | |
# two examples repeated below in context | |
print "\n\nAFAICT none of the cases below should match if it needs to backtrack ...\n"; | |
say '------'; | |
say "'a' backtrack on '=' need backtrack - no match: ", | |
so 'a' ~~ /<param-x>/; # no need to backtrack | |
say "'a=b' backtrack on '=' need backtrack - yes match: ", | |
so 'a=b' ~~ /<param-x>/; # seems to backtrack | |
say "'(a)' backtrack on '=' need backtrack - no match: ", | |
so '(a)' ~~ / '(' <param-x> ')' /; # no need to backtrack | |
say "'(a=b)' backtrack on '=' need backtrack - yes match: ", | |
so '(a=b)' ~~ / '(' <param-x> ')' /; # seems not to backtrack | |
say "'a' backtrack on not '=' need backtrack - yes match: ", | |
so 'a' ~~ /<param-y>/; # seems to backtrack | |
say "'a=b' backtrack on not '=' need backtrack - no match: ", | |
so 'a=b' ~~ /<param-y>/; # no need to backtrack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment