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.
Files changed (167) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +113 -0
  3. package/bin/zuzu +17 -0
  4. package/bin/zuzu-build-browser-bundle +57 -0
  5. package/bin/zuzu-generate-browser-stdlib +584 -0
  6. package/bin/zuzu-js +23 -0
  7. package/bin/zuzu-js-compile +152 -0
  8. package/bin/zuzu-js-electron +19 -0
  9. package/dist/zuzu-browser-worker.js +45574 -0
  10. package/dist/zuzu-browser.js +45362 -0
  11. package/lib/browser-bundle-entry.js +160 -0
  12. package/lib/browser-gui-renderer.js +387 -0
  13. package/lib/browser-runtime.js +167 -0
  14. package/lib/browser-worker-entry.js +413 -0
  15. package/lib/browser-ztests/runner.html +103 -0
  16. package/lib/browser-ztests/runner.js +369 -0
  17. package/lib/cli.js +350 -0
  18. package/lib/collections.js +367 -0
  19. package/lib/compiler.js +303 -0
  20. package/lib/electron/launcher.js +70 -0
  21. package/lib/electron/main.js +956 -0
  22. package/lib/electron/preload.js +80 -0
  23. package/lib/electron/renderer.html +122 -0
  24. package/lib/electron/renderer.js +24 -0
  25. package/lib/execution-metadata.js +18 -0
  26. package/lib/gui/dom-renderer.js +778 -0
  27. package/lib/host/browser-host.js +278 -0
  28. package/lib/host/capabilities.js +47 -0
  29. package/lib/host/electron-host.js +15 -0
  30. package/lib/host/node-host.js +74 -0
  31. package/lib/paths.js +150 -0
  32. package/lib/runtime-entrypoints.js +60 -0
  33. package/lib/runtime-helpers.js +886 -0
  34. package/lib/runtime.js +3529 -0
  35. package/lib/tap.js +37 -0
  36. package/lib/transpiler-new/ast.js +23 -0
  37. package/lib/transpiler-new/codegen.js +2455 -0
  38. package/lib/transpiler-new/errors.js +28 -0
  39. package/lib/transpiler-new/index.js +26 -0
  40. package/lib/transpiler-new/lexer.js +834 -0
  41. package/lib/transpiler-new/parser.js +2332 -0
  42. package/lib/transpiler-new/validate-bindings.js +326 -0
  43. package/lib/transpiler-utils.js +95 -0
  44. package/lib/transpiler.js +33 -0
  45. package/lib/zuzu.js +53 -0
  46. package/modules/javascript.js +193 -0
  47. package/modules/std/archive.js +603 -0
  48. package/modules/std/clib.js +338 -0
  49. package/modules/std/data/csv.js +1331 -0
  50. package/modules/std/data/json.js +531 -0
  51. package/modules/std/data/xml.js +441 -0
  52. package/modules/std/data/yaml.js +256 -0
  53. package/modules/std/db-worker.js +250 -0
  54. package/modules/std/db.js +664 -0
  55. package/modules/std/digest/_hash.js +443 -0
  56. package/modules/std/digest/md5.js +26 -0
  57. package/modules/std/digest/sha.js +72 -0
  58. package/modules/std/eval.js +10 -0
  59. package/modules/std/gui/objects.js +1519 -0
  60. package/modules/std/internals.js +571 -0
  61. package/modules/std/io/socks-worker.js +318 -0
  62. package/modules/std/io/socks.js +186 -0
  63. package/modules/std/io.js +475 -0
  64. package/modules/std/marshal/cbor.js +463 -0
  65. package/modules/std/marshal/graph.js +1624 -0
  66. package/modules/std/marshal.js +87 -0
  67. package/modules/std/math/bignum.js +91 -0
  68. package/modules/std/math.js +79 -0
  69. package/modules/std/net/dns.js +306 -0
  70. package/modules/std/net/http.js +820 -0
  71. package/modules/std/net/smtp.js +943 -0
  72. package/modules/std/net/url.js +109 -0
  73. package/modules/std/proc.js +602 -0
  74. package/modules/std/secure.js +3724 -0
  75. package/modules/std/string/base64.js +138 -0
  76. package/modules/std/string.js +299 -0
  77. package/modules/std/task.js +914 -0
  78. package/modules/std/time.js +579 -0
  79. package/modules/std/tui.js +188 -0
  80. package/modules/std/worker-thread.js +246 -0
  81. package/modules/std/worker.js +790 -0
  82. package/package.json +67 -0
  83. package/stdlib/modules/javascript.zzm +99 -0
  84. package/stdlib/modules/perl.zzm +105 -0
  85. package/stdlib/modules/std/archive.zzm +132 -0
  86. package/stdlib/modules/std/cache/lru.zzm +174 -0
  87. package/stdlib/modules/std/clib.zzm +112 -0
  88. package/stdlib/modules/std/colour.zzm +220 -0
  89. package/stdlib/modules/std/config.zzm +818 -0
  90. package/stdlib/modules/std/data/cbor.zzm +497 -0
  91. package/stdlib/modules/std/data/csv.zzm +285 -0
  92. package/stdlib/modules/std/data/ini.zzm +472 -0
  93. package/stdlib/modules/std/data/json/schema/core.zzm +573 -0
  94. package/stdlib/modules/std/data/json/schema/format.zzm +581 -0
  95. package/stdlib/modules/std/data/json/schema/model.zzm +255 -0
  96. package/stdlib/modules/std/data/json/schema/output.zzm +272 -0
  97. package/stdlib/modules/std/data/json/schema/relative_pointer.zzm +299 -0
  98. package/stdlib/modules/std/data/json/schema/validation.zzm +1503 -0
  99. package/stdlib/modules/std/data/json/schema.zzm +306 -0
  100. package/stdlib/modules/std/data/json.zzm +102 -0
  101. package/stdlib/modules/std/data/kdl/json.zzm +460 -0
  102. package/stdlib/modules/std/data/kdl/xml.zzm +387 -0
  103. package/stdlib/modules/std/data/kdl.zzm +1631 -0
  104. package/stdlib/modules/std/data/toml.zzm +756 -0
  105. package/stdlib/modules/std/data/toon.zzm +1017 -0
  106. package/stdlib/modules/std/data/xml/escape.zzm +156 -0
  107. package/stdlib/modules/std/data/xml.zzm +276 -0
  108. package/stdlib/modules/std/data/yaml.zzm +94 -0
  109. package/stdlib/modules/std/db.zzm +173 -0
  110. package/stdlib/modules/std/defer.zzm +75 -0
  111. package/stdlib/modules/std/digest/crc32.zzm +196 -0
  112. package/stdlib/modules/std/digest/md5.zzm +54 -0
  113. package/stdlib/modules/std/digest/sha.zzm +83 -0
  114. package/stdlib/modules/std/dump.zzm +317 -0
  115. package/stdlib/modules/std/eval.zzm +63 -0
  116. package/stdlib/modules/std/getopt.zzm +432 -0
  117. package/stdlib/modules/std/gui/dialogue.zzm +592 -0
  118. package/stdlib/modules/std/gui/objects.zzm +123 -0
  119. package/stdlib/modules/std/gui.zzm +1914 -0
  120. package/stdlib/modules/std/internals.zzm +139 -0
  121. package/stdlib/modules/std/io/socks.zzm +139 -0
  122. package/stdlib/modules/std/io.zzm +157 -0
  123. package/stdlib/modules/std/lingua/en.zzm +347 -0
  124. package/stdlib/modules/std/log.zzm +169 -0
  125. package/stdlib/modules/std/mail.zzm +2726 -0
  126. package/stdlib/modules/std/marshal.zzm +138 -0
  127. package/stdlib/modules/std/math/bignum.zzm +98 -0
  128. package/stdlib/modules/std/math/range.zzm +116 -0
  129. package/stdlib/modules/std/math/roman.zzm +156 -0
  130. package/stdlib/modules/std/math.zzm +141 -0
  131. package/stdlib/modules/std/net/dns.zzm +93 -0
  132. package/stdlib/modules/std/net/http.zzm +278 -0
  133. package/stdlib/modules/std/net/smtp.zzm +257 -0
  134. package/stdlib/modules/std/net/url.zzm +69 -0
  135. package/stdlib/modules/std/path/jsonpointer.zzm +526 -0
  136. package/stdlib/modules/std/path/kdl.zzm +1003 -0
  137. package/stdlib/modules/std/path/simple.zzm +520 -0
  138. package/stdlib/modules/std/path/z/context.zzm +147 -0
  139. package/stdlib/modules/std/path/z/evaluate.zzm +549 -0
  140. package/stdlib/modules/std/path/z/functions.zzm +874 -0
  141. package/stdlib/modules/std/path/z/lexer.zzm +490 -0
  142. package/stdlib/modules/std/path/z/node.zzm +1455 -0
  143. package/stdlib/modules/std/path/z/operators.zzm +445 -0
  144. package/stdlib/modules/std/path/z/parser.zzm +359 -0
  145. package/stdlib/modules/std/path/z.zzm +403 -0
  146. package/stdlib/modules/std/path/zz/functions.zzm +828 -0
  147. package/stdlib/modules/std/path/zz/operators.zzm +1036 -0
  148. package/stdlib/modules/std/path/zz.zzm +100 -0
  149. package/stdlib/modules/std/proc.zzm +155 -0
  150. package/stdlib/modules/std/result.zzm +149 -0
  151. package/stdlib/modules/std/secure.zzm +606 -0
  152. package/stdlib/modules/std/string/base64.zzm +66 -0
  153. package/stdlib/modules/std/string/quoted_printable.zzm +485 -0
  154. package/stdlib/modules/std/string.zzm +179 -0
  155. package/stdlib/modules/std/task.zzm +221 -0
  156. package/stdlib/modules/std/template/z.zzm +531 -0
  157. package/stdlib/modules/std/template/zz.zzm +62 -0
  158. package/stdlib/modules/std/time.zzm +188 -0
  159. package/stdlib/modules/std/tui.zzm +89 -0
  160. package/stdlib/modules/std/uuid.zzm +223 -0
  161. package/stdlib/modules/std/web/session.zzm +388 -0
  162. package/stdlib/modules/std/web/static.zzm +329 -0
  163. package/stdlib/modules/std/web.zzm +1942 -0
  164. package/stdlib/modules/std/worker.zzm +202 -0
  165. package/stdlib/modules/std/zuzuzoo.zzm +3960 -0
  166. package/stdlib/modules/test/more.zzm +528 -0
  167. package/stdlib/modules/test/parser.zzm +209 -0
