Last active
June 13, 2016 03:10
-
-
Save agwind/deaad9b98b77efd6747890fc2049cb79 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
#!/usr/bin/env perl6 | |
use v6; | |
#use Grammar::Debugger; | |
grammar TEST { | |
token TOP { | |
<row> | |
} | |
token row { | |
\[ (<number> | <period> ) ** 0..* \] | |
} | |
token period { | |
\. | |
} | |
token number { | |
'one' | 'two' | 'three' | 'four' | 'five' | |
} | |
}; | |
my %translate = | |
'one' => 1, | |
'two' => 2, | |
'three' => 3, | |
'four' => 4, | |
'five' => 5, | |
; | |
class TEST::Action { | |
has Str $!rowstr = ''; | |
method TOP($/) { | |
$/.make: $<row>.made; | |
#say $<row>; | |
} | |
method row($/) { | |
$/.make: ~$!rowstr; | |
$!rowstr = ''; | |
} | |
method number($/) { | |
$!rowstr = $!rowstr ~ %translate{$/.lc}; | |
} | |
method period($/) { | |
$!rowstr = $!rowstr ~ ',' | |
} | |
} | |
my $string = "[one.two.three.two]"; | |
my $action = TEST::Action.new(); | |
my $output = TEST.parse($string, :actions($action)).ast; | |
say $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment