Created
June 13, 2016 03:21
-
-
Save zoffixznet/7ad25eb0a35382a4b33d78d00c205230 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
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($/) { | |
$/.make: join '', $/[0].map: { | |
$_<number>.defined ?? $_<number>.made !! $_<period>.made | |
}; | |
} | |
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)).made; | |
say $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment