desmost 0.9.1 → 0.10.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 +11 -2
- package/dist/compiler/compile.d.ts +1 -7
- package/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js +3 -94
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/compiler.d.ts +56 -0
- package/dist/compiler/compiler.d.ts.map +1 -0
- package/dist/compiler/compiler.js +209 -0
- package/dist/compiler/compiler.js.map +1 -0
- package/dist/compiler/format.d.ts +2 -2
- package/dist/compiler/format.d.ts.map +1 -1
- package/dist/compiler/format.js +18 -9
- package/dist/compiler/format.js.map +1 -1
- package/dist/decompiler/decompile.d.ts +1 -1
- package/dist/decompiler/decompile.d.ts.map +1 -1
- package/dist/decompiler/extract.d.ts.map +1 -1
- package/dist/decompiler/extract.js +7 -3
- package/dist/decompiler/extract.js.map +1 -1
- package/dist/errors.d.ts +35 -27
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +46 -48
- package/dist/errors.js.map +1 -1
- package/dist/index.internal.d.ts +1 -1
- package/dist/index.internal.d.ts.map +1 -1
- package/dist/magic/global/desmos.d.ts +2 -2
- package/dist/magic/global/desmos.d.ts.map +1 -1
- package/dist/magic/global/desmos.js +3 -2
- package/dist/magic/global/desmos.js.map +1 -1
- package/dist/magic/global/viewport.d.ts +2 -2
- package/dist/magic/global/viewport.d.ts.map +1 -1
- package/dist/magic/global/viewport.js +5 -5
- package/dist/magic/global/viewport.js.map +1 -1
- package/dist/magic/incantation.d.ts +4 -4
- package/dist/magic/incantation.d.ts.map +1 -1
- package/dist/magic/incantation.js +15 -8
- package/dist/magic/incantation.js.map +1 -1
- package/dist/magic/local/colour.d.ts +3 -1
- package/dist/magic/local/colour.d.ts.map +1 -1
- package/dist/magic/local/colour.js +15 -11
- package/dist/magic/local/colour.js.map +1 -1
- package/dist/magic/local/label.d.ts.map +1 -1
- package/dist/magic/local/label.js +7 -7
- package/dist/magic/local/label.js.map +1 -1
- package/dist/magic/local/line.d.ts +2 -2
- package/dist/magic/local/line.d.ts.map +1 -1
- package/dist/magic/local/line.js +0 -1
- package/dist/magic/local/line.js.map +1 -1
- package/dist/options.d.ts +57 -23
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +2 -1
- package/dist/options.js.map +1 -1
- package/dist/parser/ast.d.ts +3 -17
- package/dist/parser/ast.d.ts.map +1 -1
- package/dist/parser/ast.js +0 -2
- package/dist/parser/ast.js.map +1 -1
- package/dist/parser/desmost-parser.d.ts +33 -22
- package/dist/parser/desmost-parser.d.ts.map +1 -1
- package/dist/parser/desmost-parser.js +106 -92
- package/dist/parser/desmost-parser.js.map +1 -1
- package/dist/parser/generic-parser.d.ts +19 -10
- package/dist/parser/generic-parser.d.ts.map +1 -1
- package/dist/parser/generic-parser.js +56 -16
- package/dist/parser/generic-parser.js.map +1 -1
- package/dist/utils.d.ts +9 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +13 -2
- package/dist/utils.js.map +1 -1
- package/package.json +5 -2
- package/src/compiler/compile.ts +7 -120
- package/src/compiler/compiler.ts +275 -0
- package/src/compiler/format.ts +19 -7
- package/src/decompiler/decompile.ts +1 -1
- package/src/decompiler/extract.ts +3 -1
- package/src/errors.ts +40 -24
- package/src/index.internal.ts +1 -1
- package/src/magic/.template.ts +2 -2
- package/src/magic/global/desmos.ts +7 -9
- package/src/magic/global/viewport.ts +11 -17
- package/src/magic/incantation.ts +21 -22
- package/src/magic/local/colour.ts +23 -13
- package/src/magic/local/label.ts +11 -17
- package/src/magic/local/line.ts +2 -2
- package/src/options.ts +81 -47
- package/src/parser/ast.ts +1 -21
- package/src/parser/desmost-parser.ts +131 -135
- package/src/parser/generic-parser.ts +71 -29
- package/src/utils.ts +25 -3
- package/dist/compiler/evaluate.d.ts +0 -18
- package/dist/compiler/evaluate.d.ts.map +0 -1
- package/dist/compiler/evaluate.js +0 -93
- package/dist/compiler/evaluate.js.map +0 -1
- package/dist/desmos.d.ts +0 -16
- package/dist/desmos.d.ts.map +0 -1
- package/dist/desmos.js +0 -19
- package/dist/desmos.js.map +0 -1
- package/src/compiler/evaluate.ts +0 -128
- package/src/desmos.ts +0 -22
package/README.md
CHANGED
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
A tiny DSL for compiling LaTeX to Desmos.
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
<br>
|
|
9
|
+
|
|
10
|
+
|
|
7
11
|
<table>
|
|
8
|
-
<tr></tr>
|
|
9
12
|
<tr>
|
|
10
13
|
<th> You write this: </th>
|
|
11
14
|
<th> and Desmost gives you this: </th>
|
|
@@ -43,12 +46,18 @@ f(x) = A \sin(x-t)
|
|
|
43
46
|
In other words, it’s like HTML+CSS but for Desmos. Write your content in LaTeX (alongside your Markdown!) with Desmost syntax where you need it, and Desmost will turn it into a Desmos calculator embed for you.
|
|
44
47
|
|
|
45
48
|
|
|
49
|
+
<br>
|
|
50
|
+
|
|
51
|
+
|
|
46
52
|
## Requirements
|
|
47
53
|
|
|
48
54
|
- Desmos API v1.12
|
|
49
55
|
- Desmost only works **in the browser**, because the Desmos API can only be included via a `<script>` tag
|
|
50
56
|
|
|
51
57
|
|
|
58
|
+
<br>
|
|
59
|
+
|
|
60
|
+
|
|
52
61
|
## Usage
|
|
53
62
|
|
|
54
63
|
### Compile
|
|
@@ -91,5 +100,5 @@ This will replace all ` ```desmos ` blocks from your Markdown source with Desmos
|
|
|
91
100
|
|
|
92
101
|
|
|
93
102
|
<a href="https://brainmade.org">
|
|
94
|
-
<img
|
|
103
|
+
<img height="40" src=".assets/brainmade-black.svg" />
|
|
95
104
|
</a>
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
+
import { type DesmostDebug } from "./compiler.js";
|
|
1
2
|
import { type DesmostOptions } from "../options.js";
|
|
2
|
-
import { Ast } from "../parser/index.js";
|
|
3
|
-
/** Debug diagnostics returned from `compile()`. */
|
|
4
|
-
export interface DesmostDebug {
|
|
5
|
-
duration: number;
|
|
6
|
-
num_blocks: number;
|
|
7
|
-
ast: Ast[];
|
|
8
|
-
}
|
|
9
3
|
/**
|
|
10
4
|
* Compile Desmost into Desmos.
|
|
11
5
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,YAAY,CAAC;AAGhE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO;AACtB,sDAAsD;AACtD,MAAM,EAAE,MAAM,CAAC,UAAU;AAEzB,0CAA0C;AAC1C,MAAM,EAAE,MAAM;AAEd;;;;EAIE;AACF,OAAO,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAC/B,IAAI,GAAG,YAAY,CAmBrB"}
|
package/dist/compiler/compile.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DesmostCompiler } from "./compiler.js";
|
|
2
2
|
import { fill_defaults } from "../options.js";
|
|
3
|
-
import { DesmostParser, Ast } from "../parser/index.js";
|
|
4
3
|
/**
|
|
5
4
|
* Compile Desmost into Desmos.
|
|
6
5
|
*
|
|
@@ -37,97 +36,7 @@ options) {
|
|
|
37
36
|
console.error(`Desmost: No source code provided, aborting compilation!`);
|
|
38
37
|
return;
|
|
39
38
|
}
|
|
40
|
-
let
|
|
41
|
-
|
|
42
|
-
var t_init = performance.now();
|
|
43
|
-
var num_blocks = 0;
|
|
44
|
-
var ast = [];
|
|
45
|
-
}
|
|
46
|
-
let parser = new DesmostParser(source, opts);
|
|
47
|
-
let errors = [];
|
|
48
|
-
/* To aggregate errors at the start, we need a target to retroactively inject errors into */
|
|
49
|
-
if (opts.place_errors === "start") {
|
|
50
|
-
desmos.setExpression({ id: "deferred-start", latex: " " }); // FIXME check if ` ` needed
|
|
51
|
-
}
|
|
52
|
-
/* Keep track of whether we're still evaluating leading blank expressions, which might be ignored. */
|
|
53
|
-
let seen_non_blank = false;
|
|
54
|
-
/** The number of pending blank expressions to add. */
|
|
55
|
-
let pending_blanks = 0;
|
|
56
|
-
/* The compiler is lazy, parsing and evaluating one block at a time (as opposed to first parsing the entire AST). We don't need the whole AST, so this saves memory. */
|
|
57
|
-
/* NOTE: It also doesn't sacrifice performance, since `.setExpressions()` internally just calls `.setExpression()` in a loop anyway. Benchmarks in the frontend produce similar times for both, so there's no performance improvement. */
|
|
58
|
-
try {
|
|
59
|
-
while (true) {
|
|
60
|
-
let r = parser.parse_next();
|
|
61
|
-
if (r === null)
|
|
62
|
-
break;
|
|
63
|
-
if (opts.debug) {
|
|
64
|
-
num_blocks++;
|
|
65
|
-
ast.push(r);
|
|
66
|
-
}
|
|
67
|
-
/** An error message to leave for aggregation later. */
|
|
68
|
-
let defer = undefined;
|
|
69
|
-
switch (r.kind) {
|
|
70
|
-
case Ast.Kind.INCANTATION_INVOCATION:
|
|
71
|
-
defer = evaluate_global_incantation(r, desmos, opts);
|
|
72
|
-
break;
|
|
73
|
-
case Ast.Kind.EXPRESSION:
|
|
74
|
-
// @ts-expect-error: check type-narrows
|
|
75
|
-
if (r.data.latex === " ") {
|
|
76
|
-
if (opts.ignore_all_blanks)
|
|
77
|
-
break;
|
|
78
|
-
if (!seen_non_blank && !opts.keep_leading_blanks)
|
|
79
|
-
break;
|
|
80
|
-
pending_blanks++;
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
flush_pending_blanks(desmos, pending_blanks);
|
|
85
|
-
pending_blanks = 0;
|
|
86
|
-
seen_non_blank = true;
|
|
87
|
-
defer = evaluate_expr(r, desmos, opts);
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
case Ast.Kind.INVALID_INCANTATION:
|
|
91
|
-
defer = evaluate_error(r.error, desmos, opts);
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (defer !== undefined) {
|
|
95
|
-
errors.push(defer);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
errors.push(e.message);
|
|
101
|
-
}
|
|
102
|
-
if (opts.keep_trailing_blanks) {
|
|
103
|
-
flush_pending_blanks(desmos, pending_blanks);
|
|
104
|
-
}
|
|
105
|
-
if (errors.length > 0) {
|
|
106
|
-
let expr = {
|
|
107
|
-
type: "text",
|
|
108
|
-
text: errors.join("\n\n"),
|
|
109
|
-
};
|
|
110
|
-
switch (opts.place_errors) {
|
|
111
|
-
case "start":
|
|
112
|
-
desmos.setExpression({ ...expr, id: "deferred-start" });
|
|
113
|
-
break;
|
|
114
|
-
case "end":
|
|
115
|
-
case "inline":
|
|
116
|
-
desmos.setExpression(expr);
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (opts.debug) {
|
|
121
|
-
return {
|
|
122
|
-
duration: performance.now() - t_init,
|
|
123
|
-
num_blocks: num_blocks,
|
|
124
|
-
ast: ast,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function flush_pending_blanks(desmos, count) {
|
|
129
|
-
for (let i = 0; i < count; i++) {
|
|
130
|
-
desmos.setExpression({ latex: ` ` });
|
|
131
|
-
}
|
|
39
|
+
let compiler = new DesmostCompiler(desmos, source, fill_defaults(options));
|
|
40
|
+
return compiler.compile();
|
|
132
41
|
}
|
|
133
42
|
//# sourceMappingURL=compile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAqB,MAAM,YAAY,CAAC;AAEhE,OAAO,EAAuB,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO;AACtB,sDAAsD;AACtD,MAAyB;AAEzB,0CAA0C;AAC1C,MAAc;AAEd;;;;EAIE;AACF,OAAiC;IAGjC,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,4EAA4E,CAAC,CAAC;QAC5F,OAAO;IACR,CAAC;IAED,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO;IACR,CAAC;IAED,IAAI,QAAQ,GAAG,IAAI,eAAe,CACjC,MAAM,EACN,MAAM,EACN,aAAa,CAAC,OAAO,CAAC,CACtB,CAAC;IAEF,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { DesmostOptions } from "../options.js";
|
|
2
|
+
import { DesmostError, type Fallible } from "../errors.js";
|
|
3
|
+
import { Ast } from "../parser/index.js";
|
|
4
|
+
/** Debug diagnostics returned from `compile()`. */
|
|
5
|
+
export interface DesmostDebug {
|
|
6
|
+
duration: number;
|
|
7
|
+
num_blocks: number;
|
|
8
|
+
ast: Ast[];
|
|
9
|
+
}
|
|
10
|
+
export declare class DesmostCompiler {
|
|
11
|
+
private desmos;
|
|
12
|
+
/** The source code to compile. */
|
|
13
|
+
private source;
|
|
14
|
+
private options;
|
|
15
|
+
private parser;
|
|
16
|
+
/** Accumulated errors awaiting evaluation. */
|
|
17
|
+
private errors;
|
|
18
|
+
/**
|
|
19
|
+
* Have we only seen blank lines so far?
|
|
20
|
+
*
|
|
21
|
+
* This is used for excluding leading blanks.
|
|
22
|
+
*/
|
|
23
|
+
private seen_non_blank;
|
|
24
|
+
/**
|
|
25
|
+
* The number of pending blank expressions to add.
|
|
26
|
+
*
|
|
27
|
+
* This is used to excluding trailing blanks.
|
|
28
|
+
*/
|
|
29
|
+
private pending_blanks;
|
|
30
|
+
private debug;
|
|
31
|
+
/** Create a compiler for compiling `source` into `desmos`. */
|
|
32
|
+
constructor(desmos: Desmos.Calculator, source: string, options: DesmostOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Run the compiler to completion.
|
|
35
|
+
*/
|
|
36
|
+
compile(): void | DesmostDebug;
|
|
37
|
+
/**
|
|
38
|
+
* Compile only the next block, returning `true` if compilation has finished.
|
|
39
|
+
*/
|
|
40
|
+
compile_next(): Fallible<boolean>;
|
|
41
|
+
compile_block(block: Ast): void;
|
|
42
|
+
/**
|
|
43
|
+
* Evaluate arguments (if any) to a global incantation `invocation`, then apply the incantation to `desmos`.
|
|
44
|
+
*/
|
|
45
|
+
evaluate_global_incantation(invocation: Ast.IncantationInvocation): Fallible<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Evaluate local incantation invocations on `expr`, then add `expr` to `desmos`.
|
|
48
|
+
*/
|
|
49
|
+
evaluate_expr(expr: Ast.Expression): Fallible<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Handle a `DesmostError`, respecting the user's options.
|
|
52
|
+
*/
|
|
53
|
+
evaluate_error(error: DesmostError): Fallible<void | string>;
|
|
54
|
+
flush_pending_blanks(): void;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAiB,GAAG,EAAE,MAAM,WAAW,CAAC;AAI/C,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAE5B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,GAAG,EAAE,CAAC;CACX;AAGD,qBAAa,eAAe;IAE3B,OAAO,CAAC,MAAM,CAAmB;IAEjC,kCAAkC;IAClC,OAAO,CAAC,MAAM,CAAQ;IAEtB,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,MAAM,CAAe;IAE7B,8CAA8C;IAC9C,OAAO,CAAC,MAAM,CAAqB;IAEnC;;;;OAIG;IACH,OAAO,CAAC,cAAc,CAAQ;IAE9B;;;;OAIG;IACH,OAAO,CAAC,cAAc,CAAY;IAElC,OAAO,CAAC,KAAK,CAA4B;IAGzC,8DAA8D;gBAE7D,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc;IAUxB;;OAEG;IACI,OAAO,IAAI,IAAI,GAAG,YAAY;IAuDrC;;OAEG;IACH,YAAY,IAAI,QAAQ,CAAC,OAAO,CAAC;IAkBjC,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAoC/B;;OAEG;IACH,2BAA2B,CAAC,UAAU,EAAE,GAAG,CAAC,qBAAqB,GAAG,QAAQ,CAAC,IAAI,CAAC;IAgBlF;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC;IAsCnD;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,YAAY,GAAG,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC;IA0B5D,oBAAoB,IAAI,IAAI;CAM5B"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import dedent from "dedent";
|
|
2
|
+
import { format_error, normalise_latex, prettify_latex } from "./format.js";
|
|
3
|
+
import { DesmostError } from "../errors.js";
|
|
4
|
+
import { DesmostParser, Ast } from "../parser/index.js";
|
|
5
|
+
import { is_latex } from "../utils.js";
|
|
6
|
+
export class DesmostCompiler {
|
|
7
|
+
desmos;
|
|
8
|
+
/** The source code to compile. */
|
|
9
|
+
source;
|
|
10
|
+
options;
|
|
11
|
+
parser;
|
|
12
|
+
/** Accumulated errors awaiting evaluation. */
|
|
13
|
+
errors = [];
|
|
14
|
+
/**
|
|
15
|
+
* Have we only seen blank lines so far?
|
|
16
|
+
*
|
|
17
|
+
* This is used for excluding leading blanks.
|
|
18
|
+
*/
|
|
19
|
+
seen_non_blank = false;
|
|
20
|
+
/**
|
|
21
|
+
* The number of pending blank expressions to add.
|
|
22
|
+
*
|
|
23
|
+
* This is used to excluding trailing blanks.
|
|
24
|
+
*/
|
|
25
|
+
pending_blanks = 0;
|
|
26
|
+
debug = null;
|
|
27
|
+
/** Create a compiler for compiling `source` into `desmos`. */
|
|
28
|
+
constructor(desmos, source, options) {
|
|
29
|
+
this.desmos = desmos;
|
|
30
|
+
this.source = source;
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.parser = new DesmostParser(this.source, this.options);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Run the compiler to completion.
|
|
36
|
+
*/
|
|
37
|
+
compile() {
|
|
38
|
+
if (this.options.debug) {
|
|
39
|
+
this.debug = {
|
|
40
|
+
duration: performance.now(),
|
|
41
|
+
num_blocks: 0,
|
|
42
|
+
ast: [],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/* To aggregate errors at the start, we need a target to retroactively inject errors into */
|
|
46
|
+
if (this.options.place_errors === "start") {
|
|
47
|
+
this.desmos.setExpression({ id: "deferred", latex: " " }); // FIXME check if ` ` needed
|
|
48
|
+
}
|
|
49
|
+
/* The compiler is lazy, parsing and evaluating one block at a time (as opposed to first parsing the entire AST). We don't need the whole AST, so this saves memory. */
|
|
50
|
+
/* NOTE: It also doesn't sacrifice performance, since `.setExpressions()` internally just calls `.setExpression()` in a loop anyway. Benchmarks in the frontend produce similar times for both, so there's no performance improvement. */
|
|
51
|
+
try {
|
|
52
|
+
let done = false;
|
|
53
|
+
while (!done) {
|
|
54
|
+
done = this.compile_next();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
this.errors.push(e); // FIXME Should probably override as critical
|
|
59
|
+
}
|
|
60
|
+
if (this.options.keep_trailing_blanks) {
|
|
61
|
+
this.flush_pending_blanks();
|
|
62
|
+
}
|
|
63
|
+
/* NOTE: No need to check `options.place_errors`!
|
|
64
|
+
|
|
65
|
+
- If it's `start`, `id: deferred` will replace the placeholder at the start as required.
|
|
66
|
+
- If it's `end`, `id: deferred` won't exist so this expression will be appended as required.
|
|
67
|
+
- If it's `inline`, we shouldn't have any accumulated errors at all, but if we do, then the end is where they should be anyway.
|
|
68
|
+
*/
|
|
69
|
+
if (this.errors.length > 0) {
|
|
70
|
+
this.desmos.setExpression({
|
|
71
|
+
id: "deferred",
|
|
72
|
+
type: "text",
|
|
73
|
+
text: this.errors.map(err => format_error(err, this.options)).join("\n\n"),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.desmos.removeExpression({ id: "deferred" });
|
|
78
|
+
}
|
|
79
|
+
if (this.options.debug) {
|
|
80
|
+
this.debug.duration = performance.now() - this.debug.duration;
|
|
81
|
+
return this.debug;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Compile only the next block, returning `true` if compilation has finished.
|
|
86
|
+
*/
|
|
87
|
+
compile_next() {
|
|
88
|
+
let result = this.parser.parse_next();
|
|
89
|
+
if (result === undefined)
|
|
90
|
+
return true;
|
|
91
|
+
let { blocks, errors } = result;
|
|
92
|
+
for (let block of blocks) {
|
|
93
|
+
this.compile_block(block);
|
|
94
|
+
}
|
|
95
|
+
for (let error of errors) {
|
|
96
|
+
this.evaluate_error(error);
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
compile_block(block) {
|
|
101
|
+
if (this.options.debug) {
|
|
102
|
+
this.debug.num_blocks++;
|
|
103
|
+
this.debug.ast.push(block);
|
|
104
|
+
}
|
|
105
|
+
switch (block.kind) {
|
|
106
|
+
case Ast.Kind.INCANTATION_INVOCATION:
|
|
107
|
+
this.evaluate_global_incantation(block);
|
|
108
|
+
break;
|
|
109
|
+
case Ast.Kind.EXPRESSION:
|
|
110
|
+
// @ts-expect-error: check type-narrows
|
|
111
|
+
if (block.data.latex === " ") {
|
|
112
|
+
if (this.options.ignore_all_blanks)
|
|
113
|
+
break;
|
|
114
|
+
if (!this.seen_non_blank && !this.options.keep_leading_blanks)
|
|
115
|
+
break;
|
|
116
|
+
this.pending_blanks++;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this.flush_pending_blanks();
|
|
121
|
+
this.pending_blanks = 0;
|
|
122
|
+
this.seen_non_blank = true;
|
|
123
|
+
this.evaluate_expr(block);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// == LOW-LEVEL == //
|
|
129
|
+
/**
|
|
130
|
+
* Evaluate arguments (if any) to a global incantation `invocation`, then apply the incantation to `desmos`.
|
|
131
|
+
*/
|
|
132
|
+
evaluate_global_incantation(invocation) {
|
|
133
|
+
let data = undefined;
|
|
134
|
+
if ("arg_raw" in invocation && invocation.arg_raw != undefined) {
|
|
135
|
+
try {
|
|
136
|
+
data = invocation.incantation.evaluate_arg(invocation.arg_raw, this.options);
|
|
137
|
+
invocation.incantation.apply(this.desmos, data);
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
this.evaluate_error(e);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Evaluate local incantation invocations on `expr`, then add `expr` to `desmos`.
|
|
146
|
+
*/
|
|
147
|
+
evaluate_expr(expr) {
|
|
148
|
+
for (let invocation of expr.incantations) {
|
|
149
|
+
let data = undefined;
|
|
150
|
+
if ("arg_raw" in invocation && invocation.arg_raw != undefined) {
|
|
151
|
+
try {
|
|
152
|
+
data = invocation.incantation.evaluate_arg(invocation.arg_raw, this.options);
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
this.evaluate_error(e);
|
|
156
|
+
// if it needs the arg, then we can't press on
|
|
157
|
+
if (invocation.incantation.requires_arg)
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
invocation.incantation.apply(expr.data, data);
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
this.evaluate_error(e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (is_latex(expr.data)) {
|
|
169
|
+
expr.data.latex = normalise_latex(expr.data.latex);
|
|
170
|
+
if (this.options.prettify) {
|
|
171
|
+
expr.data.latex = prettify_latex(expr.data.latex);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else if (expr.data.type === "text" && this.options.dedent_text) {
|
|
175
|
+
expr.data.text = dedent(expr.data.text ?? "");
|
|
176
|
+
}
|
|
177
|
+
this.desmos.setExpression(expr.data);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Handle a `DesmostError`, respecting the user's options.
|
|
181
|
+
*/
|
|
182
|
+
evaluate_error(error) {
|
|
183
|
+
switch (this.options.errors) {
|
|
184
|
+
case "crash":
|
|
185
|
+
throw error;
|
|
186
|
+
case "suppress":
|
|
187
|
+
console.error(format_error(error, this.options));
|
|
188
|
+
break;
|
|
189
|
+
default: switch (this.options.place_errors) {
|
|
190
|
+
case "end":
|
|
191
|
+
case "start":
|
|
192
|
+
this.errors.push(error);
|
|
193
|
+
break;
|
|
194
|
+
case "inline":
|
|
195
|
+
this.desmos.setExpression({
|
|
196
|
+
type: "text",
|
|
197
|
+
text: format_error(error, this.options),
|
|
198
|
+
});
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
flush_pending_blanks() {
|
|
204
|
+
for (let i = 0; i < this.pending_blanks; i++) {
|
|
205
|
+
this.desmos.setExpression({ latex: ` ` });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAGzE,OAAO,EAAE,YAAY,EAAiB,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAYpC,MAAM,OAAO,eAAe;IAEnB,MAAM,CAAmB;IAEjC,kCAAkC;IAC1B,MAAM,CAAQ;IAEd,OAAO,CAAgB;IAEvB,MAAM,CAAe;IAE7B,8CAA8C;IACtC,MAAM,GAAmB,EAAE,CAAA;IAEnC;;;;OAIG;IACK,cAAc,GAAG,KAAK,CAAA;IAE9B;;;;OAIG;IACK,cAAc,GAAW,CAAC,CAAA;IAE1B,KAAK,GAAwB,IAAI,CAAA;IAGzC,8DAA8D;IAC9D,YACC,MAAyB,EACzB,MAAc,EACd,OAAuB;QAGvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAGD;;OAEG;IACI,OAAO;QAEb,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAA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AAK,UAAU;gBACd,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;gBACjD,MAAM;YAEP,OAAO,CAAC,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;gBAC5C,KAAK,KAAK,CAAC;gBACX,KAAK,OAAO;oBACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBACxB,MAAM;gBAEP,KAAK,QAAQ;oBACZ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;wBACzB,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC;qBACvC,CAAC,CAAC;oBACH,MAAM;YACR,CAAC;QACF,CAAC;IACF,CAAC;IAED,oBAAoB;QAEnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QAC3C,CAAC;IACF,CAAC;CACD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DesmostOptions } from "../options.js";
|
|
2
|
-
import {
|
|
3
|
-
export declare function format_error(e:
|
|
2
|
+
import { DesmostError } from "../errors.js";
|
|
3
|
+
export declare function format_error(e: DesmostError, options: DesmostOptions): string;
|
|
4
4
|
/**
|
|
5
5
|
* Remove line breaks from `latex` so Desmos can properly consume it.
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/compiler/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/compiler/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAIzC,wBAAgB,YAAY,CAC3B,CAAC,EAAE,YAAY,EACf,OAAO,EAAE,cAAc,GACrB,MAAM,CA6BR;AAGD;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIrD;AAGD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAmBpD"}
|
package/dist/compiler/format.js
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DesmostError } from "../errors.js";
|
|
2
2
|
import { LINE } from "../utils.js";
|
|
3
3
|
export function format_error(e, options) {
|
|
4
4
|
let prefix = options.error_prefix;
|
|
5
5
|
let sep = (prefix === "" || prefix.endsWith("\n")) ? "" : " ";
|
|
6
6
|
// TODO maybe include stack? (configurable?)
|
|
7
7
|
let display = `${prefix}${sep}${e.name}: ${e.message}`;
|
|
8
|
-
if (e.
|
|
9
|
-
display
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (e.
|
|
15
|
-
display += `\n
|
|
8
|
+
if (e.data == undefined) {
|
|
9
|
+
return display;
|
|
10
|
+
}
|
|
11
|
+
if (e.data.show != undefined) {
|
|
12
|
+
display += `\n${LINE}\n`;
|
|
13
|
+
display += e.data.show.text;
|
|
14
|
+
if (e.data.show.span != undefined) {
|
|
15
|
+
display += `\n`;
|
|
16
|
+
display += ' '.repeat(e.data.show.span.start);
|
|
17
|
+
display += '^'.repeat(e.data.show.span.length);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (options.expand_errors) {
|
|
21
|
+
if (e.data.hint != undefined)
|
|
22
|
+
display += `\n${LINE}\nHint: ${e.data.hint}`;
|
|
23
|
+
if (e.data.note != undefined)
|
|
24
|
+
display += `\n${LINE}\nNote: ${e.data.note}`;
|
|
16
25
|
}
|
|
17
26
|
return display;
|
|
18
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/compiler/format.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/compiler/format.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGhC,MAAM,UAAU,YAAY,CAC3B,CAAe,EACf,OAAuB;IAGvB,IAAI,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAClC,IAAI,GAAG,GAAG,CAAC,MAAM,KAAK,EAAE,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAE9D,4CAA4C;IAC5C,IAAI,OAAO,GAAG,GAAG,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IAEvD,IAAI,CAAC,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;QAC9B,OAAO,IAAI,KAAK,IAAI,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAE5B,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC;YACnC,OAAO,IAAI,IAAI,CAAC;YAChB,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAA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B,CACpB,CAAC;IAEF,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompile.d.ts","sourceRoot":"","sources":["../../src/decompiler/decompile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"decompile.d.ts","sourceRoot":"","sources":["../../src/decompiler/decompile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD,MAAM,WAAW,iBAAiB;IAE/B,OAAO,EAAE,GAAG,CAAC,qBAAqB,EAAE,CAAC;IACvC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC;CACzB;AAGD;;;;GAIG;AACH,wBAAgB,SAAS;AACxB,mDAAmD;AACnD,MAAM,EAAE,MAAM,CAAC,UAAU;AAEzB;;;;;;GAMG;AACH,KAAK,CAAC,EAAE,MAAM,CAAC,UAAU,EAGzB,OAAO,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAC/B,MAAM,CAGR;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,iBAAiB,CASpG;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,CAO5D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/decompiler/extract.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAMhC;;GAEG;AACH,wBAAgB,gBAAgB,CAC7B,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,KAAK,EAAE,MAAM,CAAC,UAAU,GACxB,GAAG,CAAC,qBAAqB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/decompiler/extract.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAMhC;;GAEG;AACH,wBAAgB,gBAAgB,CAC7B,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,KAAK,EAAE,MAAM,CAAC,UAAU,GACxB,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAwBlC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC7B,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,KAAK,EAAE,MAAM,CAAC,UAAU,GACxB,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAmBlC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,eAAe,GAAG,GAAG,CAAC,UAAU,CAuBrF"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { stringify_json5, prettify_source } from "./format.js";
|
|
2
2
|
import { Ast } from "../parser/index.js";
|
|
3
|
-
import { is_latex } from "../
|
|
3
|
+
import { is_latex } from "../utils.js";
|
|
4
4
|
import { DesmosIncantation, ViewportIncantation } from "../magic/global/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* Extract a `/desmos` incantation from the settings of `desmos`.
|
|
7
7
|
*/
|
|
8
8
|
export function extract_settings(desmos, blank) {
|
|
9
9
|
let defaults = blank.settings;
|
|
10
|
-
let arg_raw = stringify_json5(desmos.settings, (k, v) => (
|
|
10
|
+
let arg_raw = stringify_json5(desmos.settings, (k, v) => (
|
|
11
|
+
// @ts-expect-error: weird
|
|
12
|
+
v === defaults[k]
|
|
11
13
|
|| k === "__observers"
|
|
12
14
|
|| k === "guid"
|
|
13
15
|
|| k === "randomSeed"
|
|
@@ -26,7 +28,9 @@ export function extract_settings(desmos, blank) {
|
|
|
26
28
|
export function extract_viewport(desmos, blank) {
|
|
27
29
|
let defaults = blank.graphpaperBounds.mathCoordinates;
|
|
28
30
|
let { left, right, bottom, top } = desmos.graphpaperBounds.mathCoordinates;
|
|
29
|
-
let arg_raw = stringify_json5({ left, right, bottom, top },
|
|
31
|
+
let arg_raw = stringify_json5({ left, right, bottom, top },
|
|
32
|
+
/// @ts-expect-error: weird
|
|
33
|
+
(k, v) => v === defaults[k] ? undefined : v, " ");
|
|
30
34
|
if (arg_raw.trim() === "")
|
|
31
35
|
return null;
|
|
32
36
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/decompiler/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/decompiler/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGzE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC7B,MAAyB,EACzB,KAAwB;IAGxB,IAAI,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;IAE9B,IAAI,OAAO,GAAG,eAAe,CAC1B,MAAM,CAAC,QAAQ,EACf,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACJ,0BAA0B;IAC1B,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC;WACjB,CAAC,KAAK,aAAa;WACnB,CAAC,KAAK,MAAM;WACZ,CAAC,KAAK,YAA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