-
Notifications
You must be signed in to change notification settings - Fork 20
/
Actions.pm
52 lines (43 loc) · 1.12 KB
/
Actions.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class JSON::Tiny::Actions;
method TOP($/) {
make $/.values.[0].ast;
};
method object($/) {
make $<pairlist>.ast.hash;
}
method pairlist($/) {
make $<pair>>>.ast.flat;
}
method pair($/) {
make $<string>.ast => $<value>.ast;
}
method array($/) {
make [$<value>>>.ast];
}
method string($/) {
make join '', $0.list.map({ (.<str> || .<str_escape>).ast });
}
method value:sym<number>($/) { make +$/.Str }
method value:sym<string>($/) { make $<string>.ast }
method value:sym<true>($/) { make Bool::True }
method value:sym<false>($/) { make Bool::False }
method value:sym<null>($/) { make Any }
method value:sym<object>($/) { make $<object>.ast }
method value:sym<array>($/) { make $<array>.ast }
method str($/) { make ~$/ }
method str_escape($/) {
if $<xdigit> {
make chr(:16($<xdigit>.join));
} else {
my %h = '\\' => "\\",
'/' => "/",
'b' => "\b",
'n' => "\n",
't' => "\t",
'f' => "\f",
'r' => "\r",
'"' => "\"";
make %h{~$/};
}
}
# vim: ft=perl6