unit class JSON::Tiny::Actions; method TOP($/) { make $.made; }; method object($/) { make $.made.hash.item; } method pairlist($/) { make $>>.made.flat; } method pair($/) { make $.made => $.made; } method array($/) { make $.made.item; } method arraylist($/) { make [$.map(*.made)]; } method string($/) { my $str = +@$ == 1 ?? $[0].made !! $>>.made.join; # see https://github.com/moritz/json/issues/25 # when a combining character comes after an opening quote, # it doesn't become part of the quoted string, because # it's stuffed into the same grapheme as the quote. # so we need to extract those combining character(s) # from the match of the opening quote, and stuff it into the string. if $0.Str ne '"' { my @chars := $0.Str.NFC; $str = @chars[1..*].chrs ~ $str; } make $str } method value:sym($/) { make +$/.Str } method value:sym($/) { make $.made } method value:sym($/) { make Bool::True } method value:sym($/) { make Bool::False } method value:sym($/) { make Any } method value:sym($/) { make $.made } method value:sym($/) { make $.made } method str($/) { make ~$/ } my %h = '\\' => "\\", '/' => "/", 'b' => "\b", 'n' => "\n", 't' => "\t", 'f' => "\f", 'r' => "\r", '"' => "\""; method str_escape($/) { if $ { make utf16.new( $.map({:16(~$_)}) ).decode(); } else { make %h{~$/}; } } # vim: ft=perl6