zuzu-js 0.2.0 → 0.4.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/README.md +0 -6
- package/bin/zuzu-generate-browser-stdlib +1 -0
- package/dist/zuzu-browser-worker.js +1484 -369
- package/dist/zuzu-browser.js +1488 -373
- package/lib/cli.js +1 -1
- package/lib/collections.js +6 -2
- package/lib/runtime-helpers.js +36 -0
- package/lib/runtime.js +128 -10
- package/lib/transpiler-new/codegen.js +45 -0
- package/lib/transpiler-new/lexer.js +40 -1
- package/lib/transpiler-new/parser.js +32 -14
- package/lib/transpiler-new/validate-bindings.js +21 -1
- package/modules/std/math/bignum.js +158 -31
- package/modules/std/math.js +1 -1
- package/modules/std/net/url.js +33 -24
- package/modules/std/string/encode.js +188 -0
- package/modules/std/string.js +21 -0
- package/modules/std/time.js +95 -4
- package/package.json +2 -1
- package/stdlib/modules/std/colour.zzm +1 -0
- package/stdlib/modules/std/config.zzm +6 -5
- package/stdlib/modules/std/getopt.zzm +3 -15
- package/stdlib/modules/std/net/url.zzm +45 -3
- package/stdlib/modules/std/string/encode.zzm +95 -0
|
@@ -534,11 +534,12 @@ class Config extends Node {
|
|
|
534
534
|
}
|
|
535
535
|
|
|
536
536
|
method clone () {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
537
|
+
return new Config(
|
|
538
|
+
raw: _merge_values( {}, self.raw, {} ),
|
|
539
|
+
_layers: _layers.copy(),
|
|
540
|
+
_source: _source,
|
|
541
|
+
_format: _format,
|
|
542
|
+
);
|
|
542
543
|
}
|
|
543
544
|
|
|
544
545
|
method _delegate_node () {
|
|
@@ -126,21 +126,6 @@ function _normalize_schema_type ( raw_type ) {
|
|
|
126
126
|
if ( raw_type ≡ null ) {
|
|
127
127
|
return "Boolean";
|
|
128
128
|
}
|
|
129
|
-
if ( raw_type instanceof Function ) {
|
|
130
|
-
let function_name := null;
|
|
131
|
-
try {
|
|
132
|
-
function_name := raw_type.name;
|
|
133
|
-
}
|
|
134
|
-
catch {
|
|
135
|
-
}
|
|
136
|
-
if (
|
|
137
|
-
function_name ≡ "Boolean" or
|
|
138
|
-
function_name ≡ "Number" or
|
|
139
|
-
function_name ≡ "String"
|
|
140
|
-
) {
|
|
141
|
-
return function_name;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
129
|
if ( raw_type ≡ Boolean ) {
|
|
145
130
|
return "Boolean";
|
|
146
131
|
}
|
|
@@ -150,6 +135,9 @@ function _normalize_schema_type ( raw_type ) {
|
|
|
150
135
|
if ( raw_type ≡ String ) {
|
|
151
136
|
return "String";
|
|
152
137
|
}
|
|
138
|
+
if ( raw_type instanceof Function ) {
|
|
139
|
+
return "String";
|
|
140
|
+
}
|
|
153
141
|
let type_name := "" _ raw_type;
|
|
154
142
|
if ( type_name ≡ "" ) {
|
|
155
143
|
return "Boolean";
|
|
@@ -54,9 +54,51 @@ C<query_params>.
|
|
|
54
54
|
|
|
55
55
|
=item C<< fill_template(template, values) >>
|
|
56
56
|
|
|
57
|
-
Parameters: C<template> is an
|
|
58
|
-
dictionary or pair list. Returns: C<String>.
|
|
59
|
-
C<values>.
|
|
57
|
+
Parameters: C<template> is an RFC 6570 URI Template and C<values> is a
|
|
58
|
+
dictionary or pair list of template variables. Returns: C<String>.
|
|
59
|
+
Expands the template using C<values>.
|
|
60
|
+
|
|
61
|
+
This is a complete implementation of RFC 6570 (all four levels),
|
|
62
|
+
validated against the official URI Template test suite. All expression
|
|
63
|
+
operators are supported:
|
|
64
|
+
|
|
65
|
+
=over
|
|
66
|
+
|
|
67
|
+
=item * C<{var}> - simple string expansion;
|
|
68
|
+
|
|
69
|
+
=item * C<{+var}> - reserved expansion, leaving URI-reserved characters
|
|
70
|
+
and percent-encoded triplets intact;
|
|
71
|
+
|
|
72
|
+
=item * C<{#var}> - fragment expansion;
|
|
73
|
+
|
|
74
|
+
=item * C<{.var}> - label expansion with a dot prefix;
|
|
75
|
+
|
|
76
|
+
=item * C<{/var}> - path segment expansion;
|
|
77
|
+
|
|
78
|
+
=item * C<{;var}> - path-style parameter expansion;
|
|
79
|
+
|
|
80
|
+
=item * C<{?var}> - form-style query expansion;
|
|
81
|
+
|
|
82
|
+
=item * C<{&var}> - form-style query continuation.
|
|
83
|
+
|
|
84
|
+
=back
|
|
85
|
+
|
|
86
|
+
Each variable in an expression may take the C<:N> prefix modifier
|
|
87
|
+
(expand only the first I<N> characters of a string value, with I<N>
|
|
88
|
+
between 1 and 9999) or the C<*> explode modifier (expand list and
|
|
89
|
+
dictionary members as separate items), and expressions may name several
|
|
90
|
+
variables separated by commas, for example C<{?q,page,lang}>.
|
|
91
|
+
|
|
92
|
+
Variable values may be Strings (or Numbers and Booleans, which are
|
|
93
|
+
rendered as text), Arrays (RFC 6570 list values), or Dicts and pair
|
|
94
|
+
lists (RFC 6570 associative values; dictionary keys are expanded in
|
|
95
|
+
sorted order). Variables that are null, missing, or empty lists or
|
|
96
|
+
dictionaries are undefined per RFC 6570 and are omitted from the
|
|
97
|
+
expansion.
|
|
98
|
+
|
|
99
|
+
Invalid templates - unbalanced braces, unknown operators, malformed
|
|
100
|
+
variable names or modifiers, or a C<:N> prefix applied to a list or
|
|
101
|
+
dictionary value - throw an exception.
|
|
60
102
|
|
|
61
103
|
=back
|
|
62
104
|
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
=encoding utf8
|
|
2
|
+
|
|
3
|
+
=head1 NAME
|
|
4
|
+
|
|
5
|
+
std/string/encode - Character-encoding conversions between Strings and BinaryStrings.
|
|
6
|
+
|
|
7
|
+
=head1 SYNOPSIS
|
|
8
|
+
|
|
9
|
+
from std/string/encode import *;
|
|
10
|
+
|
|
11
|
+
let bytes := encode( "héllo", ENCODING_UTF16 );
|
|
12
|
+
let text := decode( bytes, "UTF-16" );
|
|
13
|
+
|
|
14
|
+
=head1 IMPLEMENTATION SUPPORT
|
|
15
|
+
|
|
16
|
+
This module is supported by all implementations of ZuzuScript.
|
|
17
|
+
|
|
18
|
+
=head1 DESCRIPTION
|
|
19
|
+
|
|
20
|
+
This module converts between text (C<String>) and encoded bytes
|
|
21
|
+
(C<BinaryString>).
|
|
22
|
+
|
|
23
|
+
All implementations support UTF-8, UTF-16, UTF-32, and ISO-8859-1
|
|
24
|
+
(Latin-1). Implementations are encouraged to support additional
|
|
25
|
+
encodings where the host platform makes that practical; programs that
|
|
26
|
+
need to run on every implementation should restrict themselves to the
|
|
27
|
+
four required encodings.
|
|
28
|
+
|
|
29
|
+
Encoding names are matched case-insensitively, so C<"utf-8"> and
|
|
30
|
+
C<"UTF-8"> are equivalent.
|
|
31
|
+
|
|
32
|
+
For UTF-16 and UTF-32, C<encode> produces the canonical form: big-endian
|
|
33
|
+
with no byte order mark. This is deterministic and identical across
|
|
34
|
+
implementations. C<decode> honours a leading byte order mark (consuming
|
|
35
|
+
it and switching to little-endian where it says so) and otherwise
|
|
36
|
+
assumes big-endian input.
|
|
37
|
+
|
|
38
|
+
Invalid input raises an exception: unknown encoding names, bytes that do
|
|
39
|
+
not form valid text in the requested encoding, and characters that the
|
|
40
|
+
target encoding cannot represent (for example, encoding C<"😀"> as
|
|
41
|
+
ISO-8859-1) all throw.
|
|
42
|
+
|
|
43
|
+
=head1 EXPORTS
|
|
44
|
+
|
|
45
|
+
=head2 Functions
|
|
46
|
+
|
|
47
|
+
=over
|
|
48
|
+
|
|
49
|
+
=item * C<encode(String text, String encoding)>
|
|
50
|
+
|
|
51
|
+
Parameters: C<text> is the text to encode; C<encoding> names the target
|
|
52
|
+
encoding and defaults to C<"UTF-8">. Returns: C<BinaryString>. Encodes
|
|
53
|
+
C<text> as bytes. Throws a TypeException if C<text> is not a C<String>,
|
|
54
|
+
and an exception if the encoding is unknown or cannot represent a
|
|
55
|
+
character in C<text>.
|
|
56
|
+
|
|
57
|
+
=item * C<decode(BinaryString bytes, String encoding)>
|
|
58
|
+
|
|
59
|
+
Parameters: C<bytes> is the encoded input; C<encoding> names the source
|
|
60
|
+
encoding and defaults to C<"UTF-8">. Returns: C<String>. Decodes
|
|
61
|
+
C<bytes> into text. Throws a TypeException if C<bytes> is not a
|
|
62
|
+
C<BinaryString>, and an exception if the encoding is unknown or the
|
|
63
|
+
bytes are not valid for it.
|
|
64
|
+
|
|
65
|
+
=back
|
|
66
|
+
|
|
67
|
+
=head2 Constants
|
|
68
|
+
|
|
69
|
+
=over
|
|
70
|
+
|
|
71
|
+
=item C<ENCODING_UTF8>
|
|
72
|
+
|
|
73
|
+
Type: C<String>. The value C<"UTF-8">.
|
|
74
|
+
|
|
75
|
+
=item C<ENCODING_UTF16>
|
|
76
|
+
|
|
77
|
+
Type: C<String>. The value C<"UTF-16">.
|
|
78
|
+
|
|
79
|
+
=item C<ENCODING_UTF32>
|
|
80
|
+
|
|
81
|
+
Type: C<String>. The value C<"UTF-32">.
|
|
82
|
+
|
|
83
|
+
=item C<ENCODING_LATIN>
|
|
84
|
+
|
|
85
|
+
Type: C<String>. The value C<"ISO-8859-1">.
|
|
86
|
+
|
|
87
|
+
=back
|
|
88
|
+
|
|
89
|
+
=head1 COPYRIGHT AND LICENCE
|
|
90
|
+
|
|
91
|
+
B<< std/string/encode >> is copyright Toby Inkster.
|
|
92
|
+
|
|
93
|
+
It is free software; you may redistribute it and/or modify it under
|
|
94
|
+
the terms of either the Artistic License 1.0 or the GNU General Public
|
|
95
|
+
License version 2.
|