@divvun/cg3 0.0.0-stage → 0.5.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 +152 -2
- package/dist/COPYING +674 -0
- package/dist/binding.d.ts +3 -0
- package/dist/binding.js +7 -0
- package/dist/core.d.ts +37 -0
- package/dist/core.js +210 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.js +65 -0
- package/dist/glue.d.ts +48 -0
- package/dist/glue.js +7 -0
- package/dist/grammar.d.ts +105 -0
- package/dist/grammar.js +67 -0
- package/dist/handle.d.ts +18 -0
- package/dist/handle.js +38 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +45 -0
- package/dist/logging.d.ts +24 -0
- package/dist/logging.js +36 -0
- package/dist/pkg/cg3_wasm.d.ts +83 -0
- package/dist/pkg/cg3_wasm.js +475 -0
- package/dist/pkg/cg3_wasm_bg.wasm +0 -0
- package/dist/pkg/cg3_wasm_bg.wasm.d.ts +15 -0
- package/dist/pkg/snippets/cg3-wasm-e617f80cd6086414/src/sink.js +19 -0
- package/package.json +28 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@divvun/cg3`: VISL CG-3 for JavaScript. It loads compiled Constraint
|
|
3
|
+
* Grammars (`.cg3b`) and runs them, in browsers, Web Workers, Deno, Node and
|
|
4
|
+
* Bun, giving the output vislcg3 gives for the same grammar, input and
|
|
5
|
+
* options. It does not read textual grammars: compile them with `cg-comp`.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { core } from "./binding.js";
|
|
10
|
+
import { grammarReader } from "./grammar.js";
|
|
11
|
+
// [spec:cg3:req:wasm.typed-surface]
|
|
12
|
+
// This module declares the whole public API. Results are plain values, and
|
|
13
|
+
// js/build.mjs fails a build whose declarations use any.
|
|
14
|
+
// [spec:cg3:req:wasm.init]
|
|
15
|
+
/**
|
|
16
|
+
* Loads and starts the package's WebAssembly module. Call it once and wait
|
|
17
|
+
* for it before anything else. With no argument it loads the `.wasm` file
|
|
18
|
+
* that ships beside the package. Calling it again returns the same promise.
|
|
19
|
+
*/
|
|
20
|
+
export function init(source) {
|
|
21
|
+
return core.init(source);
|
|
22
|
+
}
|
|
23
|
+
/** The version of the cg3 library the package was built from, which is the package's own version. */
|
|
24
|
+
export function version() {
|
|
25
|
+
return core.call((glue) => glue.version());
|
|
26
|
+
}
|
|
27
|
+
// [spec:cg3:req:wasm.logging]
|
|
28
|
+
/**
|
|
29
|
+
* Sends the library's log events to `logger`. `null` puts back the default,
|
|
30
|
+
* which writes each event to the console method for its level. Whatever the
|
|
31
|
+
* logger, `apply` still returns its run's warnings.
|
|
32
|
+
*/
|
|
33
|
+
export function setLogger(logger) {
|
|
34
|
+
core.setLogger(logger);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Logs events at `level` and the more severe levels; `off` logs nothing.
|
|
38
|
+
* The default is `warn`. The module never sends the levels below it.
|
|
39
|
+
*/
|
|
40
|
+
export function setLogLevel(level) {
|
|
41
|
+
core.setLogLevel(level);
|
|
42
|
+
}
|
|
43
|
+
export const { readGrammar } = grammarReader(core);
|
|
44
|
+
export { Grammar } from "./grammar.js";
|
|
45
|
+
export { Cg3Error } from "./errors.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much the library logs. Each level takes in the ones before it, and
|
|
3
|
+
* `off` logs nothing. The default is `warn`.
|
|
4
|
+
*/
|
|
5
|
+
export type LogLevel = "off" | "error" | "warn" | "info" | "debug" | "trace";
|
|
6
|
+
/** One event from the library's `tracing` instrumentation. */
|
|
7
|
+
export interface LogEvent {
|
|
8
|
+
level: Exclude<LogLevel, "off">;
|
|
9
|
+
/** The Rust module the event came from, such as `cg3::grammar_applicator`. */
|
|
10
|
+
target: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
/** Receives every event at or above the log level. */
|
|
14
|
+
export type Logger = (event: LogEvent) => void;
|
|
15
|
+
export declare function isLogLevel(value: unknown): value is LogLevel;
|
|
16
|
+
export declare function levelNumber(level: LogLevel): number;
|
|
17
|
+
/** The level of an event from the glue. A number it does not use reads as trace. */
|
|
18
|
+
export declare function eventLevel(level: number): LogEvent["level"];
|
|
19
|
+
/**
|
|
20
|
+
* The logger in place until `setLogger` replaces it: each event goes to the
|
|
21
|
+
* console method for its level. At the default level only warnings and
|
|
22
|
+
* errors reach it.
|
|
23
|
+
*/
|
|
24
|
+
export declare const consoleLogger: Logger;
|
package/dist/logging.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** The levels in the glue's numbering, where each level is its index. */
|
|
2
|
+
const LEVELS = ["off", "error", "warn", "info", "debug", "trace"];
|
|
3
|
+
export function isLogLevel(value) {
|
|
4
|
+
return typeof value === "string" && LEVELS.includes(value);
|
|
5
|
+
}
|
|
6
|
+
export function levelNumber(level) {
|
|
7
|
+
return LEVELS.indexOf(level);
|
|
8
|
+
}
|
|
9
|
+
/** The level of an event from the glue. A number it does not use reads as trace. */
|
|
10
|
+
export function eventLevel(level) {
|
|
11
|
+
const name = LEVELS[level];
|
|
12
|
+
return name === undefined || name === "off" ? "trace" : name;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The logger in place until `setLogger` replaces it: each event goes to the
|
|
16
|
+
* console method for its level. At the default level only warnings and
|
|
17
|
+
* errors reach it.
|
|
18
|
+
*/
|
|
19
|
+
export const consoleLogger = ({ level, target, message }) => {
|
|
20
|
+
const line = `${target}: ${message}`;
|
|
21
|
+
switch (level) {
|
|
22
|
+
case "error":
|
|
23
|
+
console.error(line);
|
|
24
|
+
break;
|
|
25
|
+
case "warn":
|
|
26
|
+
console.warn(line);
|
|
27
|
+
break;
|
|
28
|
+
case "info":
|
|
29
|
+
console.info(line);
|
|
30
|
+
break;
|
|
31
|
+
case "debug":
|
|
32
|
+
case "trace":
|
|
33
|
+
console.debug(line);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A compiled grammar, loaded once and applied any number of times.
|
|
6
|
+
*/
|
|
7
|
+
export class Grammar {
|
|
8
|
+
private constructor();
|
|
9
|
+
free(): void;
|
|
10
|
+
[Symbol.dispose](): void;
|
|
11
|
+
/**
|
|
12
|
+
* Runs the grammar on `input` with the options in `options`, the JSON of
|
|
13
|
+
* an `ApplyOptions` object, and returns an `ApplyResult` object.
|
|
14
|
+
*/
|
|
15
|
+
apply(input: string, options: string): any;
|
|
16
|
+
/**
|
|
17
|
+
* What `CompiledGrammar::info` reports, as `GrammarInfo` in
|
|
18
|
+
* `js/cg3/grammar.ts` declares it.
|
|
19
|
+
*/
|
|
20
|
+
info(): any;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Starts the module instance: hands it the wrapper's sink, sends every panic
|
|
25
|
+
* message there before the panic aborts into a trap, and sends tracing events
|
|
26
|
+
* at `level` and above there. The wrapper calls it once, from `init()`.
|
|
27
|
+
*/
|
|
28
|
+
export function install(sink: any, level: number): void;
|
|
29
|
+
|
|
30
|
+
export function readGrammar(bytes: Uint8Array): Grammar;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Forwards events at `level` and above from here on, and nothing below it.
|
|
34
|
+
* Tracing caches which callsites are enabled, so the cache is rebuilt
|
|
35
|
+
* against the new level.
|
|
36
|
+
*/
|
|
37
|
+
export function setLogLevel(level: number): void;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The version of the library this module was built from, which the npm
|
|
41
|
+
* package is published at.
|
|
42
|
+
*/
|
|
43
|
+
export function version(): string;
|
|
44
|
+
|
|
45
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
46
|
+
|
|
47
|
+
export interface InitOutput {
|
|
48
|
+
readonly memory: WebAssembly.Memory;
|
|
49
|
+
readonly __wbg_grammar_free: (a: number, b: number) => void;
|
|
50
|
+
readonly grammar_apply: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
51
|
+
readonly grammar_info: (a: number) => number;
|
|
52
|
+
readonly install: (a: number, b: number) => void;
|
|
53
|
+
readonly readGrammar: (a: number, b: number, c: number) => void;
|
|
54
|
+
readonly setLogLevel: (a: number) => void;
|
|
55
|
+
readonly version: (a: number) => void;
|
|
56
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
57
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
58
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
59
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
60
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
67
|
+
* a precompiled `WebAssembly.Module`.
|
|
68
|
+
*
|
|
69
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
70
|
+
*
|
|
71
|
+
* @returns {InitOutput}
|
|
72
|
+
*/
|
|
73
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
77
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
78
|
+
*
|
|
79
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
80
|
+
*
|
|
81
|
+
* @returns {Promise<InitOutput>}
|
|
82
|
+
*/
|
|
83
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/* @ts-self-types="./cg3_wasm.d.ts" */
|
|
2
|
+
import { installSink, sinkLog, sinkPanic } from './snippets/cg3-wasm-e617f80cd6086414/src/sink.js';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A compiled grammar, loaded once and applied any number of times.
|
|
7
|
+
*/
|
|
8
|
+
export class Grammar {
|
|
9
|
+
static __wrap(ptr) {
|
|
10
|
+
ptr = ptr >>> 0;
|
|
11
|
+
const obj = Object.create(Grammar.prototype);
|
|
12
|
+
obj.__wbg_ptr = ptr;
|
|
13
|
+
GrammarFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
16
|
+
__destroy_into_raw() {
|
|
17
|
+
const ptr = this.__wbg_ptr;
|
|
18
|
+
this.__wbg_ptr = 0;
|
|
19
|
+
GrammarFinalization.unregister(this);
|
|
20
|
+
return ptr;
|
|
21
|
+
}
|
|
22
|
+
free() {
|
|
23
|
+
const ptr = this.__destroy_into_raw();
|
|
24
|
+
wasm.__wbg_grammar_free(ptr, 0);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Runs the grammar on `input` with the options in `options`, the JSON of
|
|
28
|
+
* an `ApplyOptions` object, and returns an `ApplyResult` object.
|
|
29
|
+
* @param {string} input
|
|
30
|
+
* @param {string} options
|
|
31
|
+
* @returns {any}
|
|
32
|
+
*/
|
|
33
|
+
apply(input, options) {
|
|
34
|
+
try {
|
|
35
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
36
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
37
|
+
const len0 = WASM_VECTOR_LEN;
|
|
38
|
+
const ptr1 = passStringToWasm0(options, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
39
|
+
const len1 = WASM_VECTOR_LEN;
|
|
40
|
+
wasm.grammar_apply(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
41
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
42
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
43
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
44
|
+
if (r2) {
|
|
45
|
+
throw takeObject(r1);
|
|
46
|
+
}
|
|
47
|
+
return takeObject(r0);
|
|
48
|
+
} finally {
|
|
49
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* What `CompiledGrammar::info` reports, as `GrammarInfo` in
|
|
54
|
+
* `js/cg3/grammar.ts` declares it.
|
|
55
|
+
* @returns {any}
|
|
56
|
+
*/
|
|
57
|
+
info() {
|
|
58
|
+
const ret = wasm.grammar_info(this.__wbg_ptr);
|
|
59
|
+
return takeObject(ret);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (Symbol.dispose) Grammar.prototype[Symbol.dispose] = Grammar.prototype.free;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Starts the module instance: hands it the wrapper's sink, sends every panic
|
|
66
|
+
* message there before the panic aborts into a trap, and sends tracing events
|
|
67
|
+
* at `level` and above there. The wrapper calls it once, from `init()`.
|
|
68
|
+
* @param {any} sink
|
|
69
|
+
* @param {number} level
|
|
70
|
+
*/
|
|
71
|
+
export function install(sink, level) {
|
|
72
|
+
wasm.install(addHeapObject(sink), level);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {Uint8Array} bytes
|
|
77
|
+
* @returns {Grammar}
|
|
78
|
+
*/
|
|
79
|
+
export function readGrammar(bytes) {
|
|
80
|
+
try {
|
|
81
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
82
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_export);
|
|
83
|
+
const len0 = WASM_VECTOR_LEN;
|
|
84
|
+
wasm.readGrammar(retptr, ptr0, len0);
|
|
85
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
86
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
87
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
88
|
+
if (r2) {
|
|
89
|
+
throw takeObject(r1);
|
|
90
|
+
}
|
|
91
|
+
return Grammar.__wrap(r0);
|
|
92
|
+
} finally {
|
|
93
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Forwards events at `level` and above from here on, and nothing below it.
|
|
99
|
+
* Tracing caches which callsites are enabled, so the cache is rebuilt
|
|
100
|
+
* against the new level.
|
|
101
|
+
* @param {number} level
|
|
102
|
+
*/
|
|
103
|
+
export function setLogLevel(level) {
|
|
104
|
+
wasm.setLogLevel(level);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The version of the library this module was built from, which the npm
|
|
109
|
+
* package is published at.
|
|
110
|
+
* @returns {string}
|
|
111
|
+
*/
|
|
112
|
+
export function version() {
|
|
113
|
+
let deferred1_0;
|
|
114
|
+
let deferred1_1;
|
|
115
|
+
try {
|
|
116
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
117
|
+
wasm.version(retptr);
|
|
118
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
119
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
120
|
+
deferred1_0 = r0;
|
|
121
|
+
deferred1_1 = r1;
|
|
122
|
+
return getStringFromWasm0(r0, r1);
|
|
123
|
+
} finally {
|
|
124
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
125
|
+
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function __wbg_get_imports() {
|
|
129
|
+
const import0 = {
|
|
130
|
+
__proto__: null,
|
|
131
|
+
__wbg___wbindgen_debug_string_ab4b34d23d6778bd: function(arg0, arg1) {
|
|
132
|
+
const ret = debugString(getObject(arg1));
|
|
133
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
134
|
+
const len1 = WASM_VECTOR_LEN;
|
|
135
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
136
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
137
|
+
},
|
|
138
|
+
__wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
|
|
139
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
140
|
+
},
|
|
141
|
+
__wbg_installSink_91e2b9a7428d86ae: function(arg0) {
|
|
142
|
+
installSink(takeObject(arg0));
|
|
143
|
+
},
|
|
144
|
+
__wbg_new_682678e2f47e32bc: function() {
|
|
145
|
+
const ret = new Array();
|
|
146
|
+
return addHeapObject(ret);
|
|
147
|
+
},
|
|
148
|
+
__wbg_new_aa8d0fa9762c29bd: function() {
|
|
149
|
+
const ret = new Object();
|
|
150
|
+
return addHeapObject(ret);
|
|
151
|
+
},
|
|
152
|
+
__wbg_push_471a5b068a5295f6: function(arg0, arg1) {
|
|
153
|
+
const ret = getObject(arg0).push(getObject(arg1));
|
|
154
|
+
return ret;
|
|
155
|
+
},
|
|
156
|
+
__wbg_set_022bee52d0b05b19: function() { return handleError(function (arg0, arg1, arg2) {
|
|
157
|
+
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
158
|
+
return ret;
|
|
159
|
+
}, arguments); },
|
|
160
|
+
__wbg_sinkLog_939b7ec9bc2a1d5b: function(arg0, arg1, arg2, arg3, arg4) {
|
|
161
|
+
sinkLog(arg0, getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
|
|
162
|
+
},
|
|
163
|
+
__wbg_sinkPanic_c595f4bb4e5748dd: function(arg0, arg1) {
|
|
164
|
+
sinkPanic(getStringFromWasm0(arg0, arg1));
|
|
165
|
+
},
|
|
166
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
167
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
168
|
+
const ret = arg0;
|
|
169
|
+
return addHeapObject(ret);
|
|
170
|
+
},
|
|
171
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
172
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
173
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
174
|
+
return addHeapObject(ret);
|
|
175
|
+
},
|
|
176
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
177
|
+
takeObject(arg0);
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
__proto__: null,
|
|
182
|
+
"./cg3_wasm_bg.js": import0,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const GrammarFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
187
|
+
? { register: () => {}, unregister: () => {} }
|
|
188
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_grammar_free(ptr >>> 0, 1));
|
|
189
|
+
|
|
190
|
+
function addHeapObject(obj) {
|
|
191
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
192
|
+
const idx = heap_next;
|
|
193
|
+
heap_next = heap[idx];
|
|
194
|
+
|
|
195
|
+
heap[idx] = obj;
|
|
196
|
+
return idx;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function debugString(val) {
|
|
200
|
+
// primitive types
|
|
201
|
+
const type = typeof val;
|
|
202
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
203
|
+
return `${val}`;
|
|
204
|
+
}
|
|
205
|
+
if (type == 'string') {
|
|
206
|
+
return `"${val}"`;
|
|
207
|
+
}
|
|
208
|
+
if (type == 'symbol') {
|
|
209
|
+
const description = val.description;
|
|
210
|
+
if (description == null) {
|
|
211
|
+
return 'Symbol';
|
|
212
|
+
} else {
|
|
213
|
+
return `Symbol(${description})`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (type == 'function') {
|
|
217
|
+
const name = val.name;
|
|
218
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
219
|
+
return `Function(${name})`;
|
|
220
|
+
} else {
|
|
221
|
+
return 'Function';
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// objects
|
|
225
|
+
if (Array.isArray(val)) {
|
|
226
|
+
const length = val.length;
|
|
227
|
+
let debug = '[';
|
|
228
|
+
if (length > 0) {
|
|
229
|
+
debug += debugString(val[0]);
|
|
230
|
+
}
|
|
231
|
+
for(let i = 1; i < length; i++) {
|
|
232
|
+
debug += ', ' + debugString(val[i]);
|
|
233
|
+
}
|
|
234
|
+
debug += ']';
|
|
235
|
+
return debug;
|
|
236
|
+
}
|
|
237
|
+
// Test for built-in
|
|
238
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
239
|
+
let className;
|
|
240
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
241
|
+
className = builtInMatches[1];
|
|
242
|
+
} else {
|
|
243
|
+
// Failed to match the standard '[object ClassName]'
|
|
244
|
+
return toString.call(val);
|
|
245
|
+
}
|
|
246
|
+
if (className == 'Object') {
|
|
247
|
+
// we're a user defined class or Object
|
|
248
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
249
|
+
// easier than looping through ownProperties of `val`.
|
|
250
|
+
try {
|
|
251
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
252
|
+
} catch (_) {
|
|
253
|
+
return 'Object';
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// errors
|
|
257
|
+
if (val instanceof Error) {
|
|
258
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
259
|
+
}
|
|
260
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
261
|
+
return className;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function dropObject(idx) {
|
|
265
|
+
if (idx < 1028) return;
|
|
266
|
+
heap[idx] = heap_next;
|
|
267
|
+
heap_next = idx;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
let cachedDataViewMemory0 = null;
|
|
271
|
+
function getDataViewMemory0() {
|
|
272
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
273
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
274
|
+
}
|
|
275
|
+
return cachedDataViewMemory0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function getStringFromWasm0(ptr, len) {
|
|
279
|
+
ptr = ptr >>> 0;
|
|
280
|
+
return decodeText(ptr, len);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
let cachedUint8ArrayMemory0 = null;
|
|
284
|
+
function getUint8ArrayMemory0() {
|
|
285
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
286
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
287
|
+
}
|
|
288
|
+
return cachedUint8ArrayMemory0;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function getObject(idx) { return heap[idx]; }
|
|
292
|
+
|
|
293
|
+
function handleError(f, args) {
|
|
294
|
+
try {
|
|
295
|
+
return f.apply(this, args);
|
|
296
|
+
} catch (e) {
|
|
297
|
+
wasm.__wbindgen_export3(addHeapObject(e));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
let heap = new Array(1024).fill(undefined);
|
|
302
|
+
heap.push(undefined, null, true, false);
|
|
303
|
+
|
|
304
|
+
let heap_next = heap.length;
|
|
305
|
+
|
|
306
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
307
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
308
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
309
|
+
WASM_VECTOR_LEN = arg.length;
|
|
310
|
+
return ptr;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
314
|
+
if (realloc === undefined) {
|
|
315
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
316
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
317
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
318
|
+
WASM_VECTOR_LEN = buf.length;
|
|
319
|
+
return ptr;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
let len = arg.length;
|
|
323
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
324
|
+
|
|
325
|
+
const mem = getUint8ArrayMemory0();
|
|
326
|
+
|
|
327
|
+
let offset = 0;
|
|
328
|
+
|
|
329
|
+
for (; offset < len; offset++) {
|
|
330
|
+
const code = arg.charCodeAt(offset);
|
|
331
|
+
if (code > 0x7F) break;
|
|
332
|
+
mem[ptr + offset] = code;
|
|
333
|
+
}
|
|
334
|
+
if (offset !== len) {
|
|
335
|
+
if (offset !== 0) {
|
|
336
|
+
arg = arg.slice(offset);
|
|
337
|
+
}
|
|
338
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
339
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
340
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
341
|
+
|
|
342
|
+
offset += ret.written;
|
|
343
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
WASM_VECTOR_LEN = offset;
|
|
347
|
+
return ptr;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function takeObject(idx) {
|
|
351
|
+
const ret = getObject(idx);
|
|
352
|
+
dropObject(idx);
|
|
353
|
+
return ret;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
357
|
+
cachedTextDecoder.decode();
|
|
358
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
359
|
+
let numBytesDecoded = 0;
|
|
360
|
+
function decodeText(ptr, len) {
|
|
361
|
+
numBytesDecoded += len;
|
|
362
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
363
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
364
|
+
cachedTextDecoder.decode();
|
|
365
|
+
numBytesDecoded = len;
|
|
366
|
+
}
|
|
367
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const cachedTextEncoder = new TextEncoder();
|
|
371
|
+
|
|
372
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
373
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
374
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
375
|
+
view.set(buf);
|
|
376
|
+
return {
|
|
377
|
+
read: arg.length,
|
|
378
|
+
written: buf.length
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
let WASM_VECTOR_LEN = 0;
|
|
384
|
+
|
|
385
|
+
let wasmModule, wasm;
|
|
386
|
+
function __wbg_finalize_init(instance, module) {
|
|
387
|
+
wasm = instance.exports;
|
|
388
|
+
wasmModule = module;
|
|
389
|
+
cachedDataViewMemory0 = null;
|
|
390
|
+
cachedUint8ArrayMemory0 = null;
|
|
391
|
+
return wasm;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async function __wbg_load(module, imports) {
|
|
395
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
396
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
397
|
+
try {
|
|
398
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
399
|
+
} catch (e) {
|
|
400
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
401
|
+
|
|
402
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
403
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
404
|
+
|
|
405
|
+
} else { throw e; }
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const bytes = await module.arrayBuffer();
|
|
410
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
411
|
+
} else {
|
|
412
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
413
|
+
|
|
414
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
415
|
+
return { instance, module };
|
|
416
|
+
} else {
|
|
417
|
+
return instance;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function expectedResponseType(type) {
|
|
422
|
+
switch (type) {
|
|
423
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
424
|
+
}
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function initSync(module) {
|
|
430
|
+
if (wasm !== undefined) return wasm;
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
if (module !== undefined) {
|
|
434
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
435
|
+
({module} = module)
|
|
436
|
+
} else {
|
|
437
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const imports = __wbg_get_imports();
|
|
442
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
443
|
+
module = new WebAssembly.Module(module);
|
|
444
|
+
}
|
|
445
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
446
|
+
return __wbg_finalize_init(instance, module);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
async function __wbg_init(module_or_path) {
|
|
450
|
+
if (wasm !== undefined) return wasm;
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
if (module_or_path !== undefined) {
|
|
454
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
455
|
+
({module_or_path} = module_or_path)
|
|
456
|
+
} else {
|
|
457
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (module_or_path === undefined) {
|
|
462
|
+
module_or_path = new URL('cg3_wasm_bg.wasm', import.meta.url);
|
|
463
|
+
}
|
|
464
|
+
const imports = __wbg_get_imports();
|
|
465
|
+
|
|
466
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
467
|
+
module_or_path = fetch(module_or_path);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
471
|
+
|
|
472
|
+
return __wbg_finalize_init(instance, module);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_grammar_free: (a: number, b: number) => void;
|
|
5
|
+
export const grammar_apply: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
6
|
+
export const grammar_info: (a: number) => number;
|
|
7
|
+
export const install: (a: number, b: number) => void;
|
|
8
|
+
export const readGrammar: (a: number, b: number, c: number) => void;
|
|
9
|
+
export const setLogLevel: (a: number) => void;
|
|
10
|
+
export const version: (a: number) => void;
|
|
11
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
12
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
13
|
+
export const __wbindgen_export3: (a: number) => void;
|
|
14
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
15
|
+
export const __wbindgen_export4: (a: number, b: number, c: number) => void;
|