Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created November 7, 2011 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tadzik/1344631 to your computer and use it in GitHub Desktop.
Save tadzik/1344631 to your computer and use it in GitHub Desktop.
META.info parser not worky
#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