Last active
June 13, 2016 03:02
-
-
Save agwind/055b50c52026845c4b5d1c9b100f28d8 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 { | |
method TOP($/) { | |
$/.make: $<row>.made; | |
} | |
method row($/) { | |
#say $/.perl; | |
$/.make: *.ast; | |
} | |
method number($/) { | |
$/.make: %translate{$/.lc}; | |
} | |
method period($/) { | |
$/.make: ','; | |
} | |
} | |
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