Permalink
Browse files

Revert "simplify action methods"

This reverts commit 43a90e3.

It broke everything, and testing didn't catch it because the modules installed
in ~/.perl6/lib/ where preferred. Ouch.
  • Loading branch information...
1 parent 43a90e3 commit 8b0cab6d6cfbe013d23722fab8bb170e91efc304 @moritz committed Nov 1, 2009
Showing with 25 additions and 4 deletions.
  1. +25 −4 lib/JSON/Tiny/Actions.pm
View
@@ -4,19 +4,40 @@ method TOP($/, $what) {
make $/{$what}.ast;
};
method object($/) {
- make %($<pairlist>.ast)
+ make $<pairlist>.ast ?? hash ( $<pairlist>.ast ) !! {};
}
method pairlist($/) {
- make = $<pair>».ast;
+ if $<pair> {
+ my %r;
+ for $<pair>.map(*.ast) -> $m {
+ %r{$m<key>} = $m<value>;
+ }
+ make %r;
+ }
+ else {
+ make undef;
+ }
}
method pair($/) {
- make ( $<string>.ast => $<value>.ast );
+ make {
+ key => $<string>.ast,
+ value => $<value>.ast,
+ };
}
method array($/) {
- make $<value>».ast;
+ if $<value> {
+ my @r = ();
+ for $<value>>>.ast {
+ when Hash { @r.push: \$_ }
+ default { @r.push: $_ }
+ }
+ make @r
+ } else {
+ make [];
+ }
}
method value($/, $what) {

0 comments on commit 8b0cab6

Please sign in to comment.