@@ -0,0 +1,100 @@
1
+ =encoding utf8
2
+
3
+ =head1 NAME
4
+
5
+ std/path/zz - ZuzuScript-flavoured path selectors.
6
+
7
+ =head1 SYNOPSIS
8
+
9
+ from std/path/zz import ZZPath;
10
+
11
+ let data := { users: [ { name: "Ada" } ] };
12
+ say( ( new ZZPath( path: "/users/#0/name" ) ).first(data) );
13
+
14
+ =head1 IMPLEMENTATION SUPPORT
15
+
16
+ This module is supported by all implementations of ZuzuScript.
17
+
18
+ =head1 DESCRIPTION
19
+
20
+ This module provides the public C<ZZPath> class. It currently reuses the
21
+ ZPath traversal, parser, lexer, assignment, and reference
22
+ machinery while routing expression operators through
23
+ C<std/path/zz/operators> and expression functions through
24
+ C<std/path/zz/functions>.
25
+
26
+ =head1 EXPORTS
27
+
28
+ =head2 Classes
29
+
30
+ =over
31
+
32
+ =item C<ZZEvaluator>
33
+
34
+ Evaluator class that supplies ZZPath operators and functions.
35
+
36
+ =over
37
+
38
+ =item C<< evaluator.operator_definitions() >>
39
+
40
+ Parameters: none. Returns: C<Array>. Returns ZZPath operator
41
+ definitions.
42
+
43
+ =item C<< evaluator.function_definitions() >>
44
+
45
+ Parameters: none. Returns: C<Array>. Returns ZZPath function
46
+ definitions.
47
+
48
+ =back
49
+
50
+ =item C<< ZZPath({ path: String }) >>
51
+
52
+ Constructs a ZZPath query object. Returns: C<ZZPath>. Inherits the
53
+ public query, assignment, and reference methods from C<ZPath>.
54
+
55
+ =over
56
+
57
+ =item C<< path.get_evaluator() >>
58
+
59
+ Parameters: none. Returns: C<ZZEvaluator>. Returns the evaluator used
60
+ for this path.
61
+
62
+ =item C<< node.find(path) >>
63
+
64
+ C<ZZPath> inherits from C<ZPath>, so a C<ZZPath> object can be passed to
65
+ C<std/path/z/node> C<Node.find()>.
66
+
67
+ =back
68
+
69
+ =back
70
+
71
+ =head1 COPYRIGHT AND LICENCE
72
+
73
+ B<< std/path/zz >> is copyright Toby Inkster.
74
+
75
+ It is free software; you may redistribute it and/or modify it under
76
+ the terms of either the Artistic License 1.0 or the GNU General Public
77
+ License version 2.
78
+
79
+ =cut
80
+
81
+ from std/path/z import ZPath;
82
+ from std/path/z/evaluate import Evaluator as ZEvaluator;
83
+
84
+ class ZZEvaluator extends ZEvaluator {
85
+ method operator_definitions () {
86
+ from std/path/zz/operators import STANDARD_OPERATORS;
87
+ return STANDARD_OPERATORS;
88
+ }
89
+
90
+ method function_definitions () {
91
+ from std/path/zz/functions import STANDARD_FUNCTIONS;
92
+ return STANDARD_FUNCTIONS;
93
+ }
94
+ }
95
+
96
+ class ZZPath extends ZPath {
97
+ method get_evaluator () {
98
+ return new ZZEvaluator();
99
+ }
100
+ }
@@ -0,0 +1,155 @@
1
+ =encoding utf8
2
+
3
+ =head1 NAME
4
+
5
+ std/proc - Process execution, environment, and signals.
6
+
7
+ =head1 SYNOPSIS
8
+
9
+ from std/proc import Proc, Env, sleep;
10
+
11
+ let pid := Proc.pid();
12
+ let home := Env.get("HOME", "");
13
+
14
+ let res := Proc.run(
15
+ "perl",
16
+ [ "-e", "print qq<ok\\n>;" ]
17
+ );
18
+
19
+ let seen := 0;
20
+ Proc.onsignal( "USR1", function () {
21
+ seen++;
22
+ } );
23
+ Proc.kill( "USR1", Proc.pid() );
24
+
25
+ sleep(0.1);
26
+
27
+ =head1 IMPLEMENTATION SUPPORT
28
+
29
+ This module is supported by zuzu.pl, zuzu-rust, and zuzu-js on Node and
30
+ Electron. It is not supported by zuzu-js in the browser.
31
+
32
+ =head1 DESCRIPTION
33
+
34
+ This module provides OS process helpers, environment variable helpers,
35
+ signal send/receive primitives, process-identification helpers, and
36
+ process exit.
37
+
38
+ =head1 EXPORTS
39
+
40
+ =head2 Classes
41
+
42
+ =over
43
+
44
+ =item C<Proc>
45
+
46
+ Static methods:
47
+
48
+ =over
49
+
50
+ =item * C<pid()>
51
+
52
+ Parameters: none. Returns: C<Number>. Returns the current process id.
53
+
54
+ =item * C<< exit(code?) >>
55
+
56
+ Parameters: C<code> is an optional numeric exit status. Returns:
57
+ C<null>. Exits the current process.
58
+
59
+ =item * C<< run(command, argv?, options?) >>
60
+
61
+ Parameters: C<command> is an executable, C<argv> is an optional array of
62
+ arguments, and C<options> controls execution. Returns: C<Dict>. Runs one
63
+ process and returns its result.
64
+
65
+ Options include C<stdin>, C<capture_stdout>, C<capture_stderr>,
66
+ and C<merge_stderr>. Also supports C<env> injection, C<cwd>, and
67
+ C<timeout>.
68
+
69
+ =item * C<< run_async(command, argv?, options?) >>
70
+
71
+ Parameters: same as C<run>. Returns: C<Task>. Awaitable version of
72
+ C<run> resolving to the same result dictionary.
73
+
74
+ =item * C<< pipeline(commands, options?) >>
75
+
76
+ Parameters: C<commands> is an array of command specs and C<options>
77
+ controls execution. Returns: C<Dict>. Runs commands in sequence, piping
78
+ captured stdout from each step to the next step's stdin.
79
+
80
+ =item * C<< pipeline_async(commands, options?) >>
81
+
82
+ Parameters: same as C<pipeline>. Returns: C<Task>. Awaitable version of
83
+ C<pipeline> resolving to the same result dictionary.
84
+
85
+ =item * C<is_success(result)>
86
+
87
+ Parameters: C<result> is a process result dictionary. Returns:
88
+ C<Boolean>. Returns true when the command exited successfully.
89
+
90
+ =item * C<status_text(result)>
91
+
92
+ Parameters: C<result> is a process result dictionary. Returns:
93
+ C<String>. Formats the process status for display.
94
+
95
+ =item * C<kill(String signal, Number pid?)>
96
+
97
+ Parameters: C<signal> is a signal name and C<pid> is an optional process
98
+ id. Returns: C<null>. Sends a signal to a process.
99
+
100
+ =item * C<onsignal(String signal, Function callback)>
101
+
102
+ Parameters: C<signal> is a signal name and C<callback> is a handler.
103
+ Returns: C<null>. Registers a process signal callback.
104
+
105
+ =back
106
+
107
+ =item C<Env>
108
+
109
+ Static methods:
110
+
111
+ =over
112
+
113
+ =item * C<get(String name, Any default?)>
114
+
115
+ Parameters: C<name> is an environment variable name and C<default> is an
116
+ optional fallback. Returns: C<String> or value. Returns an environment
117
+ variable value or the fallback.
118
+
119
+ =item * C<set(String name, String value)>
120
+
121
+ Parameters: C<name> is an environment variable name and C<value> is its
122
+ new value. Returns: C<null>. Sets an environment variable.
123
+
124
+ =item * C<remove(String name)>
125
+
126
+ Parameters: C<name> is an environment variable name. Returns: C<null>.
127
+ Removes an environment variable.
128
+
129
+ =back
130
+
131
+ =back
132
+
133
+ =head2 Functions
134
+
135
+ =over
136
+
137
+ =item * C<< sleep(seconds) >>
138
+
139
+ Parameters: C<seconds> is the delay in seconds. Returns: C<null>.
140
+ Sleeps for the requested time; fractional seconds are allowed.
141
+
142
+ =item * C<< sleep_async(seconds) >>
143
+
144
+ Parameters: C<seconds> is the delay in seconds. Returns: C<Task>.
145
+ Returns an awaitable task that completes after the requested delay.
146
+
147
+ =back
148
+
149
+ =head1 COPYRIGHT AND LICENCE
150
+
151
+ B<< std/proc >> is copyright Toby Inkster.
152
+
153
+ It is free software; you may redistribute it and/or modify it under
154
+ the terms of either the Artistic License 1.0 or the GNU General Public
155
+ License version 2.
@@ -0,0 +1,149 @@
1
+ =encoding utf8
2
+
3
+ =head1 NAME
4
+
5
+ std/result - A simple Result object for explicit success and failure values.
6
+
7
+ =head1 SYNOPSIS
8
+
9
+ from std/result import Result;
10
+
11
+ let r := Result.ok(42);
12
+
13
+ if ( r.is_ok() ) {
14
+ say r.unwrap();
15
+ }
16
+
17
+ =head1 IMPLEMENTATION SUPPORT
18
+
19
+ This module is supported by all implementations of ZuzuScript.
20
+
21
+ =head1 DESCRIPTION
22
+
23
+ C<Result> is a small, subclassable object modelled on a simplified version
24
+ of Rust's C<Result> concept. It is useful when a function, task, or worker
25
+ wants to return an explicit success or failure value without throwing an
26
+ exception.
27
+
28
+ It is a normal ZuzuScript class. Workers do not require C<Result>; any value
29
+ supported by C<std/marshal> may be returned.
30
+
31
+ =head1 EXPORTS
32
+
33
+ =head2 Classes
34
+
35
+ =over
36
+
37
+ =item C<Result>
38
+
39
+ Container for either an ok value or an error value.
40
+
41
+ =over
42
+
43
+ =item C<< Result.ok(value) >>
44
+
45
+ Parameters: C<value> is any success value. Returns: C<Result>. Creates an
46
+ ok result wrapping C<value>.
47
+
48
+ =item C<< Result.err(error) >>
49
+
50
+ Parameters: C<error> is any error value. Returns: C<Result>. Creates an
51
+ error result wrapping C<error>.
52
+
53
+ =item C<< result.is_ok() >>
54
+
55
+ Parameters: none. Returns: C<Boolean>. Returns true when the result is an
56
+ ok value.
57
+
58
+ =item C<< result.is_err() >>
59
+
60
+ Parameters: none. Returns: C<Boolean>. Returns true when the result is an
61
+ error value.
62
+
63
+ =item C<< result.value() >>
64
+
65
+ Parameters: none. Returns: value. Returns the stored ok value, or
66
+ C<null> for an error result.
67
+
68
+ =item C<< result.error() >>
69
+
70
+ Parameters: none. Returns: value. Returns the stored error value, or
71
+ C<null> for an ok result.
72
+
73
+ =item C<< result.unwrap() >>
74
+
75
+ Parameters: none. Returns: value. Returns the ok value, or throws if the
76
+ result is an error.
77
+
78
+ =item C<< result.unwrap_err() >>
79
+
80
+ Parameters: none. Returns: value. Returns the error value, or throws if
81
+ the result is ok.
82
+
83
+ =back
84
+
85
+ =back
86
+
87
+ =head1 COPYRIGHT AND LICENCE
88
+
89
+ B<< std/result >> is copyright Toby Inkster.
90
+
91
+ It is free software; you may redistribute it and/or modify it under
92
+ the terms of either the Artistic License 1.0 or the GNU General Public
93
+ License version 2.
94
+
95
+ =cut
96
+
97
+ class Result {
98
+ let Boolean _is_ok := true;
99
+ let _value := null;
100
+ let _error := null;
101
+
102
+ static method ok ( value ) {
103
+ return new self(
104
+ _is_ok: true,
105
+ _value: value,
106
+ _error: null,
107
+ );
108
+ }
109
+
110
+ static method err ( error ) {
111
+ return new self(
112
+ _is_ok: false,
113
+ _value: null,
114
+ _error: error,
115
+ );
116
+ }
117
+
118
+ method is_ok () {
119
+ return _is_ok;
120
+ }
121
+
122
+ method is_err () {
123
+ return not _is_ok;
124
+ }
125
+
126
+ method value () {
127
+ return _value;
128
+ }
129
+
130
+ method error () {
131
+ return _error;
132
+ }
133
+
134
+ method unwrap () {
135
+ if ( _is_ok ) {
136
+ return _value;
137
+ }
138
+
139
+ die `called Result.unwrap() on an err value: ${_error}`;
140
+ }
141
+
142
+ method unwrap_err () {
143
+ if ( not _is_ok ) {
144
+ return _error;
145
+ }
146
+
147
+ die `called Result.unwrap_err() on an ok value: ${_value}`;
148
+ }
149
+ }