-
-
Save dakkar/07b3c50bdf899421489c to your computer and use it in GitHub Desktop.
parametric tokens/rules in Perl6 Grammars
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
use v6.0.0; | |
use Test; | |
grammar Parametric { | |
rule TOP { <header('foo')> <header('bar')> } | |
token header($name, $sub-header = "{$name}-header") { | |
^^ [:i $name ] ':' <.ws> <::($sub-header)> \n | |
} | |
token foo-header { <[ab]>+ } | |
token bar-header { <[cd]>+ } | |
} | |
sub test-it($str) { | |
note $str.perl; | |
my $result = Parametric.parse($str); | |
ok $result, 'should match'; | |
note $/.perl; | |
} | |
subtest { | |
test-it q:heredoc/END/; | |
Foo: abababa | |
Bar: cdcdcdcd | |
END | |
},'simple case'; | |
done-testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment