|
|
1.5 misha 1: @main[]
1.1 misha 2: $a[^hash::create[]]
3: $b[$.a[$a]]
4: $a.b[$b]
5:
6: $h[
7: $.hash[
1.2 moko 8: $.void[$void]
1.1 misha 9: $.bool-true(true)
10: $.bool-false(false)
11: $.int(1)
12: $.double(1/2)
13: $.[a/b]["1"]
14: $.string[value with "quotes"/other things]
15: $.string-ru[русские буквы]
16: $.hash[
17: $.e[ee]
18: ]
19:
20: $._options[
21: $.0[]
22: $.1[$.indent(true)]
23: ]
24: ]
25:
26: $.date[
1.7 moko 27: $.value[^date::create(2026;08;18;06;09;00)]
1.1 misha 28:
29: $._options[
30: $.0[$.date[unix-timestamp]]
31: $.1[$.date[gmt-string]]
1.6 moko 32: $.2[$.date[iso-string]]
33: $.3[$.date[sql-string]]
34: $.4[$.date[$handler]]
35: $.5[
1.5 misha 36: $.date[unsupported]
37: $.exception(true)
38: ]
1.1 misha 39: ]
40: ]
41:
42: $.table[
43: $.table_nameless_empty[^table::create[nameless]{}]
44: $.table_nameless_1[^table::create[nameless]{v1 v2 v3}]
45: $.table_nameless_2[^table::create[nameless]{v1 v2 v3^#0Av4 v5 v6}]
46: $.table_named_empty[^table::create{c1 c2 c3}]
47: $.table_named_1[^table::create{c1 c2 c3^#0Av1 v2 v3}]
48: $.table_named_2[^table::create{c1 c2 c3^#0Av1 v2 v3^#0Av4 v5 v6}]
49: $.table_named_3[^table::create{c1 c2 c3^#0Av1 v2 v3^#0Av4 v5 v6}]
50:
51: $._options[
52: $.0[$.table[object]]
53: $.1[$.table[object] $.indent(true)]
54: $.2[$.table[array]]
55: $.3[$.table[array] $.indent(true)]
1.3 moko 56: $.4[$.table[compact]]
57: $.5[$.table[compact] $.indent(true)]
1.5 misha 58: $.6[
59: $.table[unsupported]
60: $.exception(true)
61: ]
1.1 misha 62: ]
63: ]
64:
65: $.my[
66: $.object[^my::create[]]
67:
68: $._options[
69: $.0[$.my[$handler]]
1.5 misha 70: $.1[
71: $.my[$unknown]
72: $.exception(true)
73: ]
74: $.2[
75: $.my[$main]
76: $.exception(true)
77: ]
1.1 misha 78: ]
79: ]
80:
81: $.file[
82: $.text[^file::create[text;zigi;file-content]]
83: $.binary[^file::load[binary;./256.txt]]
84: $.stated[^file::stat[./256.txt]]
85:
86: $._options[
87: $.0[$.file[text]]
88: $.1[$.file[base64] $.indent(true)]
89: $.2[$.file[$handler]]
1.5 misha 90: $.3[$.file[stat]]
91: $.4[
92: $.file[unsupported]
93: $.exception(true)
94: ]
1.1 misha 95: ]
96: ]
97:
98: $.image[
99: $.value[^image::create(100;100;0)]
100: $._options[
101: $.1[$.image[$handler]]
1.8 moko 102: $.2[$.exception(false)]
1.1 misha 103: ]
104: ]
105:
106: $.hash_with_infinite_recursion[
107: $.value[$a]
108:
109: $._options[
110: $.0[$.exception(true)]
111: ]
112: ]
113:
1.4 misha 114: $.xdoc[
115: $.value[^xdoc::create{<?xml version="1.0"?><r><t z="1"/></r>}]
116: $._options[
117: $.0[]
118: $.1[$.xdoc[
119: $.omit-xml-declaration[yes]
120: $.indent[yes]
121: ]]
122: ]
123: ]
1.1 misha 124: ]
125:
126: ^h.table.table_named_3.append{v7 v8 v9 v0}
1.3 moko 127: ^h.table.table_named_3.append{vA"}
128: ^h.table.table_named_3.append{vB\}
1.1 misha 129:
130: $s[^h.foreach[k;v]{
131: <h3>$k</h3>
132: ^if($v is "hash" && def $v._options){
133: $hOptions[$v._options]
134: $hValue[^hash::create[$v]]
135: ^hValue.delete[_options]
136: ^hOptions.foreach[;hOpt]{^2string[$hValue;$hOpt]}[, ]
137: }{
138: ^2string[$v]
139: }
140: }]
141:
142: ^s.match["([acm]date)":"[^^"]+"][g]{"$match.1":"-value-"}
143:
144:
145: @2string[value;options]
146: $options[^hash::create[$options]]
147: $bShouldBeException($options.exception)
148: ^options.delete[exception]
149: ^try{
150: $result[^json:string[$value;$options]^if($bShouldBeException){. FAILED. EXCEPTION SHOULD BE HERE}]
151: }{
152: $exception.handled(true)
1.9 ! moko 153: $result["exception":"$exception.source, ^taint[as-is;$exception.comment]^if($bShouldBeException){. That's OK}"]
1.1 misha 154: }
155:
156:
1.3 moko 157: @handler[k;v;p][kk;vv]
1.1 misha 158: $result[^switch[$v.CLASS_NAME]{
159: ^case[date]{"new Date(^v.unix-timestamp[])"}
160: ^case[file]{{"file":{"name":"$v.name", "text":"$v.text", "params":"-params-"}}}
161: ^case[image]{"image []"}
1.3 moko 162: ^case[DEFAULT]{"$v.CLASS_NAME at key $k, with ^p._count[] option"}
1.1 misha 163: }]
164:
165:
166:
167: @CLASS
168: my
169:
170: @create[]
171: $v[ac/dc]