desmost 0.8.2 → 0.9.1
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 +80 -13
- package/dist/compiler/compile.d.ts +7 -3
- package/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js +7 -3
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/evaluate.d.ts +5 -5
- package/dist/compiler/evaluate.d.ts.map +1 -1
- package/dist/compiler/evaluate.js +16 -8
- package/dist/compiler/evaluate.js.map +1 -1
- package/dist/compiler/format.d.ts +2 -2
- package/dist/compiler/format.d.ts.map +1 -1
- package/dist/compiler/format.js +14 -1
- package/dist/compiler/format.js.map +1 -1
- package/dist/compiler/index.d.ts +0 -1
- package/dist/compiler/index.d.ts.map +1 -1
- package/dist/decompiler/decompile.d.ts +12 -1
- package/dist/decompiler/decompile.d.ts.map +1 -1
- package/dist/decompiler/decompile.js +14 -2
- package/dist/decompiler/decompile.js.map +1 -1
- package/dist/decompiler/emit.d.ts.map +1 -1
- package/dist/decompiler/emit.js +13 -6
- package/dist/decompiler/emit.js.map +1 -1
- package/dist/decompiler/extract.d.ts.map +1 -1
- package/dist/decompiler/extract.js +3 -2
- package/dist/decompiler/extract.js.map +1 -1
- package/dist/decompiler/format.js +1 -1
- package/dist/decompiler/format.js.map +1 -1
- package/dist/desmos.d.ts +4 -0
- package/dist/desmos.d.ts.map +1 -1
- package/dist/desmos.js +6 -0
- package/dist/desmos.js.map +1 -1
- package/dist/errors.d.ts +18 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +37 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.internal.d.ts +1 -1
- package/dist/index.internal.d.ts.map +1 -1
- package/dist/index.internal.js +1 -1
- package/dist/index.internal.js.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/magic/expr/latex.d.ts +1 -2
- package/dist/magic/expr/latex.d.ts.map +1 -1
- package/dist/magic/expr/latex.js +1 -4
- package/dist/magic/expr/latex.js.map +1 -1
- package/dist/magic/expr/text.d.ts +1 -1
- package/dist/magic/expr/text.d.ts.map +1 -1
- package/dist/magic/expr/text.js +1 -1
- package/dist/magic/expr/text.js.map +1 -1
- package/dist/magic/global/dark-mode.d.ts.map +1 -1
- package/dist/magic/global/dark-mode.js +1 -3
- package/dist/magic/global/dark-mode.js.map +1 -1
- package/dist/magic/global/desmos.d.ts +4 -1
- package/dist/magic/global/desmos.d.ts.map +1 -1
- package/dist/magic/global/desmos.js +14 -1
- package/dist/magic/global/desmos.js.map +1 -1
- package/dist/magic/global/viewport.d.ts +3 -0
- package/dist/magic/global/viewport.d.ts.map +1 -1
- package/dist/magic/global/viewport.js +23 -0
- package/dist/magic/global/viewport.js.map +1 -1
- package/dist/magic/incantation.d.ts +13 -8
- package/dist/magic/incantation.d.ts.map +1 -1
- package/dist/magic/incantation.js +23 -3
- package/dist/magic/incantation.js.map +1 -1
- package/dist/magic/local/anim.d.ts.map +1 -1
- package/dist/magic/local/anim.js +0 -1
- package/dist/magic/local/anim.js.map +1 -1
- package/dist/magic/local/colour.d.ts +3 -2
- package/dist/magic/local/colour.d.ts.map +1 -1
- package/dist/magic/local/colour.js +3 -3
- package/dist/magic/local/colour.js.map +1 -1
- package/dist/magic/local/label.d.ts +4 -3
- package/dist/magic/local/label.d.ts.map +1 -1
- package/dist/magic/local/label.js +37 -16
- package/dist/magic/local/label.js.map +1 -1
- package/dist/magic/local/line.d.ts +3 -0
- package/dist/magic/local/line.d.ts.map +1 -1
- package/dist/magic/local/line.js +10 -0
- package/dist/magic/local/line.js.map +1 -1
- package/dist/magic/local/slider.d.ts +2 -2
- package/dist/magic/local/slider.d.ts.map +1 -1
- package/dist/magic/local/slider.js +0 -1
- package/dist/magic/local/slider.js.map +1 -1
- package/dist/{compiler/options.d.ts → options.d.ts} +49 -22
- package/dist/options.d.ts.map +1 -0
- package/dist/{compiler/options.js → options.js} +6 -1
- package/dist/options.js.map +1 -0
- package/dist/parser/desmost-parser.d.ts +1 -1
- package/dist/parser/desmost-parser.d.ts.map +1 -1
- package/dist/parser/desmost-parser.js +9 -5
- package/dist/parser/desmost-parser.js.map +1 -1
- package/dist/parser/generic-parser.d.ts +1 -5
- package/dist/parser/generic-parser.d.ts.map +1 -1
- package/dist/parser/generic-parser.js +7 -10
- package/dist/parser/generic-parser.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -1
- package/package.json +9 -6
- package/src/compiler/compile.ts +8 -4
- package/src/compiler/evaluate.ts +22 -13
- package/src/compiler/format.ts +16 -3
- package/src/compiler/index.ts +0 -1
- package/src/decompiler/decompile.ts +18 -2
- package/src/decompiler/emit.ts +15 -6
- package/src/decompiler/extract.ts +3 -2
- package/src/decompiler/format.ts +1 -1
- package/src/decompiler/readme.md +9 -1
- package/src/desmos.ts +9 -0
- package/src/errors.ts +29 -8
- package/src/index.internal.ts +1 -1
- package/src/index.ts +2 -2
- package/src/magic/.template.ts +25 -16
- package/src/magic/expr/latex.ts +2 -7
- package/src/magic/expr/text.ts +2 -2
- package/src/magic/global/dark-mode.ts +1 -3
- package/src/magic/global/desmos.ts +23 -1
- package/src/magic/global/viewport.ts +40 -1
- package/src/magic/incantation.ts +59 -22
- package/src/magic/local/anim.ts +0 -1
- package/src/magic/local/colour.ts +4 -3
- package/src/magic/local/label.ts +52 -22
- package/src/magic/local/line.ts +20 -3
- package/src/magic/local/slider.ts +2 -3
- package/src/{compiler/options.ts → options.ts} +61 -14
- package/src/parser/desmost-parser.ts +12 -6
- package/src/parser/generic-parser.ts +12 -12
- package/src/parser/readme.md +2 -0
- package/src/utils.ts +3 -0
- package/svelte/desmost.svelte +5 -3
- package/dist/compiler/options.d.ts.map +0 -1
- package/dist/compiler/options.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,28 +1,95 @@
|
|
|
1
1
|
# Desmost
|
|
2
2
|
|
|
3
|
-
[**Docs**](https://github.com/Sup2point0/desmost/tree/main/docs)  ·  [**Changelog**](https://github.com/Sup2point0/desmost/blob/main/CHANGELOG.md)  ·  [**Playground**](https://sup2point0.github.io/desmost)
|
|
3
|
+
[**Docs**](https://github.com/Sup2point0/desmost/tree/main/docs)  ·  [**Changelog**](https://github.com/Sup2point0/desmost/blob/main/CHANGELOG.md)  ·  [**Learn**](https://github.com/Sup2point0/desmost/blob/main/docs/writing/learn-x-in-y.md)  ·  [**Playground**](https://sup2point0.github.io/desmost)
|
|
4
4
|
|
|
5
5
|
A tiny DSL for compiling LaTeX to Desmos.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
<table>
|
|
8
|
+
<tr></tr>
|
|
9
|
+
<tr>
|
|
10
|
+
<th> You write this: </th>
|
|
11
|
+
<th> and Desmost gives you this: </th>
|
|
12
|
+
</tr>
|
|
13
|
+
<tr>
|
|
14
|
+
<td>
|
|
15
|
+
<pre lang="hs"><code>
|
|
16
|
+
/viewport{left: -5, right: 5}
|
|
17
|
+
<br>
|
|
11
18
|
% Drag the slider!
|
|
12
|
-
|
|
13
19
|
A = 1
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/label{
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
f(x) = A \sin(x-t)
|
|
21
|
+
<br>
|
|
22
|
+
/label{
|
|
23
|
+
text: "we love Desmos(t)!"
|
|
24
|
+
} :: (0, f(0))
|
|
25
|
+
<br>
|
|
26
|
+
/anim
|
|
27
|
+
/slider{min: -10, max: 10}
|
|
19
28
|
:: t = 0
|
|
20
|
-
|
|
29
|
+
</code></pre>
|
|
30
|
+
</td>
|
|
31
|
+
<td>
|
|
32
|
+
<a href="https://sup2point0.github.io/desmost">
|
|
33
|
+
<img
|
|
34
|
+
width="600"
|
|
35
|
+
src=".assets/demo.png"
|
|
36
|
+
alt="“Desmos(t) is awesome!”, but in a fully-fledged Desmos graphing calculator embed"
|
|
37
|
+
/>
|
|
38
|
+
</a>
|
|
39
|
+
</td>
|
|
40
|
+
</tr>
|
|
41
|
+
</table>
|
|
21
42
|
|
|
22
|
-
|
|
43
|
+
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.
|
|
23
44
|
|
|
24
45
|
|
|
25
46
|
## Requirements
|
|
26
47
|
|
|
27
48
|
- Desmos API v1.12
|
|
28
49
|
- Desmost only works **in the browser**, because the Desmos API can only be included via a `<script>` tag
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Compile
|
|
55
|
+
```ts
|
|
56
|
+
import { compile } from "desmost";
|
|
57
|
+
|
|
58
|
+
let calc = Desmos.GraphingCalculator(...);
|
|
59
|
+
compile(calc, "f(x) = x^2");
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Pass in [options](https://github.com/Sup2point0/desmost/blob/main/docs/compiling/compiler-options.md) to customise compilation:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
compile(calc, "/text{ sup world! }", {
|
|
66
|
+
errors: "crash",
|
|
67
|
+
ignore_blank_lines: true,
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Render
|
|
72
|
+
Left up to you, in your framework of choice!
|
|
73
|
+
|
|
74
|
+
But if you enjoy nice things, Desmost provides a [Svelte<sup>↗</sup>](https://svelte.dev) component for mass-compiling Desmost, intended to be used in conjunction with [MDsveX<sup>↗</sup>](https://mdsvex.pngwn.io/):
|
|
75
|
+
|
|
76
|
+
```svelte
|
|
77
|
+
<script>
|
|
78
|
+
import Content from "./intro.md";
|
|
79
|
+
import { Desmost } from "desmost/svelte";
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<Desmost>
|
|
83
|
+
<Content />
|
|
84
|
+
</Desmost>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This will replace all ` ```desmos ` blocks from your Markdown source with Desmos calculator embeds.
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
<br>
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
<a href="https://brainmade.org">
|
|
94
|
+
<img align="right" height="80" src=".github/brainmade-black.svg" />
|
|
95
|
+
</a>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DesmostOptions } from "
|
|
1
|
+
import { type DesmostOptions } from "../options.js";
|
|
2
2
|
import { Ast } from "../parser/index.js";
|
|
3
3
|
/** Debug diagnostics returned from `compile()`. */
|
|
4
4
|
export interface DesmostDebug {
|
|
@@ -28,6 +28,10 @@ export declare function compile(
|
|
|
28
28
|
desmos: Desmos.Calculator,
|
|
29
29
|
/** The Desmost source code to compile. */
|
|
30
30
|
source: string,
|
|
31
|
-
/**
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Compilation options.
|
|
33
|
+
*
|
|
34
|
+
* See {@linkcode DesmostOptions} for the options available.
|
|
35
|
+
*/
|
|
36
|
+
options?: Partial<DesmostOptions>): void | DesmostDebug;
|
|
33
37
|
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -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":"AAEA,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,YAAY,CAAC;AAChE,OAAO,EAAiB,GAAG,EAAE,MAAM,WAAW,CAAC;AAG/C,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAE5B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,GAAG,EAAE,CAAC;CACX;AAGD;;;;;;;;;;;;;;;;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,CAkHrB"}
|
package/dist/compiler/compile.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { fill_defaults } from "./options.js";
|
|
2
1
|
import { evaluate_global_incantation, evaluate_expr, evaluate_error } from "./evaluate.js";
|
|
2
|
+
import { fill_defaults } from "../options.js";
|
|
3
3
|
import { DesmostParser, Ast } from "../parser/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Compile Desmost into Desmos.
|
|
@@ -23,7 +23,11 @@ export function compile(
|
|
|
23
23
|
desmos,
|
|
24
24
|
/** The Desmost source code to compile. */
|
|
25
25
|
source,
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Compilation options.
|
|
28
|
+
*
|
|
29
|
+
* See {@linkcode DesmostOptions} for the options available.
|
|
30
|
+
*/
|
|
27
31
|
options) {
|
|
28
32
|
if (desmos == undefined) {
|
|
29
33
|
console.error(`Desmost: No \`Desmos.Calculator\` instance provided, aborting compilation!`);
|
|
@@ -67,7 +71,7 @@ options) {
|
|
|
67
71
|
defer = evaluate_global_incantation(r, desmos, opts);
|
|
68
72
|
break;
|
|
69
73
|
case Ast.Kind.EXPRESSION:
|
|
70
|
-
// @ts-expect-error:
|
|
74
|
+
// @ts-expect-error: check type-narrows
|
|
71
75
|
if (r.data.latex === " ") {
|
|
72
76
|
if (opts.ignore_all_blanks)
|
|
73
77
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA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ptions } from "../options.js";
|
|
2
2
|
import { Ast } from "../parser/index.js";
|
|
3
3
|
import { UnrecoverableError, type Unrecoverable } from "../errors.js";
|
|
4
4
|
/**
|
|
5
5
|
* Evaluate arguments (if any) to a global incantation `invocation`, then apply the incantation to `desmos`.
|
|
6
6
|
*/
|
|
7
|
-
export declare function evaluate_global_incantation(invocation: Ast.IncantationInvocation, desmos: Desmos.Calculator, options:
|
|
7
|
+
export declare function evaluate_global_incantation(invocation: Ast.IncantationInvocation, desmos: Desmos.Calculator, options: DesmostOptions): Unrecoverable<void | string>;
|
|
8
8
|
/**
|
|
9
|
-
* Evaluate
|
|
9
|
+
* Evaluate local incantation invocations on `expr`, then add `expr` to `desmos`.
|
|
10
10
|
*/
|
|
11
|
-
export declare function evaluate_expr(expr: Ast.Expression, desmos: Desmos.Calculator, options:
|
|
11
|
+
export declare function evaluate_expr(expr: Ast.Expression, desmos: Desmos.Calculator, options: DesmostOptions): Unrecoverable<void | string>;
|
|
12
12
|
/**
|
|
13
13
|
* Handle an `InvalidInvocation`, respecting the user's preferences in `options`.
|
|
14
14
|
*
|
|
15
15
|
* If the user set `place_errors: start` or `place_errors: end`, this returns the formatted error message for deferred aggregation.
|
|
16
16
|
*/
|
|
17
|
-
export declare function evaluate_error(error: UnrecoverableError, desmos: Desmos.Calculator, options:
|
|
17
|
+
export declare function evaluate_error(error: UnrecoverableError, desmos: Desmos.Calculator, options: DesmostOptions): Unrecoverable<void | string>;
|
|
18
18
|
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/compiler/evaluate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/compiler/evaluate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAInE;;GAEG;AACH,wBAAgB,2BAA2B,CAC1C,UAAU,EAAE,GAAG,CAAC,qBAAqB,EACrC,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,cAAc,GACrB,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CAe9B;AAGD;;GAEG;AACH,wBAAgB,aAAa,CAC5B,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,cAAc,GACrB,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CAkD9B;AAGD;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,cAAc,GACrB,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CAuB9B"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import dedent from "dedent";
|
|
1
2
|
import { format_error, normalise_latex, prettify_latex } from "./format.js";
|
|
2
3
|
import { Ast } from "../parser/index.js";
|
|
3
4
|
import { UnrecoverableError } from "../errors.js";
|
|
5
|
+
import { is_latex } from "../desmos.js";
|
|
4
6
|
/**
|
|
5
7
|
* Evaluate arguments (if any) to a global incantation `invocation`, then apply the incantation to `desmos`.
|
|
6
8
|
*/
|
|
@@ -8,7 +10,7 @@ export function evaluate_global_incantation(invocation, desmos, options) {
|
|
|
8
10
|
let data = undefined;
|
|
9
11
|
if ("arg_raw" in invocation && invocation.arg_raw != undefined) {
|
|
10
12
|
try {
|
|
11
|
-
data = invocation.incantation.evaluate_arg(invocation.arg_raw);
|
|
13
|
+
data = invocation.incantation.evaluate_arg(invocation.arg_raw, options);
|
|
12
14
|
}
|
|
13
15
|
catch (e) {
|
|
14
16
|
let msg = evaluate_error(e, desmos, options);
|
|
@@ -18,7 +20,7 @@ export function evaluate_global_incantation(invocation, desmos, options) {
|
|
|
18
20
|
invocation.incantation.apply(desmos, data);
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
|
-
* Evaluate
|
|
23
|
+
* Evaluate local incantation invocations on `expr`, then add `expr` to `desmos`.
|
|
22
24
|
*/
|
|
23
25
|
export function evaluate_expr(expr, desmos, options) {
|
|
24
26
|
let errors = [];
|
|
@@ -33,28 +35,34 @@ export function evaluate_expr(expr, desmos, options) {
|
|
|
33
35
|
let data = undefined;
|
|
34
36
|
if ("arg_raw" in invocation && invocation.arg_raw != undefined) {
|
|
35
37
|
try {
|
|
36
|
-
data = invocation.incantation.evaluate_arg(invocation.arg_raw);
|
|
38
|
+
data = invocation.incantation.evaluate_arg(invocation.arg_raw, options);
|
|
37
39
|
}
|
|
38
40
|
catch (e) {
|
|
39
41
|
errors.push(format_error(e, options));
|
|
42
|
+
// if it needs the arg, then we can't press on
|
|
40
43
|
if (invocation.incantation.requires_arg)
|
|
41
44
|
continue;
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
|
-
|
|
47
|
+
try {
|
|
48
|
+
invocation.incantation.apply(expr.data, data);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
errors.push(format_error(e, options));
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
54
|
if (errors.length > 0) {
|
|
47
55
|
desmos.setExpression({ type: "text", text: errors.join("\n\n") });
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
if (expr.data.latex != undefined) {
|
|
51
|
-
// @ts-expect-error: outdated types
|
|
57
|
+
if (is_latex(expr.data)) {
|
|
52
58
|
expr.data.latex = normalise_latex(expr.data.latex);
|
|
53
59
|
if (options.prettify) {
|
|
54
|
-
// @ts-expect-error: outdated types
|
|
55
60
|
expr.data.latex = prettify_latex(expr.data.latex);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
63
|
+
else if (expr.data.type === "text" && options.dedent_text) {
|
|
64
|
+
expr.data.text = dedent(expr.data.text ?? "");
|
|
65
|
+
}
|
|
58
66
|
desmos.setExpression(expr.data);
|
|
59
67
|
}
|
|
60
68
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../src/compiler/evaluate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAGzE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAsB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../src/compiler/evaluate.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAGzE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAsB,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAC1C,UAAqC,EACrC,MAAyB,EACzB,OAAuB;IAGvB,IAAI,IAAI,GAAG,SAAS,CAAC;IAErB,IAAI,SAAS,IAAI,UAAU,IAAI,UAAU,CAAC,OAAO,IAAI,SAAS,EAAE,CAAC;QAChE,IAAI,CAAC;YACJ,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACV,IAAI,GAAG,GAAG,cAAc,CAAC,CAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACtD,OAAO,GAAG,CAAC;QACZ,CAAC;IACF,CAAC;IAED,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,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CAAC;oBACpB,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC;iBAClC,CAAC,CAAC;gBACH,MAAM;QACR,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { DesmostOptions } from "
|
|
1
|
+
import type { DesmostOptions } from "../options.js";
|
|
2
2
|
import { UnrecoverableError } from "../errors.js";
|
|
3
|
-
export declare function format_error(e: UnrecoverableError, options:
|
|
3
|
+
export declare function format_error(e: UnrecoverableError, 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,
|
|
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,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAI/C,wBAAgB,YAAY,CAC3B,CAAC,EAAE,kBAAkB,EACrB,OAAO,EAAE,cAAc,GACrB,MAAM,CAiBR;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,9 +1,20 @@
|
|
|
1
1
|
import { UnrecoverableError } from "../errors.js";
|
|
2
|
+
import { LINE } from "../utils.js";
|
|
2
3
|
export function format_error(e, options) {
|
|
3
4
|
let prefix = options.error_prefix;
|
|
4
5
|
let sep = (prefix === "" || prefix.endsWith("\n")) ? "" : " ";
|
|
5
|
-
return `${prefix}${sep}${e.name}: ${e.message}`;
|
|
6
6
|
// TODO maybe include stack? (configurable?)
|
|
7
|
+
let display = `${prefix}${sep}${e.name}: ${e.message}`;
|
|
8
|
+
if (e.info != undefined && options.expand_errors) {
|
|
9
|
+
display += `\n${LINE}`;
|
|
10
|
+
if (e.info.hint != undefined)
|
|
11
|
+
display += `\nHint: ${e.info.hint}`;
|
|
12
|
+
if (e.info.note != undefined)
|
|
13
|
+
display += `\n${LINE}\nNote: ${e.info.note}`;
|
|
14
|
+
if (e.info.flagged_by != undefined)
|
|
15
|
+
display += `\n${LINE}\nFlagged by: \`${e.info.flagged_by}\``;
|
|
16
|
+
}
|
|
17
|
+
return display;
|
|
7
18
|
}
|
|
8
19
|
/**
|
|
9
20
|
* Remove line breaks from `latex` so Desmos can properly consume it.
|
|
@@ -22,7 +33,9 @@ export function normalise_latex(latex) {
|
|
|
22
33
|
*/
|
|
23
34
|
export function prettify_latex(latex) {
|
|
24
35
|
latex = latex.replaceAll(/(?<!\\left)(\(|\[|\\\{)/g, "\\left$1");
|
|
36
|
+
latex = latex.replaceAll(/(?:\\left\s?)+/g, "\\left");
|
|
25
37
|
latex = latex.replaceAll(/(?<!\\right)(\)|\]|\\\})/g, "\\right$1");
|
|
38
|
+
latex = latex.replaceAll(/(?:\\right\s?)+/g, "\\right");
|
|
26
39
|
latex = latex.replaceAll(/(:|,)(?!\\ ) */g, "$1\\ ");
|
|
27
40
|
latex = latex.replaceAll(/(?<=[^\w]|^)\\?(length|mean|median|count|total|repeat|join|sort|shuffle|unique|mod|ceil|floor|round|sign) ?(?=\(|\\left\()/g, "\\operatorname{$1}");
|
|
28
41
|
latex = latex.replaceAll(/\s(and|or)\s/g, "\\operatorname{$1}");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/compiler/format.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM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AAG,CAAC,CAAC;IACtC,OAAO,KAAK,CAAC;AACd,CAAC;AAGD;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAE3C,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,0BAA0B,EAAE,UAAU,CAAC,CAAC;IACjE,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IACtD,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAC;IACnE,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;IACxD,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;IAErD,KAAK,GAAG,KAAK,CAAC,UAAU,CACvB,6HAA6H,EAC7H,oBAAoB,CACpB,CAAC;IAEF,KAAK,GAAG,KAAK,CAAC,UAAU,CACvB,eAAe,EACf,oBAAoB,CACpB,CAAC;IAEF,OAAO,KAAK,CAAC;AACd,CAAC"}
|
package/dist/compiler/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Ast } from "../parser/index.js";
|
|
2
|
+
import type { DesmostOptions } from "../compiler/index.js";
|
|
2
3
|
export interface SemiStructuredAst {
|
|
3
4
|
globals: Ast.IncantationInvocation[];
|
|
4
5
|
locals: Ast.Expression[];
|
|
@@ -8,7 +9,17 @@ export interface SemiStructuredAst {
|
|
|
8
9
|
*
|
|
9
10
|
* The caller must also supply a `blank` calculator instance. This is used as a reference for default field values, so that emitted incantations like `/desmos{}` don't get filled with a huge amount of noise.
|
|
10
11
|
*/
|
|
11
|
-
export declare function decompile(
|
|
12
|
+
export declare function decompile(
|
|
13
|
+
/** The Desmos calculator instance to decompile. */
|
|
14
|
+
desmos: Desmos.Calculator,
|
|
15
|
+
/**
|
|
16
|
+
* The default blank Desmos calculator instance to use as a baseline.
|
|
17
|
+
*
|
|
18
|
+
* It is **highly recommended** to include this, otherwise your decompiled source will have a bunch of unnecessary incantations!
|
|
19
|
+
*
|
|
20
|
+
* This is used in deciding what settings are noise that can be omitted. For instance, most of your calculator settings are probably set to their default values, so there's no need to include *every single one of them* in `/desmos{}`.
|
|
21
|
+
*/
|
|
22
|
+
blank?: Desmos.Calculator, options?: Partial<DesmostOptions>): string;
|
|
12
23
|
/**
|
|
13
24
|
* Decompile `desmos` into a semi-structured AST.
|
|
14
25
|
*/
|
|
@@ -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;
|
|
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,aAAa,CAAC;AAGlD,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"}
|
|
@@ -6,8 +6,20 @@ import { Ast } from "../parser/index.js";
|
|
|
6
6
|
*
|
|
7
7
|
* The caller must also supply a `blank` calculator instance. This is used as a reference for default field values, so that emitted incantations like `/desmos{}` don't get filled with a huge amount of noise.
|
|
8
8
|
*/
|
|
9
|
-
export function decompile(
|
|
10
|
-
|
|
9
|
+
export function decompile(
|
|
10
|
+
/** The Desmos calculator instance to decompile. */
|
|
11
|
+
desmos,
|
|
12
|
+
/**
|
|
13
|
+
* The default blank Desmos calculator instance to use as a baseline.
|
|
14
|
+
*
|
|
15
|
+
* It is **highly recommended** to include this, otherwise your decompiled source will have a bunch of unnecessary incantations!
|
|
16
|
+
*
|
|
17
|
+
* This is used in deciding what settings are noise that can be omitted. For instance, most of your calculator settings are probably set to their default values, so there's no need to include *every single one of them* in `/desmos{}`.
|
|
18
|
+
*/
|
|
19
|
+
blank,
|
|
20
|
+
// TODO doc
|
|
21
|
+
options) {
|
|
22
|
+
return ast_to_source(desmos_to_ast(desmos, blank ?? desmos));
|
|
11
23
|
}
|
|
12
24
|
/**
|
|
13
25
|
* Decompile `desmos` into a semi-structured AST.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompile.js","sourceRoot":"","sources":["../../src/decompiler/decompile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEnF,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"decompile.js","sourceRoot":"","sources":["../../src/decompiler/decompile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEnF,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAWhC;;;;GAIG;AACH,MAAM,UAAU,SAAS;AACxB,mDAAmD;AACnD,MAAyB;AAEzB;;;;;;GAMG;AACH,KAAyB;AAEzB,WAAW;AACX,OAAiC;IAGjC,OAAO,aAAa,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAyB,EAAE,KAAwB;IAEhF,OAAO;QACN,OAAO,EAAE;YACR,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC;YAC/B,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC;SAC/B,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC;QACxB,MAAM,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC;KACvD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,GAAsB;IAEnD,OAAO,CACF,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;UACjD,MAAM;UACN,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAChD,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/decompiler/emit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGrC;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,qBAAqB,GAAG,MAAM,CAQtF;AAGD;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,UAAU,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/decompiler/emit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGrC;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,qBAAqB,GAAG,MAAM,CAQtF;AAGD;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,UAAU,GAAG,MAAM,CAmC7D"}
|
package/dist/decompiler/emit.js
CHANGED
|
@@ -20,16 +20,23 @@ export function emit_expression(expr) {
|
|
|
20
20
|
let content;
|
|
21
21
|
switch (expr.data.type) {
|
|
22
22
|
case "text":
|
|
23
|
-
|
|
23
|
+
expr.data.text ??= "";
|
|
24
|
+
if (expr.data.text.includes("\n")) {
|
|
25
|
+
content = `/text{\n${expr.data.text}\n}`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
content = `% ${expr.data.text}`;
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
case "table":
|
|
32
|
+
content = "[tables are currently unsupported]";
|
|
24
33
|
break;
|
|
25
34
|
default:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
content = "";
|
|
35
|
+
if (expr.data.latex?.trim() !== "") {
|
|
36
|
+
content = expr.data.latex ?? "[unsupported]";
|
|
29
37
|
}
|
|
30
38
|
else {
|
|
31
|
-
|
|
32
|
-
content = expr.data.latex ?? "?";
|
|
39
|
+
content = "";
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
return `${locals.join(" ")}${sep}${content}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/decompiler/emit.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,UAAsC;IAE7E,IAAI,UAAU,IAAI,SAAS;QAAE,OAAO,EAAE,CAAC;IAErC,IAAI,KAAK,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC;IAC9C,IAAI,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IAEjC,OAAO,IAAI,KAAK,QAAQ,OAAO,KAAK,CAAC;AACxC,CAAC;AAGD;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAqB;IAEpD,IAAI,IAAI,IAAI,SAAS;QAAE,OAAO,EAAE,CAAC;IAEjC,OAAO;IACL,IAAI,MAAM,GAAa,EAAE,CAAC;IAE1B,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAErD,IAAI,OAAO,CAAC;IAEZ,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,MAAM;YACR,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/decompiler/emit.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,UAAsC;IAE7E,IAAI,UAAU,IAAI,SAAS;QAAE,OAAO,EAAE,CAAC;IAErC,IAAI,KAAK,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC;IAC9C,IAAI,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IAEjC,OAAO,IAAI,KAAK,QAAQ,OAAO,KAAK,CAAC;AACxC,CAAC;AAGD;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAqB;IAEpD,IAAI,IAAI,IAAI,SAAS;QAAE,OAAO,EAAE,CAAC;IAEjC,OAAO;IACL,IAAI,MAAM,GAAa,EAAE,CAAC;IAE1B,IAAI,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAErD,IAAI,OAAO,CAAC;IAEZ,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,MAAM;YACR,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC;YAEtB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjC,OAAO,GAAG,WAAW,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC;YAC5C,CAAC;iBAAM,CAAC;gBACL,OAAO,GAAG,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACnC,CAAC;YACD,MAAM;QAET,KAAK,OAAO;YACT,OAAO,GAAG,oCAAoC,CAAC;YAC/C,MAAM;QAET;YACG,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;gBAClC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,eAAe,CAAC;YAChD,CAAC;iBAAM,CAAC;gBACL,OAAO,GAAG,EAAE,CAAC;YAChB,CAAC;IACP,CAAC;IAED,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,OAAO,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -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;
|
|
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,CAuBlC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC7B,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,KAAK,EAAE,MAAM,CAAC,UAAU,GACxB,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAkBlC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,eAAe,GAAG,GAAG,CAAC,UAAU,CAuBrF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { stringify_json5, prettify_source } from "./format.js";
|
|
2
2
|
import { Ast } from "../parser/index.js";
|
|
3
|
+
import { is_latex } from "../desmos.js";
|
|
3
4
|
import { DesmosIncantation, ViewportIncantation } from "../magic/global/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* Extract a `/desmos` incantation from the settings of `desmos`.
|
|
@@ -39,7 +40,7 @@ export function extract_viewport(desmos, blank) {
|
|
|
39
40
|
*/
|
|
40
41
|
export function extract_expression(expression) {
|
|
41
42
|
let data;
|
|
42
|
-
// @ts-expect-error:
|
|
43
|
+
// @ts-expect-error: check type-narrows
|
|
43
44
|
if (expression.latex?.trim() === "") {
|
|
44
45
|
data = { latex: ` ` };
|
|
45
46
|
}
|
|
@@ -47,7 +48,7 @@ export function extract_expression(expression) {
|
|
|
47
48
|
data = Object.fromEntries(Object.entries(expression)
|
|
48
49
|
.filter(([key, value]) => !is_insignificant(key, value)));
|
|
49
50
|
}
|
|
50
|
-
if (
|
|
51
|
+
if (is_latex(expression)) {
|
|
51
52
|
data.latex = prettify_source(data.latex);
|
|
52
53
|
}
|
|
53
54
|
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;
|
|
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,WAAW,CAAC;AAErC,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,CACJ,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC;WACjB,CAAC,KAAK,aAAa;WACnB,CAAC,KAAK,MAAM;WACZ,CAAC,KAAK,YAAY;WAClB,CAAC,KAAK,QAAQ,CACnB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EACjB,IAAI,CACN,CAAC;IAEF,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAEzC,OAAO;QACN,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB;QACrC,WAAW,EAAE,IAAI,iBAAiB,EAAE;QACpC,OAAO;KACP,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC7B,MAAyB,EACzB,KAAwB;IAGxB,IAAI,QAAQ,GAAG,KAAK,CAAC,gBAAg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CAAC,UAAU;QACzB,IAAI;QACJ,YAAY,EAAE,EAAE,EAAG,OAAO;KAC1B,CAAC;AACH,CAAC;AAGD,SAAS,gBAAgB,CAAC,GAAW,EAAE,KAAU;IAE9C,OAAO,CACD,KAAK,KAAK,EAAE;WACZ,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAC3E,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/decompiler/format.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAA4B,CACrD,IAAI,EAAE,QAAQ,EAAE,KAAK,EACtB,EAAE;IAED,OAAO;IACJ,
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/decompiler/format.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAA4B,CACrD,IAAI,EAAE,QAAQ,EAAE,KAAK,EACtB,EAAE;IAED,OAAO;IACJ,oCAAoC;IACpC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC;SACpC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,uBAAuB;SACrC,IAAI,EAAE;SACN,UAAU,CAAC,aAAa,EAAE,KAAK,CAAC,CAAE,iCAAiC;KACtE,CAAC;AACL,CAAC,CAAA;AAGD,MAAM,UAAU,eAAe,CAAC,MAAc;IAE3C,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IAEzD,OAAO,MAAM,CAAC;AACjB,CAAC"}
|
package/dist/desmos.d.ts
CHANGED
|
@@ -9,4 +9,8 @@ export declare enum DesmosColour {
|
|
|
9
9
|
ORANGE = "#fa7e19",
|
|
10
10
|
BLACK = "#000000"
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Is `expr` a Desmos LaTeX expression (as opposed to a note or table)?
|
|
14
|
+
*/
|
|
15
|
+
export declare function is_latex(expr: Desmos.ExpressionState): expr is Desmos.Expression;
|
|
12
16
|
//# sourceMappingURL=desmos.d.ts.map
|
package/dist/desmos.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"desmos.d.ts","sourceRoot":"","sources":["../src/desmos.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,YAAY;IAEvB,GAAG,YAAe;IAClB,IAAI,YAAc;IAClB,KAAK,YAAa;IAClB,MAAM,YAAY;IAClB,MAAM,YAAY;IAClB,KAAK,YAAa;CAClB"}
|
|
1
|
+
{"version":3,"file":"desmos.d.ts","sourceRoot":"","sources":["../src/desmos.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,YAAY;IAEvB,GAAG,YAAe;IAClB,IAAI,YAAc;IAClB,KAAK,YAAa;IAClB,MAAM,YAAY;IAClB,MAAM,YAAY;IAClB,KAAK,YAAa;CAClB;AAGD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,eAAe,GAAG,IAAI,IAAI,MAAM,CAAC,UAAU,CAGhF"}
|
package/dist/desmos.js
CHANGED
|
@@ -10,4 +10,10 @@ export var DesmosColour;
|
|
|
10
10
|
DesmosColour["ORANGE"] = "#fa7e19";
|
|
11
11
|
DesmosColour["BLACK"] = "#000000";
|
|
12
12
|
})(DesmosColour || (DesmosColour = {}));
|
|
13
|
+
/**
|
|
14
|
+
* Is `expr` a Desmos LaTeX expression (as opposed to a note or table)?
|
|
15
|
+
*/
|
|
16
|
+
export function is_latex(expr) {
|
|
17
|
+
return (expr.type === undefined || expr.type === "expression");
|
|
18
|
+
}
|
|
13
19
|
//# sourceMappingURL=desmos.js.map
|
package/dist/desmos.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"desmos.js","sourceRoot":"","sources":["../src/desmos.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAN,IAAY,YAQX;AARD,WAAY,YAAY;IAEvB,+BAAkB,CAAA;IAClB,gCAAkB,CAAA;IAClB,iCAAkB,CAAA;IAClB,kCAAkB,CAAA;IAClB,kCAAkB,CAAA;IAClB,iCAAkB,CAAA;AACnB,CAAC,EARW,YAAY,KAAZ,YAAY,QAQvB"}
|
|
1
|
+
{"version":3,"file":"desmos.js","sourceRoot":"","sources":["../src/desmos.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAN,IAAY,YAQX;AARD,WAAY,YAAY;IAEvB,+BAAkB,CAAA;IAClB,gCAAkB,CAAA;IAClB,iCAAkB,CAAA;IAClB,kCAAkB,CAAA;IAClB,kCAAkB,CAAA;IAClB,iCAAkB,CAAA;AACnB,CAAC,EARW,YAAY,KAAZ,YAAY,QAQvB;AAGD;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,IAA4B;IAEpD,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -10,25 +10,43 @@ export type NoMatch = typeof NO_MATCH & {
|
|
|
10
10
|
* It's not *literally* unrecoverable in the sense that it will crash the compiler completely, but it means there are no further fallbacks to try.
|
|
11
11
|
*/
|
|
12
12
|
export declare class UnrecoverableError extends Error {
|
|
13
|
+
info?: UnrecoverableError.Info;
|
|
13
14
|
}
|
|
14
15
|
export declare namespace UnrecoverableError {
|
|
16
|
+
interface Info {
|
|
17
|
+
hint?: string;
|
|
18
|
+
note?: string;
|
|
19
|
+
flagged_by?: string;
|
|
20
|
+
}
|
|
15
21
|
/** The parser unexpectedly reached the end of its entire input source code. */
|
|
16
22
|
class UnexpectedEnd extends UnrecoverableError {
|
|
23
|
+
info?: Info | undefined;
|
|
24
|
+
constructor(msg: string, info?: Info | undefined);
|
|
17
25
|
}
|
|
18
26
|
/** The parser did not receive input that it expected. */
|
|
19
27
|
class MissingInput extends UnrecoverableError {
|
|
28
|
+
info?: Info | undefined;
|
|
29
|
+
constructor(msg: string, info?: Info | undefined);
|
|
20
30
|
}
|
|
21
31
|
/** The parser received input that did not match what it expected. */
|
|
22
32
|
class UnexpectedInput extends UnrecoverableError {
|
|
33
|
+
info?: Info | undefined;
|
|
34
|
+
constructor(msg: string, info?: Info | undefined);
|
|
23
35
|
}
|
|
24
36
|
/** The parser received excess input that it did not expect. */
|
|
25
37
|
class ExcessInput extends UnrecoverableError {
|
|
38
|
+
info?: Info | undefined;
|
|
39
|
+
constructor(msg: string, info?: Info | undefined);
|
|
26
40
|
}
|
|
27
41
|
/** An incantation can't be applied here. */
|
|
28
42
|
class IllegalIncantation extends UnrecoverableError {
|
|
43
|
+
info?: Info | undefined;
|
|
44
|
+
constructor(msg: string, info?: Info | undefined);
|
|
29
45
|
}
|
|
30
46
|
/** An incantation's argument couldn't be parsed. */
|
|
31
47
|
class InvalidArgument extends UnrecoverableError {
|
|
48
|
+
info?: Info | undefined;
|
|
49
|
+
constructor(msg: string, info?: Info | undefined);
|
|
32
50
|
}
|
|
33
51
|
}
|
|
34
52
|
/** Indicates that a function may throw an `UnrecoverableError`. */
|