zuzu-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +5 -0
- package/README.md +113 -0
- package/bin/zuzu +17 -0
- package/bin/zuzu-build-browser-bundle +57 -0
- package/bin/zuzu-generate-browser-stdlib +584 -0
- package/bin/zuzu-js +23 -0
- package/bin/zuzu-js-compile +152 -0
- package/bin/zuzu-js-electron +19 -0
- package/dist/zuzu-browser-worker.js +45574 -0
- package/dist/zuzu-browser.js +45362 -0
- package/lib/browser-bundle-entry.js +160 -0
- package/lib/browser-gui-renderer.js +387 -0
- package/lib/browser-runtime.js +167 -0
- package/lib/browser-worker-entry.js +413 -0
- package/lib/browser-ztests/runner.html +103 -0
- package/lib/browser-ztests/runner.js +369 -0
- package/lib/cli.js +350 -0
- package/lib/collections.js +367 -0
- package/lib/compiler.js +303 -0
- package/lib/electron/launcher.js +70 -0
- package/lib/electron/main.js +956 -0
- package/lib/electron/preload.js +80 -0
- package/lib/electron/renderer.html +122 -0
- package/lib/electron/renderer.js +24 -0
- package/lib/execution-metadata.js +18 -0
- package/lib/gui/dom-renderer.js +778 -0
- package/lib/host/browser-host.js +278 -0
- package/lib/host/capabilities.js +47 -0
- package/lib/host/electron-host.js +15 -0
- package/lib/host/node-host.js +74 -0
- package/lib/paths.js +150 -0
- package/lib/runtime-entrypoints.js +60 -0
- package/lib/runtime-helpers.js +886 -0
- package/lib/runtime.js +3529 -0
- package/lib/tap.js +37 -0
- package/lib/transpiler-new/ast.js +23 -0
- package/lib/transpiler-new/codegen.js +2455 -0
- package/lib/transpiler-new/errors.js +28 -0
- package/lib/transpiler-new/index.js +26 -0
- package/lib/transpiler-new/lexer.js +834 -0
- package/lib/transpiler-new/parser.js +2332 -0
- package/lib/transpiler-new/validate-bindings.js +326 -0
- package/lib/transpiler-utils.js +95 -0
- package/lib/transpiler.js +33 -0
- package/lib/zuzu.js +53 -0
- package/modules/javascript.js +193 -0
- package/modules/std/archive.js +603 -0
- package/modules/std/clib.js +338 -0
- package/modules/std/data/csv.js +1331 -0
- package/modules/std/data/json.js +531 -0
- package/modules/std/data/xml.js +441 -0
- package/modules/std/data/yaml.js +256 -0
- package/modules/std/db-worker.js +250 -0
- package/modules/std/db.js +664 -0
- package/modules/std/digest/_hash.js +443 -0
- package/modules/std/digest/md5.js +26 -0
- package/modules/std/digest/sha.js +72 -0
- package/modules/std/eval.js +10 -0
- package/modules/std/gui/objects.js +1519 -0
- package/modules/std/internals.js +571 -0
- package/modules/std/io/socks-worker.js +318 -0
- package/modules/std/io/socks.js +186 -0
- package/modules/std/io.js +475 -0
- package/modules/std/marshal/cbor.js +463 -0
- package/modules/std/marshal/graph.js +1624 -0
- package/modules/std/marshal.js +87 -0
- package/modules/std/math/bignum.js +91 -0
- package/modules/std/math.js +79 -0
- package/modules/std/net/dns.js +306 -0
- package/modules/std/net/http.js +820 -0
- package/modules/std/net/smtp.js +943 -0
- package/modules/std/net/url.js +109 -0
- package/modules/std/proc.js +602 -0
- package/modules/std/secure.js +3724 -0
- package/modules/std/string/base64.js +138 -0
- package/modules/std/string.js +299 -0
- package/modules/std/task.js +914 -0
- package/modules/std/time.js +579 -0
- package/modules/std/tui.js +188 -0
- package/modules/std/worker-thread.js +246 -0
- package/modules/std/worker.js +790 -0
- package/package.json +67 -0
- package/stdlib/modules/javascript.zzm +99 -0
- package/stdlib/modules/perl.zzm +105 -0
- package/stdlib/modules/std/archive.zzm +132 -0
- package/stdlib/modules/std/cache/lru.zzm +174 -0
- package/stdlib/modules/std/clib.zzm +112 -0
- package/stdlib/modules/std/colour.zzm +220 -0
- package/stdlib/modules/std/config.zzm +818 -0
- package/stdlib/modules/std/data/cbor.zzm +497 -0
- package/stdlib/modules/std/data/csv.zzm +285 -0
- package/stdlib/modules/std/data/ini.zzm +472 -0
- package/stdlib/modules/std/data/json/schema/core.zzm +573 -0
- package/stdlib/modules/std/data/json/schema/format.zzm +581 -0
- package/stdlib/modules/std/data/json/schema/model.zzm +255 -0
- package/stdlib/modules/std/data/json/schema/output.zzm +272 -0
- package/stdlib/modules/std/data/json/schema/relative_pointer.zzm +299 -0
- package/stdlib/modules/std/data/json/schema/validation.zzm +1503 -0
- package/stdlib/modules/std/data/json/schema.zzm +306 -0
- package/stdlib/modules/std/data/json.zzm +102 -0
- package/stdlib/modules/std/data/kdl/json.zzm +460 -0
- package/stdlib/modules/std/data/kdl/xml.zzm +387 -0
- package/stdlib/modules/std/data/kdl.zzm +1631 -0
- package/stdlib/modules/std/data/toml.zzm +756 -0
- package/stdlib/modules/std/data/toon.zzm +1017 -0
- package/stdlib/modules/std/data/xml/escape.zzm +156 -0
- package/stdlib/modules/std/data/xml.zzm +276 -0
- package/stdlib/modules/std/data/yaml.zzm +94 -0
- package/stdlib/modules/std/db.zzm +173 -0
- package/stdlib/modules/std/defer.zzm +75 -0
- package/stdlib/modules/std/digest/crc32.zzm +196 -0
- package/stdlib/modules/std/digest/md5.zzm +54 -0
- package/stdlib/modules/std/digest/sha.zzm +83 -0
- package/stdlib/modules/std/dump.zzm +317 -0
- package/stdlib/modules/std/eval.zzm +63 -0
- package/stdlib/modules/std/getopt.zzm +432 -0
- package/stdlib/modules/std/gui/dialogue.zzm +592 -0
- package/stdlib/modules/std/gui/objects.zzm +123 -0
- package/stdlib/modules/std/gui.zzm +1914 -0
- package/stdlib/modules/std/internals.zzm +139 -0
- package/stdlib/modules/std/io/socks.zzm +139 -0
- package/stdlib/modules/std/io.zzm +157 -0
- package/stdlib/modules/std/lingua/en.zzm +347 -0
- package/stdlib/modules/std/log.zzm +169 -0
- package/stdlib/modules/std/mail.zzm +2726 -0
- package/stdlib/modules/std/marshal.zzm +138 -0
- package/stdlib/modules/std/math/bignum.zzm +98 -0
- package/stdlib/modules/std/math/range.zzm +116 -0
- package/stdlib/modules/std/math/roman.zzm +156 -0
- package/stdlib/modules/std/math.zzm +141 -0
- package/stdlib/modules/std/net/dns.zzm +93 -0
- package/stdlib/modules/std/net/http.zzm +278 -0
- package/stdlib/modules/std/net/smtp.zzm +257 -0
- package/stdlib/modules/std/net/url.zzm +69 -0
- package/stdlib/modules/std/path/jsonpointer.zzm +526 -0
- package/stdlib/modules/std/path/kdl.zzm +1003 -0
- package/stdlib/modules/std/path/simple.zzm +520 -0
- package/stdlib/modules/std/path/z/context.zzm +147 -0
- package/stdlib/modules/std/path/z/evaluate.zzm +549 -0
- package/stdlib/modules/std/path/z/functions.zzm +874 -0
- package/stdlib/modules/std/path/z/lexer.zzm +490 -0
- package/stdlib/modules/std/path/z/node.zzm +1455 -0
- package/stdlib/modules/std/path/z/operators.zzm +445 -0
- package/stdlib/modules/std/path/z/parser.zzm +359 -0
- package/stdlib/modules/std/path/z.zzm +403 -0
- package/stdlib/modules/std/path/zz/functions.zzm +828 -0
- package/stdlib/modules/std/path/zz/operators.zzm +1036 -0
- package/stdlib/modules/std/path/zz.zzm +100 -0
- package/stdlib/modules/std/proc.zzm +155 -0
- package/stdlib/modules/std/result.zzm +149 -0
- package/stdlib/modules/std/secure.zzm +606 -0
- package/stdlib/modules/std/string/base64.zzm +66 -0
- package/stdlib/modules/std/string/quoted_printable.zzm +485 -0
- package/stdlib/modules/std/string.zzm +179 -0
- package/stdlib/modules/std/task.zzm +221 -0
- package/stdlib/modules/std/template/z.zzm +531 -0
- package/stdlib/modules/std/template/zz.zzm +62 -0
- package/stdlib/modules/std/time.zzm +188 -0
- package/stdlib/modules/std/tui.zzm +89 -0
- package/stdlib/modules/std/uuid.zzm +223 -0
- package/stdlib/modules/std/web/session.zzm +388 -0
- package/stdlib/modules/std/web/static.zzm +329 -0
- package/stdlib/modules/std/web.zzm +1942 -0
- package/stdlib/modules/std/worker.zzm +202 -0
- package/stdlib/modules/std/zuzuzoo.zzm +3960 -0
- package/stdlib/modules/test/more.zzm +528 -0
- package/stdlib/modules/test/parser.zzm +209 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
=encoding utf8
|
|
2
|
+
|
|
3
|
+
=head1 NAME
|
|
4
|
+
|
|
5
|
+
std/data/json/schema/relative_pointer - Relative JSON Pointer parser.
|
|
6
|
+
|
|
7
|
+
=head1 SYNOPSIS
|
|
8
|
+
|
|
9
|
+
from std/data/json/schema/relative_pointer import RelativeJSONPointer;
|
|
10
|
+
|
|
11
|
+
let doc := {
|
|
12
|
+
people: [
|
|
13
|
+
{ name: "Ada" },
|
|
14
|
+
{ name: "Grace" },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
let pointer := new RelativeJSONPointer( path: "1/name" );
|
|
19
|
+
say( pointer.first( doc, "/people/0/age", "(missing)" ) );
|
|
20
|
+
|
|
21
|
+
=head1 IMPLEMENTATION SUPPORT
|
|
22
|
+
|
|
23
|
+
This Pure Zuzu module is supported by all implementations of ZuzuScript.
|
|
24
|
+
|
|
25
|
+
=head1 DESCRIPTION
|
|
26
|
+
|
|
27
|
+
Relative JSON Pointer describes a target by starting from a context location,
|
|
28
|
+
climbing zero or more levels, optionally shifting an array index, and then
|
|
29
|
+
optionally applying a normal JSON Pointer suffix. JSON Schema uses the
|
|
30
|
+
syntax for the C<relative-json-pointer> format.
|
|
31
|
+
|
|
32
|
+
This module evaluates relative pointers against a root document and a
|
|
33
|
+
context pointer. The context pointer must itself be a JSON Pointer string.
|
|
34
|
+
|
|
35
|
+
=head1 EXPORTS
|
|
36
|
+
|
|
37
|
+
=head2 Classes
|
|
38
|
+
|
|
39
|
+
=over
|
|
40
|
+
|
|
41
|
+
=item C<RelativeJSONPointer>
|
|
42
|
+
|
|
43
|
+
Construct with C<< new RelativeJSONPointer( path: "0/foo" ) >>. Invalid
|
|
44
|
+
syntax throws during construction.
|
|
45
|
+
|
|
46
|
+
Methods:
|
|
47
|
+
|
|
48
|
+
=over
|
|
49
|
+
|
|
50
|
+
=item C<expression()>
|
|
51
|
+
|
|
52
|
+
Returns the original pointer expression.
|
|
53
|
+
|
|
54
|
+
=item C<up()>
|
|
55
|
+
|
|
56
|
+
Returns the number of levels the pointer climbs from the context location.
|
|
57
|
+
|
|
58
|
+
=item C<index_change()>
|
|
59
|
+
|
|
60
|
+
Returns the array-index offset, or C<null> when none was supplied.
|
|
61
|
+
|
|
62
|
+
=item C<pointer()>
|
|
63
|
+
|
|
64
|
+
Returns the JSON Pointer suffix, or C<null> for a C<#> key request.
|
|
65
|
+
|
|
66
|
+
=item C<key_request()>
|
|
67
|
+
|
|
68
|
+
Returns true for C<#> pointers that request the key or array index at the
|
|
69
|
+
target location.
|
|
70
|
+
|
|
71
|
+
=item C<< target_pointer( context_pointer := "" ) >>
|
|
72
|
+
|
|
73
|
+
Returns the absolute JSON Pointer reached by climbing and applying any index
|
|
74
|
+
offset, before the suffix is applied.
|
|
75
|
+
|
|
76
|
+
=item C<< evaluate( root, context_pointer := "" ) >>
|
|
77
|
+
|
|
78
|
+
Evaluates the relative pointer. Normal pointers return the same array of
|
|
79
|
+
matches as I<std/path/jsonpointer>'s C<query>. C<#> key requests return the
|
|
80
|
+
key or index string directly, or C<null> when the request names the document
|
|
81
|
+
root.
|
|
82
|
+
|
|
83
|
+
=item C<< get( root, context_pointer := "" ) >>
|
|
84
|
+
|
|
85
|
+
Alias for C<evaluate>.
|
|
86
|
+
|
|
87
|
+
=item C<< first( root, context_pointer := "", fallback := null ) >>
|
|
88
|
+
|
|
89
|
+
Returns the first matched value, or C<fallback> when no value is found. For
|
|
90
|
+
C<#> key requests, C<fallback> is returned only when the key request returns
|
|
91
|
+
C<null>.
|
|
92
|
+
|
|
93
|
+
=item C<< exists( root, context_pointer := "" ) >>
|
|
94
|
+
|
|
95
|
+
Returns true when evaluation finds a value. For C<#> key requests, the
|
|
96
|
+
document root key is treated as absent.
|
|
97
|
+
|
|
98
|
+
=back
|
|
99
|
+
|
|
100
|
+
=back
|
|
101
|
+
|
|
102
|
+
=head2 Functions
|
|
103
|
+
|
|
104
|
+
=over
|
|
105
|
+
|
|
106
|
+
=item C<< valid_relative_json_pointer( text ) >>
|
|
107
|
+
|
|
108
|
+
Returns true when C<text> parses as a Relative JSON Pointer.
|
|
109
|
+
|
|
110
|
+
=back
|
|
111
|
+
|
|
112
|
+
=head1 COPYRIGHT AND LICENCE
|
|
113
|
+
|
|
114
|
+
B<< std/data/json/schema/relative_pointer >> is copyright Toby Inkster.
|
|
115
|
+
|
|
116
|
+
It is free software; you may redistribute it and/or modify it under
|
|
117
|
+
the terms of either the Artistic License 1.0 or the GNU General Public
|
|
118
|
+
License version 2.
|
|
119
|
+
|
|
120
|
+
=cut
|
|
121
|
+
|
|
122
|
+
from std/path/jsonpointer import JSONPointer;
|
|
123
|
+
from std/data/json/schema/model import jschema_pointer_join;
|
|
124
|
+
from std/string import replace, split, substr;
|
|
125
|
+
|
|
126
|
+
function _rjp_decode_token ( String raw ) {
|
|
127
|
+
return raw
|
|
128
|
+
▷ replace( ^^, "~1", "/", "g" )
|
|
129
|
+
▷ replace( ^^, "~0", "~", "g" );
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function _rjp_tokens ( String pointer ) {
|
|
133
|
+
if ( pointer ne "" and substr( pointer, 0, 1 ) ne "/" ) {
|
|
134
|
+
die "Relative JSON Pointer context path must be a JSON Pointer";
|
|
135
|
+
}
|
|
136
|
+
if ( pointer eq "" ) {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let raw := split( substr( pointer, 1 ), "/" );
|
|
141
|
+
let out := [];
|
|
142
|
+
for ( let token in raw ) {
|
|
143
|
+
out.push( _rjp_decode_token(token) );
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function _rjp_pointer_from_tokens ( Array tokens ) {
|
|
149
|
+
let out := "";
|
|
150
|
+
for ( let token in tokens ) {
|
|
151
|
+
out := jschema_pointer_join( out, token );
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
class RelativeJSONPointer {
|
|
157
|
+
let String path;
|
|
158
|
+
let Number up := 0;
|
|
159
|
+
let index_change := null;
|
|
160
|
+
let pointer := null;
|
|
161
|
+
let Boolean key_request := false;
|
|
162
|
+
|
|
163
|
+
method __build__ () {
|
|
164
|
+
let i := 0;
|
|
165
|
+
let n := length path;
|
|
166
|
+
if ( n == 0 ) {
|
|
167
|
+
die "Relative JSON Pointer parse error: empty pointer";
|
|
168
|
+
}
|
|
169
|
+
if ( not( substr( path, 0, 1 ) ~ /[0-9]/ ) ) {
|
|
170
|
+
die "Relative JSON Pointer parse error: missing non-negative integer";
|
|
171
|
+
}
|
|
172
|
+
if ( n > 1 and substr( path, 0, 1 ) eq "0" and substr( path, 1, 1 ) ~ /[0-9]/ ) {
|
|
173
|
+
die "Relative JSON Pointer parse error: leading zero";
|
|
174
|
+
}
|
|
175
|
+
while ( i < n and substr( path, i, 1 ) ~ /[0-9]/ ) {
|
|
176
|
+
i++;
|
|
177
|
+
}
|
|
178
|
+
up := int( substr( path, 0, i ) );
|
|
179
|
+
|
|
180
|
+
if ( i < n and substr( path, i, 1 ) ~ /[+-]/ ) {
|
|
181
|
+
let sign := substr( path, i, 1 );
|
|
182
|
+
i++;
|
|
183
|
+
let start := i;
|
|
184
|
+
if ( i >= n or not( substr( path, i, 1 ) ~ /[0-9]/ ) ) {
|
|
185
|
+
die "Relative JSON Pointer parse error: missing index offset";
|
|
186
|
+
}
|
|
187
|
+
while ( i < n and substr( path, i, 1 ) ~ /[0-9]/ ) {
|
|
188
|
+
i++;
|
|
189
|
+
}
|
|
190
|
+
let offset := int( substr( path, start, i - start ) );
|
|
191
|
+
index_change := sign eq "-" ? 0 - offset : offset;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if ( i == n ) {
|
|
195
|
+
pointer := "";
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if ( substr( path, i, 1 ) eq "#" ) {
|
|
200
|
+
if ( i + 1 ≢ n ) {
|
|
201
|
+
die "Relative JSON Pointer parse error: trailing text after '#'";
|
|
202
|
+
}
|
|
203
|
+
key_request := true;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let rest := substr( path, i );
|
|
208
|
+
new JSONPointer( path: rest );
|
|
209
|
+
pointer := rest;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
method expression () { return path; }
|
|
213
|
+
method pointer () { return pointer; }
|
|
214
|
+
method up () { return up; }
|
|
215
|
+
method index_change () { return index_change; }
|
|
216
|
+
method key_request () { return key_request; }
|
|
217
|
+
|
|
218
|
+
method target_pointer ( String context_pointer := "" ) {
|
|
219
|
+
let tokens := _rjp_tokens(context_pointer);
|
|
220
|
+
if ( up > tokens.length() ) {
|
|
221
|
+
die "Relative JSON Pointer climbs above the document root";
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let target_len := tokens.length() - up;
|
|
225
|
+
let target := [];
|
|
226
|
+
let i := 0;
|
|
227
|
+
while ( i < target_len ) {
|
|
228
|
+
target.push(tokens[i]);
|
|
229
|
+
i++;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if ( index_change ≢ null ) {
|
|
233
|
+
if (
|
|
234
|
+
target.length() == 0
|
|
235
|
+
or not( target[target.length() - 1] ~ /^(0|[1-9][0-9]*)$/ )
|
|
236
|
+
) {
|
|
237
|
+
die "Relative JSON Pointer index manipulation needs an array index";
|
|
238
|
+
}
|
|
239
|
+
let idx := int( target[target.length() - 1] ) + index_change;
|
|
240
|
+
if ( idx < 0 ) {
|
|
241
|
+
die "Relative JSON Pointer index manipulation produced negative index";
|
|
242
|
+
}
|
|
243
|
+
target[target.length() - 1] := "" _ idx;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return _rjp_pointer_from_tokens(target);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
method evaluate ( root, String context_pointer := "" ) {
|
|
250
|
+
if ( key_request ) {
|
|
251
|
+
let tokens := _rjp_tokens(context_pointer);
|
|
252
|
+
if ( up > tokens.length() ) {
|
|
253
|
+
die "Relative JSON Pointer climbs above the document root";
|
|
254
|
+
}
|
|
255
|
+
if ( tokens.length() == up ) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
return tokens[ tokens.length() - up - 1 ];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
let base := self.target_pointer(context_pointer);
|
|
262
|
+
let full := base;
|
|
263
|
+
if ( pointer ≢ null and pointer ne "" ) {
|
|
264
|
+
let suffix := pointer;
|
|
265
|
+
full := base eq "" ? suffix : base _ suffix;
|
|
266
|
+
}
|
|
267
|
+
return new JSONPointer( path: full ).query(root);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
method get ( root, String context_pointer := "" ) {
|
|
271
|
+
return self.evaluate( root, context_pointer );
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
method first ( root, String context_pointer := "", fallback := null ) {
|
|
275
|
+
if ( key_request ) {
|
|
276
|
+
let key := self.evaluate( root, context_pointer );
|
|
277
|
+
return key ≡ null ? fallback : key;
|
|
278
|
+
}
|
|
279
|
+
let out := self.evaluate( root, context_pointer );
|
|
280
|
+
return out.length() == 0 ? fallback : out[0];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
method exists ( root, String context_pointer := "" ) {
|
|
284
|
+
if ( key_request ) {
|
|
285
|
+
return self.evaluate( root, context_pointer ) ≢ null;
|
|
286
|
+
}
|
|
287
|
+
return self.evaluate( root, context_pointer ).length() > 0;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function valid_relative_json_pointer ( String text ) {
|
|
292
|
+
try {
|
|
293
|
+
new RelativeJSONPointer( path: text );
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
}
|