Skip to content

Instantly share code, notes, and snippets.

@ronaldxs
Created January 20, 2017 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronaldxs/8cb7de26fedcf8ed3c75984f5aa87b54 to your computer and use it in GitHub Desktop.
Save ronaldxs/8cb7de26fedcf8ed3c75984f5aa87b54 to your computer and use it in GitHub Desktop.
# https://design.perl6.org/S05.html#Longest-token_matching says:
# If the alternatives are in the same grammar file, the
# textually earlier alternative takes precedence.
use Test;
grammar text-order {
token alt-na_1 { <n> | <na_1> };
token alt-na_2 { <n> | <na_2> };
token n { <digit>+ }
token na_1 { <+alpha +digit> + }
token na_2 { <+alpha +[0..9]> + }
}
is text-order.parse('1', :rule<alt-na_1>).keys[0], 'n',
'Match first textual rule OK';
is text-order.parse('1', :rule<alt-na_2>).keys[0], 'n',
'Match second textual rule fail';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment