Created
November 1, 2016 01:51
-
-
Save gfldex/fcd52d39ae9bf4288f3a5952d13717c0 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 Schematics { | |
my $curr_product; | |
my $curr_line = 0; | |
token TOP { ^ <line>+ $ } | |
rule line { | |
{ $curr_line++ } | |
<product> \h* '<-' \h* [ <components> | <isk> ] | |
} | |
token itemname { [ '-' | \w | [\h\w] ]+ } | |
token amount { ['-']?\d+[.\d+]? } | |
token product { | |
[ (<amount>) \h ]? (<itemname>) | |
{ | |
$curr_product = Product.new(:name($1.Str), :stacksize($0 ?? $0.Str.Int !! 1)); | |
} | |
} | |
token components { | |
[ | |
<isk> | |
| [ (<amount>) \h (<itemname>) ] { $curr_product.components.push($1.Str => ($0 / $curr_product.stacksize).Rat ); } | |
] | |
[\h* ',' \h* <components>]* | |
| { die "match failed at: ", $curr_line } | |
} | |
token isk { | |
(<amount>) \s* 'ISK' | |
{ | |
$curr_product.components.push( ISK.new(:amount($0.Num)) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment