Skip to content

Instantly share code, notes, and snippets.

@moritz
Created October 12, 2014 20:27
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 moritz/730031f70a2e2df686df to your computer and use it in GitHub Desktop.
Save moritz/730031f70a2e2df686df to your computer and use it in GitHub Desktop.
Trying to construct a proto token
use v6;
my $re = rx{ a+ };
my $str = 'ab';
my $grammar := (grammar {}).HOW.new_type();
my $HOW := $grammar.HOW;
$HOW.add_method($grammar, 'trans', my proto token trans {*});
$HOW.add_method($grammar, "trans:sym<1>", $re);
$HOW.add_method($grammar, "trans:sym<2>", regex { $str });
$HOW.add_method($grammar, 'TOP', token { <trans> });
$HOW.compose($grammar);
say $grammar.new.parse('ab'); # Any
# vim: ft=perl6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment