Created
January 20, 2017 19:53
-
-
Save ronaldxs/8cb7de26fedcf8ed3c75984f5aa87b54 to your computer and use it in GitHub Desktop.
This file contains 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
# 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