-
-
Save zoffixznet/be2ca6fb9de2318d8fece1132a4f4525 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
class Law::Actions { | |
method key($/) { make $/.Str } | |
method value($/) { make $/.Str } | |
method object($/) { make $/[0].Str } | |
method law($/) { make $<key>.made => $<value>.made } | |
method block($/) { make $<law>.map({ .made }).hash } | |
method realm($/) { make $<object>.made => $<block>.made } | |
method TOP($/) { make $<realm>.map: { .made } } | |
} | |
grammar Law { | |
token key { \w+ } | |
token value { <!before \s> <-[\n #]>+ <!after \s> } | |
token law { <key> <space>+ <value> \n+ } | |
token object { | |
'<' ( <-[ \< \> \n ]>+ ) | |
[ <?{ $/[0] eq 'dev' }> || {die "Don't know what $/[0] category is"} ] | |
'>' \n+ | |
} | |
token comment { '#' \N*\n+ } | |
token block { [<law> | <comment>]* } | |
token realm { <object> <block> } | |
token TOP { <realm>* } | |
method create(Str $laws) { | |
my $m = self.parsefile($laws, :actions(Law::Actions)); | |
die "Usage:" unless $m; | |
return $m.made; | |
} | |
} | |
say Law.parse: q:to/END/ | |
<main> | |
key value | |
<dev> | |
key value | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment