Created
October 12, 2014 20:27
-
-
Save moritz/730031f70a2e2df686df to your computer and use it in GitHub Desktop.
Trying to construct a proto token
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; | |
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