Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dakkar

dakkar/param.p6 Secret

Created October 27, 2015 14:39
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 dakkar/07b3c50bdf899421489c to your computer and use it in GitHub Desktop.
Save dakkar/07b3c50bdf899421489c to your computer and use it in GitHub Desktop.
parametric tokens/rules in Perl6 Grammars
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