-
-
Save snarkyboojum/1344813 to your computer and use it in GitHub Desktop.
META.info parser not worky
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
#use Grammar::Tracer; | |
grammar FakeJSON { | |
token TOP { | |
'[' | |
<project>+ % ',' | |
']' | |
} | |
token project { | |
'{' | |
<pair>+ % ',' | |
'}' | |
} | |
token pair { | |
<key> ':' <value> | |
} | |
token key { | |
<string> | |
} | |
token value { | |
<string> || <array> | |
} | |
token string { | |
'"' <-[\"]>* '"' | |
} | |
token array { | |
'[' | |
[ <string>+ % ',' ]? | |
']' | |
} | |
} | |
class FakeJSON::Actions { | |
method TOP($/) { | |
make $<project>».ast; | |
} | |
method project($/) { | |
make $<pair>».ast.hash; | |
} | |
method pair($/) { | |
make Pair.new(key => $<key>.ast, value => $<value>.ast); | |
} | |
method key($/) { | |
make $<string>.ast; | |
} | |
method value($/) { | |
if $<string> { make $<string>.ast } | |
else { make $<array>.ast } | |
} | |
method string($/) { make ~$/ } | |
method array($/) { | |
if $<string> { | |
make $<string>».ast | |
} else { | |
make [] | |
} | |
} | |
} | |
my $json = q<[{"source-url":"git://github.com/tadzik/perl6-Acme-Meow.git","version":"*","name":"Acme::Meow","description":"The kitty you always wanted, now in Perl 6","depends":[]}]>; | |
my $ast = FakeJSON.parse($json, :actions(FakeJSON::Actions.new)); | |
say $ast.perl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment