Skip to content

Instantly share code, notes, and snippets.

@ronaldxs
Last active April 11, 2018 21:00
Show Gist options
  • Save ronaldxs/c6fc4545962c015ae659e47bac8c84f3 to your computer and use it in GitHub Desktop.
Save ronaldxs/c6fc4545962c015ae659e47bac8c84f3 to your computer and use it in GitHub Desktop.
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