desmost 0.4.0 → 0.4.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/dist/compiler/compile.d.ts +2 -2
- package/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js +5 -2
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/options.d.ts +1 -1
- package/dist/compiler/options.d.ts.map +1 -1
- package/dist/compiler/options.js +11 -11
- package/dist/compiler/options.js.map +1 -1
- package/dist/index.internal.d.ts +1 -0
- package/dist/index.internal.d.ts.map +1 -1
- package/dist/index.internal.js.map +1 -1
- package/package.json +5 -4
- package/src/compiler/compile.ts +8 -3
- package/src/compiler/options.ts +11 -11
- package/src/index.internal.ts +1 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type DesmostOptions } from "./options.js";
|
|
2
2
|
import { Ast } from "../parser/index.js";
|
|
3
3
|
export declare function compile(desmos: Desmos.Calculator, source: string, options?: DesmostOptions): void | DesmostDebug;
|
|
4
|
-
interface DesmostDebug {
|
|
4
|
+
export interface DesmostDebug {
|
|
5
5
|
duration: number;
|
|
6
|
+
num_blocks: number;
|
|
6
7
|
ast: Ast[];
|
|
7
8
|
}
|
|
8
|
-
export {};
|
|
9
9
|
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAiB,GAAG,EAAE,MAAM,WAAW,CAAC;AAqB/C,wBAAgB,OAAO,CAErB,MAAM,EAAE,MAAM,CAAC,UAAU,EAGzB,MAAM,EAAE,MAAM,EAGd,OAAO,CAAC,EAAE,cAAc,GACvB,IAAI,GAAG,YAAY,CA4FrB;AAGD,MAAM,WAAW,YAAY;IAE3B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,GAAG,EAAE,CAAC;CACZ"}
|
package/dist/compiler/compile.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fill_defaults } from "./options.js";
|
|
2
2
|
import { evaluate_global_incantation, evaluate_expr, evaluate_error } from "./evaluate.js";
|
|
3
3
|
import { DesmostParser, Ast } from "../parser/index.js";
|
|
4
4
|
import { UnrecoverableError } from "../errors.js";
|
|
@@ -12,8 +12,9 @@ export function compile(desmos, source, options) {
|
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
let t_init = performance.now();
|
|
15
|
+
let num_blocks = 0;
|
|
15
16
|
let ast = [];
|
|
16
|
-
let opts =
|
|
17
|
+
let opts = fill_defaults(options);
|
|
17
18
|
let parser = new DesmostParser(source, opts);
|
|
18
19
|
if (opts.place_errors === "start") {
|
|
19
20
|
desmos.setExpression({ id: "deferred-start", latex: "" });
|
|
@@ -25,6 +26,7 @@ export function compile(desmos, source, options) {
|
|
|
25
26
|
if (r === null)
|
|
26
27
|
break;
|
|
27
28
|
if (opts.debug) {
|
|
29
|
+
num_blocks++;
|
|
28
30
|
ast.push(r);
|
|
29
31
|
}
|
|
30
32
|
let defer = undefined;
|
|
@@ -72,6 +74,7 @@ export function compile(desmos, source, options) {
|
|
|
72
74
|
if (opts.debug) {
|
|
73
75
|
return {
|
|
74
76
|
duration: performance.now() - t_init,
|
|
77
|
+
num_blocks,
|
|
75
78
|
ast,
|
|
76
79
|
};
|
|
77
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,
|
|
1
|
+
{"version":3,"file":"compile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M,CAAC,aAAa,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;gBACxD,MAAM;YACR,KAAK,KAAK,CAAC;YACX,KAAK,QAAQ;gBACX,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;gBAC3B,MAAM;QACV,CAAC;IACH,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,OAAO;YACL,QAAQ,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,MAAM;YACpC,UAAU;YACV,GAAG;SACJ,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -8,5 +8,5 @@ export interface DesmostOptions {
|
|
|
8
8
|
prettify?: boolean;
|
|
9
9
|
debug?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function fill_defaults(options: Partial<DesmostOptions> | undefined): Required<DesmostOptions>;
|
|
12
12
|
//# sourceMappingURL=options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/compiler/options.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,cAAc;IAS7B,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;IASzC,YAAY,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAA;IASzC,YAAY,CAAC,EAAE,MAAM,CAAA;IAOrB,eAAe,CAAC,EAAE,OAAO,CAAA;IAOzB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAO5B,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAOhC,QAAQ,CAAC,EAAE,OAAO,CAAA;IASlB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAMD,wBAAgB,
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/compiler/options.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,cAAc;IAS7B,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;IASzC,YAAY,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAA;IASzC,YAAY,CAAC,EAAE,MAAM,CAAA;IAOrB,eAAe,CAAC,EAAE,OAAO,CAAA;IAOzB,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAO5B,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAOhC,QAAQ,CAAC,EAAE,OAAO,CAAA;IASlB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAMD,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,CAgBpG"}
|
package/dist/compiler/options.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
1
|
+
export function fill_defaults(options) {
|
|
2
|
+
let out = Object.assign({}, options);
|
|
3
|
+
out.errors ??= "surface";
|
|
4
|
+
out.place_errors ??= "inline";
|
|
5
|
+
out.error_prefix ??= "[DESMOST ERROR]\n";
|
|
6
|
+
out.ignore_comments ??= false;
|
|
7
|
+
out.ignore_blank_lines ??= false;
|
|
8
|
+
out.ignore_trailing_blanks ??= false;
|
|
9
|
+
out.prettify ??= true;
|
|
10
|
+
out.debug ??= false;
|
|
11
|
+
return out;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/compiler/options.ts"],"names":[],"mappings":"AAgFA,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/compiler/options.ts"],"names":[],"mappings":"AAgFA,MAAM,UAAU,aAAa,CAAC,OAA4C;IAExE,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAErC,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC;IACzB,GAAG,CAAC,YAAY,KAAK,QAAQ,CAAC;IAC9B,GAAG,CAAC,YAAY,KAAK,mBAAmB,CAAC;IAEzC,GAAG,CAAC,eAAe,KAAK,KAAK,CAAC;IAC9B,GAAG,CAAC,kBAAkB,KAAK,KAAK,CAAC;IACjC,GAAG,CAAC,sBAAsB,KAAK,KAAK,CAAC;IAErC,GAAG,CAAC,QAAQ,KAAK,IAAI,CAAC;IACtB,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC;IAEpB,OAAO,GAA+B,CAAC;AACzC,CAAC"}
|
package/dist/index.internal.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.internal.d.ts","sourceRoot":"","sources":["../src/index.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.internal.d.ts","sourceRoot":"","sources":["../src/index.internal.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.internal.js","sourceRoot":"","sources":["../src/index.internal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.internal.js","sourceRoot":"","sources":["../src/index.internal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "desmost",
|
|
3
3
|
"author": "Sup#2.0",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
|
|
7
7
|
"description": "A tiny DSL for compiling LaTeX to Desmos",
|
|
8
8
|
"keywords": [
|
|
9
|
-
"desmos", "latex", "
|
|
9
|
+
"desmos", "latex", "compiler"
|
|
10
10
|
],
|
|
11
11
|
|
|
12
12
|
"homepage": "https://sup2point0.github.io/desmost",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
|
|
40
|
-
"scripts":
|
|
40
|
+
"scripts":
|
|
41
|
+
{
|
|
41
42
|
"build": "nu build.nu",
|
|
42
43
|
"buildx": "nu build.nu full",
|
|
43
44
|
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
|
|
47
48
|
"check": "npx oxlint src",
|
|
48
49
|
|
|
49
|
-
"prepublishOnly": "npm run buildx"
|
|
50
|
+
"prepublishOnly": "npm run test && npm run buildx"
|
|
50
51
|
},
|
|
51
52
|
|
|
52
53
|
"dependencies":
|
package/src/compiler/compile.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DesmostOptions,
|
|
1
|
+
import { type DesmostOptions, fill_defaults } from "./options";
|
|
2
2
|
import { evaluate_global_incantation, evaluate_expr, evaluate_error } from "./evaluate";
|
|
3
3
|
|
|
4
4
|
import { DesmostParser, Ast } from "../parser";
|
|
@@ -44,9 +44,10 @@ export function compile(
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
let t_init = performance.now();
|
|
47
|
+
let num_blocks = 0;
|
|
47
48
|
let ast = [];
|
|
48
49
|
|
|
49
|
-
let opts =
|
|
50
|
+
let opts = fill_defaults(options);
|
|
50
51
|
let parser = new DesmostParser(source, opts);
|
|
51
52
|
|
|
52
53
|
/* To aggregate errors at the start, we need a target to retroactively inject errors into */
|
|
@@ -56,12 +57,14 @@ export function compile(
|
|
|
56
57
|
|
|
57
58
|
let errors = [];
|
|
58
59
|
|
|
60
|
+
/* NOTE: 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. 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. */
|
|
59
61
|
try {
|
|
60
62
|
while (true) {
|
|
61
63
|
let r = parser.parse_next();
|
|
62
64
|
if (r === null) break;
|
|
63
65
|
|
|
64
66
|
if (opts.debug) {
|
|
67
|
+
num_blocks++;
|
|
65
68
|
ast.push(r);
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -116,14 +119,16 @@ export function compile(
|
|
|
116
119
|
if (opts.debug) {
|
|
117
120
|
return {
|
|
118
121
|
duration: performance.now() - t_init,
|
|
122
|
+
num_blocks,
|
|
119
123
|
ast,
|
|
120
124
|
};
|
|
121
125
|
}
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
|
|
125
|
-
interface DesmostDebug
|
|
129
|
+
export interface DesmostDebug
|
|
126
130
|
{
|
|
127
131
|
duration: number;
|
|
132
|
+
num_blocks: number;
|
|
128
133
|
ast: Ast[];
|
|
129
134
|
}
|
package/src/compiler/options.ts
CHANGED
|
@@ -78,20 +78,20 @@ export interface DesmostOptions
|
|
|
78
78
|
/**
|
|
79
79
|
* Fill in `options` with Desmost's defaults to produce a complete `DesmostOptions` config.
|
|
80
80
|
*/
|
|
81
|
-
export function
|
|
81
|
+
export function fill_defaults(options: Partial<DesmostOptions> | undefined): Required<DesmostOptions>
|
|
82
82
|
{
|
|
83
|
-
|
|
83
|
+
let out = Object.assign({}, options);
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
out.errors ??= "surface";
|
|
86
|
+
out.place_errors ??= "inline";
|
|
87
|
+
out.error_prefix ??= "[DESMOST ERROR]\n";
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
out.ignore_comments ??= false;
|
|
90
|
+
out.ignore_blank_lines ??= false;
|
|
91
|
+
out.ignore_trailing_blanks ??= false;
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
out.prettify ??= true;
|
|
94
|
+
out.debug ??= false;
|
|
95
95
|
|
|
96
|
-
return
|
|
96
|
+
return out as Required<DesmostOptions>;
|
|
97
97
|
}
|
package/src/index.internal.ts
CHANGED