desmost 0.1.0 → 0.1.2
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/LICENCE +21 -0
- package/dist/compiler/compile.d.ts +3 -26
- package/dist/compiler/compile.d.ts.map +1 -1
- package/dist/compiler/compile.js +5 -29
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/evaluate.d.ts +3 -14
- package/dist/compiler/evaluate.d.ts.map +1 -1
- package/dist/compiler/evaluate.js +2 -14
- package/dist/compiler/evaluate.js.map +1 -1
- package/dist/compiler/index.d.ts +2 -2
- package/dist/compiler/index.js +1 -1
- package/dist/compiler/options.d.ts +0 -43
- package/dist/compiler/options.d.ts.map +1 -1
- package/dist/compiler/options.js +0 -3
- package/dist/compiler/options.js.map +1 -1
- package/dist/desmos.d.ts +0 -3
- package/dist/desmos.d.ts.map +1 -1
- package/dist/desmos.js +0 -3
- package/dist/desmos.js.map +1 -1
- package/dist/errors.d.ts +0 -19
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -12
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.internal.d.ts +2 -0
- package/dist/index.internal.d.ts.map +1 -0
- package/dist/index.internal.js +2 -0
- package/dist/index.internal.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/magic/expr/index.d.ts +1 -1
- package/dist/magic/expr/index.js +3 -3
- package/dist/magic/expr/latex.d.ts +1 -1
- package/dist/magic/expr/latex.js +1 -2
- package/dist/magic/expr/latex.js.map +1 -1
- package/dist/magic/expr/text.d.ts +1 -1
- package/dist/magic/expr/text.js +1 -2
- package/dist/magic/expr/text.js.map +1 -1
- package/dist/magic/global/dark-mode.d.ts +1 -1
- package/dist/magic/global/dark-mode.js +1 -1
- package/dist/magic/global/desmos.d.ts +1 -1
- package/dist/magic/global/desmos.js +1 -1
- package/dist/magic/global/index.d.ts +1 -1
- package/dist/magic/global/index.js +4 -4
- package/dist/magic/global/viewport.d.ts +1 -1
- package/dist/magic/global/viewport.js +1 -2
- package/dist/magic/global/viewport.js.map +1 -1
- package/dist/magic/incantation.d.ts +1 -45
- package/dist/magic/incantation.d.ts.map +1 -1
- package/dist/magic/incantation.js +1 -39
- package/dist/magic/incantation.js.map +1 -1
- package/dist/magic/index.d.ts +5 -5
- package/dist/magic/index.js +4 -4
- package/dist/magic/local/anim.d.ts +1 -1
- package/dist/magic/local/anim.js +1 -2
- package/dist/magic/local/anim.js.map +1 -1
- package/dist/magic/local/colour.d.ts +2 -2
- package/dist/magic/local/colour.js +3 -3
- package/dist/magic/local/dashed.d.ts +1 -1
- package/dist/magic/local/dashed.js +1 -1
- package/dist/magic/local/fill.d.ts +1 -1
- package/dist/magic/local/fill.js +1 -1
- package/dist/magic/local/hide.d.ts +1 -1
- package/dist/magic/local/hide.js +1 -1
- package/dist/magic/local/index.d.ts +1 -1
- package/dist/magic/local/index.js +11 -11
- package/dist/magic/local/line.d.ts +1 -1
- package/dist/magic/local/line.js +1 -1
- package/dist/magic/local/no-line.d.ts +1 -1
- package/dist/magic/local/no-line.js +1 -1
- package/dist/magic/local/point.d.ts +1 -1
- package/dist/magic/local/point.js +1 -1
- package/dist/magic/local/secret.d.ts +1 -1
- package/dist/magic/local/secret.js +1 -1
- package/dist/magic/local/slider.d.ts +1 -1
- package/dist/magic/local/slider.js +1 -2
- package/dist/magic/local/slider.js.map +1 -1
- package/dist/parser/ast.d.ts +2 -11
- package/dist/parser/ast.d.ts.map +1 -1
- package/dist/parser/ast.js +2 -3
- package/dist/parser/ast.js.map +1 -1
- package/dist/parser/desmost-parser.d.ts +7 -88
- package/dist/parser/desmost-parser.d.ts.map +1 -1
- package/dist/parser/desmost-parser.js +5 -108
- package/dist/parser/desmost-parser.js.map +1 -1
- package/dist/parser/generic-parser.d.ts +1 -44
- package/dist/parser/generic-parser.d.ts.map +1 -1
- package/dist/parser/generic-parser.js +1 -47
- package/dist/parser/generic-parser.js.map +1 -1
- package/dist/parser/index.d.ts +2 -7
- package/dist/parser/index.d.ts.map +1 -1
- package/dist/parser/index.js +2 -7
- package/dist/parser/index.js.map +1 -1
- package/package.json +14 -8
- package/src/index.internal.ts +1 -0
- package/dist/src/compiler/compile.d.ts +0 -32
- package/dist/src/compiler/compile.d.ts.map +0 -1
- package/dist/src/compiler/compile.js +0 -101
- package/dist/src/compiler/compile.js.map +0 -1
- package/dist/src/compiler/evaluate.d.ts +0 -18
- package/dist/src/compiler/evaluate.d.ts.map +0 -1
- package/dist/src/compiler/evaluate.js +0 -83
- package/dist/src/compiler/evaluate.js.map +0 -1
- package/dist/src/compiler/index.d.ts +0 -3
- package/dist/src/compiler/index.d.ts.map +0 -1
- package/dist/src/compiler/index.js +0 -2
- package/dist/src/compiler/index.js.map +0 -1
- package/dist/src/compiler/options.d.ts +0 -54
- package/dist/src/compiler/options.d.ts.map +0 -1
- package/dist/src/compiler/options.js +0 -15
- package/dist/src/compiler/options.js.map +0 -1
- package/dist/src/desmos.d.ts +0 -12
- package/dist/src/desmos.d.ts.map +0 -1
- package/dist/src/desmos.js +0 -13
- package/dist/src/desmos.js.map +0 -1
- package/dist/src/errors.d.ts +0 -45
- package/dist/src/errors.d.ts.map +0 -1
- package/dist/src/errors.js +0 -38
- package/dist/src/errors.js.map +0 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -2
- package/dist/src/index.js.map +0 -1
- package/dist/src/magic/expr/index.d.ts +0 -3
- package/dist/src/magic/expr/index.d.ts.map +0 -1
- package/dist/src/magic/expr/index.js +0 -8
- package/dist/src/magic/expr/index.js.map +0 -1
- package/dist/src/magic/expr/latex.d.ts +0 -10
- package/dist/src/magic/expr/latex.d.ts.map +0 -1
- package/dist/src/magic/expr/latex.js +0 -16
- package/dist/src/magic/expr/latex.js.map +0 -1
- package/dist/src/magic/expr/text.d.ts +0 -9
- package/dist/src/magic/expr/text.d.ts.map +0 -1
- package/dist/src/magic/expr/text.js +0 -13
- package/dist/src/magic/expr/text.js.map +0 -1
- package/dist/src/magic/global/dark-mode.d.ts +0 -7
- package/dist/src/magic/global/dark-mode.d.ts.map +0 -1
- package/dist/src/magic/global/dark-mode.js +0 -11
- package/dist/src/magic/global/dark-mode.js.map +0 -1
- package/dist/src/magic/global/desmos.d.ts +0 -9
- package/dist/src/magic/global/desmos.d.ts.map +0 -1
- package/dist/src/magic/global/desmos.js +0 -11
- package/dist/src/magic/global/desmos.js.map +0 -1
- package/dist/src/magic/global/index.d.ts +0 -3
- package/dist/src/magic/global/index.d.ts.map +0 -1
- package/dist/src/magic/global/index.js +0 -10
- package/dist/src/magic/global/index.js.map +0 -1
- package/dist/src/magic/global/viewport.d.ts +0 -16
- package/dist/src/magic/global/viewport.d.ts.map +0 -1
- package/dist/src/magic/global/viewport.js +0 -12
- package/dist/src/magic/global/viewport.js.map +0 -1
- package/dist/src/magic/incantation.d.ts +0 -74
- package/dist/src/magic/incantation.d.ts.map +0 -1
- package/dist/src/magic/incantation.js +0 -81
- package/dist/src/magic/incantation.js.map +0 -1
- package/dist/src/magic/index.d.ts +0 -6
- package/dist/src/magic/index.d.ts.map +0 -1
- package/dist/src/magic/index.js +0 -5
- package/dist/src/magic/index.js.map +0 -1
- package/dist/src/magic/local/anim.d.ts +0 -7
- package/dist/src/magic/local/anim.d.ts.map +0 -1
- package/dist/src/magic/local/anim.js +0 -11
- package/dist/src/magic/local/anim.js.map +0 -1
- package/dist/src/magic/local/colour.d.ts +0 -12
- package/dist/src/magic/local/colour.d.ts.map +0 -1
- package/dist/src/magic/local/colour.js +0 -27
- package/dist/src/magic/local/colour.js.map +0 -1
- package/dist/src/magic/local/dashed.d.ts +0 -7
- package/dist/src/magic/local/dashed.d.ts.map +0 -1
- package/dist/src/magic/local/dashed.js +0 -10
- package/dist/src/magic/local/dashed.js.map +0 -1
- package/dist/src/magic/local/fill.d.ts +0 -13
- package/dist/src/magic/local/fill.d.ts.map +0 -1
- package/dist/src/magic/local/fill.js +0 -12
- package/dist/src/magic/local/fill.js.map +0 -1
- package/dist/src/magic/local/hide.d.ts +0 -7
- package/dist/src/magic/local/hide.d.ts.map +0 -1
- package/dist/src/magic/local/hide.js +0 -10
- package/dist/src/magic/local/hide.js.map +0 -1
- package/dist/src/magic/local/index.d.ts +0 -3
- package/dist/src/magic/local/index.d.ts.map +0 -1
- package/dist/src/magic/local/index.js +0 -24
- package/dist/src/magic/local/index.js.map +0 -1
- package/dist/src/magic/local/line.d.ts +0 -15
- package/dist/src/magic/local/line.d.ts.map +0 -1
- package/dist/src/magic/local/line.js +0 -17
- package/dist/src/magic/local/line.js.map +0 -1
- package/dist/src/magic/local/no-line.d.ts +0 -7
- package/dist/src/magic/local/no-line.d.ts.map +0 -1
- package/dist/src/magic/local/no-line.js +0 -10
- package/dist/src/magic/local/no-line.js.map +0 -1
- package/dist/src/magic/local/point.d.ts +0 -15
- package/dist/src/magic/local/point.d.ts.map +0 -1
- package/dist/src/magic/local/point.js +0 -17
- package/dist/src/magic/local/point.js.map +0 -1
- package/dist/src/magic/local/secret.d.ts +0 -7
- package/dist/src/magic/local/secret.d.ts.map +0 -1
- package/dist/src/magic/local/secret.js +0 -10
- package/dist/src/magic/local/secret.js.map +0 -1
- package/dist/src/magic/local/slider.d.ts +0 -15
- package/dist/src/magic/local/slider.d.ts.map +0 -1
- package/dist/src/magic/local/slider.js +0 -13
- package/dist/src/magic/local/slider.js.map +0 -1
- package/dist/src/parser/ast.d.ts +0 -40
- package/dist/src/parser/ast.d.ts.map +0 -1
- package/dist/src/parser/ast.js +0 -13
- package/dist/src/parser/ast.js.map +0 -1
- package/dist/src/parser/desmost-parser.d.ts +0 -105
- package/dist/src/parser/desmost-parser.d.ts.map +0 -1
- package/dist/src/parser/desmost-parser.js +0 -379
- package/dist/src/parser/desmost-parser.js.map +0 -1
- package/dist/src/parser/generic-parser.d.ts +0 -62
- package/dist/src/parser/generic-parser.d.ts.map +0 -1
- package/dist/src/parser/generic-parser.js +0 -143
- package/dist/src/parser/generic-parser.js.map +0 -1
- package/dist/src/parser/index.d.ts +0 -8
- package/dist/src/parser/index.d.ts.map +0 -1
- package/dist/src/parser/index.js +0 -8
- package/dist/src/parser/index.js.map +0 -1
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import { GenericParser } from "./generic-parser";
|
|
2
|
-
import { Ast } from "./ast";
|
|
3
|
-
import { RecoverableFail, UnrecoverableError } from "../errors";
|
|
4
|
-
import { Incantation, ArgIncantation, GLOBAL_INCANTATIONS, LOCAL_INCANTATIONS, EXPR_INCANTATIONS } from "../magic";
|
|
5
|
-
/**
|
|
6
|
-
* A stateful lazy parser for Desmost.
|
|
7
|
-
*/
|
|
1
|
+
import { GenericParser } from "./generic-parser.js";
|
|
2
|
+
import { Ast } from "./ast.js";
|
|
3
|
+
import { RecoverableFail, UnrecoverableError } from "../errors.js";
|
|
4
|
+
import { Incantation, ArgIncantation, GLOBAL_INCANTATIONS, LOCAL_INCANTATIONS, EXPR_INCANTATIONS } from "../magic/index.js";
|
|
8
5
|
export class DesmostParser extends GenericParser {
|
|
9
6
|
constructor(source, options) {
|
|
10
7
|
super(options?.ignore_trailing_blanks ? source : (source + "\n"));
|
|
11
8
|
}
|
|
12
|
-
// == TOP-LEVEL == //
|
|
13
|
-
/**
|
|
14
|
-
* Parse the next semantic block of source code, producing an `Ast` object, or `null` if the parser has successfully reached the end of the source code.
|
|
15
|
-
*/
|
|
16
9
|
parse_next() {
|
|
17
10
|
this.consume_spaces();
|
|
18
11
|
if (this.out_of_bounds()) {
|
|
@@ -21,10 +14,8 @@ export class DesmostParser extends GenericParser {
|
|
|
21
14
|
if (this.current === "/") {
|
|
22
15
|
let r = this.parse_pre_sep();
|
|
23
16
|
if ("global" in r) {
|
|
24
|
-
// 1 global
|
|
25
17
|
return r.global;
|
|
26
18
|
}
|
|
27
|
-
// 1+ locals + 1 expr
|
|
28
19
|
let incantations = r.local;
|
|
29
20
|
var expr = this.parse_post_sep();
|
|
30
21
|
for (let invocation of incantations) {
|
|
@@ -32,20 +23,12 @@ export class DesmostParser extends GenericParser {
|
|
|
32
23
|
}
|
|
33
24
|
}
|
|
34
25
|
else {
|
|
35
|
-
// 1 expr
|
|
36
26
|
var expr = this.parse_post_sep();
|
|
37
27
|
}
|
|
38
28
|
this.consume_end_of_block();
|
|
39
29
|
return expr;
|
|
40
30
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Parse Desmost syntax before the `::` separator, which may be:
|
|
43
|
-
*
|
|
44
|
-
* - 1 global incantation
|
|
45
|
-
* - 1+ local incantations
|
|
46
|
-
*/
|
|
47
31
|
parse_pre_sep() {
|
|
48
|
-
// 1 global incantation
|
|
49
32
|
try {
|
|
50
33
|
let r = this.try_parse_global_incantation();
|
|
51
34
|
this.consume_end_of_block(`Received excess input after global incantation /${r.incantation.identifier}`);
|
|
@@ -56,7 +39,6 @@ export class DesmostParser extends GenericParser {
|
|
|
56
39
|
throw e;
|
|
57
40
|
}
|
|
58
41
|
let incantations = [];
|
|
59
|
-
// 1+ local incantations
|
|
60
42
|
while (this.current === "/") {
|
|
61
43
|
try {
|
|
62
44
|
incantations.push(this.try_parse_local_incantation());
|
|
@@ -72,30 +54,19 @@ export class DesmostParser extends GenericParser {
|
|
|
72
54
|
}
|
|
73
55
|
return { local: incantations };
|
|
74
56
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Parse the Desmost `::` separator.
|
|
77
|
-
*/
|
|
78
57
|
parse_sep() {
|
|
79
58
|
this.consume_whitespace();
|
|
80
59
|
this.consume("::", `Expected \`::\` separator between local incantations and expression, but found: \`${this.preview()}\``);
|
|
81
60
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Parse Desmost syntax after the `::` separator, which may be:
|
|
84
|
-
*
|
|
85
|
-
* - 1 line of LaTeX
|
|
86
|
-
* - 1 expression incantation
|
|
87
|
-
*/
|
|
88
61
|
parse_post_sep() {
|
|
89
62
|
this.consume_spaces();
|
|
90
63
|
switch (this.current) {
|
|
91
|
-
// empty block
|
|
92
64
|
case "\n":
|
|
93
65
|
return {
|
|
94
66
|
kind: Ast.Kind.EXPRESSION,
|
|
95
67
|
data: { latex: ` ` },
|
|
96
68
|
incantations: [],
|
|
97
69
|
};
|
|
98
|
-
// expr incantation
|
|
99
70
|
case "/":
|
|
100
71
|
try {
|
|
101
72
|
return this.try_parse_expr_incantation();
|
|
@@ -103,18 +74,12 @@ export class DesmostParser extends GenericParser {
|
|
|
103
74
|
catch (e) {
|
|
104
75
|
if (!(e instanceof RecoverableFail))
|
|
105
76
|
throw e;
|
|
106
|
-
// plain LaTeX (fallback)
|
|
107
77
|
return this.parse_latex_line();
|
|
108
78
|
}
|
|
109
|
-
// plain LaTeX
|
|
110
79
|
default:
|
|
111
80
|
return this.parse_latex_line();
|
|
112
81
|
}
|
|
113
82
|
}
|
|
114
|
-
// == LOW-LEVEL == //
|
|
115
|
-
/**
|
|
116
|
-
* Parse a single line of LaTeX.
|
|
117
|
-
*/
|
|
118
83
|
parse_latex_line() {
|
|
119
84
|
let init = this.i;
|
|
120
85
|
while (!this.out_of_bounds() && this.current !== "\n") {
|
|
@@ -126,9 +91,6 @@ export class DesmostParser extends GenericParser {
|
|
|
126
91
|
incantations: [],
|
|
127
92
|
};
|
|
128
93
|
}
|
|
129
|
-
/**
|
|
130
|
-
* Attempt to parse a global incantation invocation.
|
|
131
|
-
*/
|
|
132
94
|
try_parse_global_incantation() {
|
|
133
95
|
let init = this.i;
|
|
134
96
|
this.try_consume("/");
|
|
@@ -161,9 +123,6 @@ export class DesmostParser extends GenericParser {
|
|
|
161
123
|
arg_raw: data,
|
|
162
124
|
};
|
|
163
125
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Attempt to parse a local incantation invocation.
|
|
166
|
-
*/
|
|
167
126
|
try_parse_local_incantation() {
|
|
168
127
|
let init = this.i;
|
|
169
128
|
this.try_consume("/");
|
|
@@ -197,7 +156,6 @@ export class DesmostParser extends GenericParser {
|
|
|
197
156
|
};
|
|
198
157
|
}
|
|
199
158
|
try_parse_expr_incantation() {
|
|
200
|
-
// TODO refactor with `backtrack()` helper
|
|
201
159
|
let init = this.i;
|
|
202
160
|
this.try_consume("/");
|
|
203
161
|
try {
|
|
@@ -205,7 +163,6 @@ export class DesmostParser extends GenericParser {
|
|
|
205
163
|
}
|
|
206
164
|
catch (e) {
|
|
207
165
|
if (e instanceof RecoverableFail) {
|
|
208
|
-
// TODO maybe flag to user
|
|
209
166
|
this.i = init;
|
|
210
167
|
}
|
|
211
168
|
throw e;
|
|
@@ -219,12 +176,8 @@ export class DesmostParser extends GenericParser {
|
|
|
219
176
|
incantations: [],
|
|
220
177
|
};
|
|
221
178
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Attempt to parse an incantation identifier.
|
|
224
|
-
*/
|
|
225
179
|
try_parse_identifier(incantations) {
|
|
226
180
|
for (let incantation of incantations) {
|
|
227
|
-
// yeah the duplication here is a little meh, unfortunately needing `return` means we can't extract it into a helper
|
|
228
181
|
try {
|
|
229
182
|
this.try_consume(incantation.identifier);
|
|
230
183
|
return incantation;
|
|
@@ -246,55 +199,7 @@ export class DesmostParser extends GenericParser {
|
|
|
246
199
|
}
|
|
247
200
|
throw new RecoverableFail();
|
|
248
201
|
}
|
|
249
|
-
|
|
250
|
-
* Parse an argument to an incantation, enclosed in `{}`.
|
|
251
|
-
*
|
|
252
|
-
* ```ts
|
|
253
|
-
* /incantation{ arg }
|
|
254
|
-
* ^^^^^^^
|
|
255
|
-
* ```
|
|
256
|
-
*
|
|
257
|
-
* ## Notes
|
|
258
|
-
*
|
|
259
|
-
* We don't actually care for what type the argument is since we won't be evaluating it, we just want to find the closing `}`.
|
|
260
|
-
*
|
|
261
|
-
* However, the argument itself might be *meant* to contain a `}`. So we need a way to accurately identify the actual closing brace:
|
|
262
|
-
*
|
|
263
|
-
* ```ts
|
|
264
|
-
* /incantation{ field: { value: 1 } }
|
|
265
|
-
* ^ ^
|
|
266
|
-
* ```
|
|
267
|
-
*
|
|
268
|
-
* A well-formed argument always has matching pairs of `{}`, so we'll keep a stack. It starts with the opening `{`. When the stack is depleted, we must've reached the end of the argument.
|
|
269
|
-
*
|
|
270
|
-
* However, there's still more edge cases:
|
|
271
|
-
*
|
|
272
|
-
* ```ts
|
|
273
|
-
* /label{ text: "This }s weird" }
|
|
274
|
-
* ^
|
|
275
|
-
* ```
|
|
276
|
-
*
|
|
277
|
-
* `{` and `}` can appear in strings, and they won't necessarily be matched, so we'll ignore them by also tracking string contexts.
|
|
278
|
-
*
|
|
279
|
-
* ```ts
|
|
280
|
-
* /latex{ \{ x, y ) }
|
|
281
|
-
* ^
|
|
282
|
-
* ```
|
|
283
|
-
*
|
|
284
|
-
* `{` and `}` in LaTeX can be escaped with `\{` or `\}`, and these won't necessarily be matched, so we'll ignore them by also tracking backslash escapes.
|
|
285
|
-
*
|
|
286
|
-
* If the user truly mismatches `{}`, then, well ...parsing will fail catastrophically!
|
|
287
|
-
*/
|
|
288
|
-
parse_incantation_arg(
|
|
289
|
-
/**
|
|
290
|
-
* The type of argument to parse.
|
|
291
|
-
*
|
|
292
|
-
* Parsing strategy varies for different types:
|
|
293
|
-
*
|
|
294
|
-
* - String / LaTeX: Track only balanced `{}` and escaped `\{\}`.
|
|
295
|
-
* - JavaScript object: The above, plus balanced string quotes.
|
|
296
|
-
*/
|
|
297
|
-
arg_type) {
|
|
202
|
+
parse_incantation_arg(arg_type) {
|
|
298
203
|
let init = this.i;
|
|
299
204
|
this.consume("{", `Expected \`{\` to start incantation argument, but found: \`${this.preview()}\``);
|
|
300
205
|
let Ctx;
|
|
@@ -306,11 +211,6 @@ export class DesmostParser extends GenericParser {
|
|
|
306
211
|
Ctx["ESCAPE"] = "\\";
|
|
307
212
|
})(Ctx || (Ctx = {}));
|
|
308
213
|
let stack = [Ctx.BLOCK];
|
|
309
|
-
/**
|
|
310
|
-
* Pop `ctx` if it is the currently active context, returning `true` if successful.
|
|
311
|
-
*
|
|
312
|
-
* If `{ force: true }`, backtrack the stack and report errors for unterminated contexts.
|
|
313
|
-
*/
|
|
314
214
|
function try_pop(ctx, options) {
|
|
315
215
|
if (stack.at(-1) === ctx) {
|
|
316
216
|
stack.pop();
|
|
@@ -318,7 +218,6 @@ export class DesmostParser extends GenericParser {
|
|
|
318
218
|
}
|
|
319
219
|
else if (options?.force) {
|
|
320
220
|
if (stack.includes(ctx)) {
|
|
321
|
-
/* NOTE: We could report errors for unterminated contexts, but we'll leave that for the actual evaluation - in case we get something wrong ;) */
|
|
322
221
|
while (stack.at(-1) !== ctx) {
|
|
323
222
|
stack.pop();
|
|
324
223
|
}
|
|
@@ -336,7 +235,6 @@ export class DesmostParser extends GenericParser {
|
|
|
336
235
|
case Ctx.ESCAPE:
|
|
337
236
|
stack.push(Ctx.ESCAPE);
|
|
338
237
|
break;
|
|
339
|
-
/* NOTE: *Currently* `{}` should be ignored in all contexts except `Ctx.BLOCK`. This might change if more contexts are added in future! */
|
|
340
238
|
case Char.L_BRACE:
|
|
341
239
|
if (top !== Ctx.BLOCK)
|
|
342
240
|
break;
|
|
@@ -363,7 +261,6 @@ export class DesmostParser extends GenericParser {
|
|
|
363
261
|
}
|
|
364
262
|
this.advance(`Unexpected end of input while parsing incantation argument, stack: ${JSON.stringify(stack)}`);
|
|
365
263
|
}
|
|
366
|
-
/* NOTE: Cut in by 1 on both sides to exclude {} braces */
|
|
367
264
|
return this.source.slice(init + 1, this.i - 1).trim();
|
|
368
265
|
}
|
|
369
266
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"desmost-parser.js","sourceRoot":"","sources":["../../src/parser/desmost-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAGhE,OAAO,EACL,WAAW,EAAE,cAAc,EAC3B,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAC3D,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,CAAC,KAAK,CAAC,CAAC;wBAAC,MAAM;oBACnE,KAAK,GAAG,CAAC,KAAK;wBAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;wBAAC,MAAM;oBACnE,KAAK,GAAG,CAAC,KAAK;wBAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;wBAAC,MAAM;gBACrE,CAAC;YACH,CAAC;YAED,IAAI,CAAC,OAAO,CACV,sEAAsE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAC9F,CAAC;QACJ,CAAC;QAGD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACxD,CAAC;CAEF;AAGD,IAAK,IAQJ;AARD,WAAK,IAAI;IAEP,qBAAkB,CAAA;IAClB,qBAAkB,CAAA;IAClB,0BAAkB,CAAA;IAClB,2BAAkB,CAAA;IAClB,sBAAkB,CAAA;IAClB,wBAAmB,CAAA;AACrB,CAAC,EARI,IAAI,KAAJ,IAAI,QAQR"}
|
|
@@ -1,61 +1,18 @@
|
|
|
1
|
-
import type { Recoverable, Unrecoverable } from "../errors";
|
|
2
|
-
/**
|
|
3
|
-
* A stateful lazy parser, providing core methods for parsing.
|
|
4
|
-
*
|
|
5
|
-
* Many methods come in `<verb>` and `try_<verb>` pairs. On parsing failure, the former throws an `UnrecoverableError`, but the latter instead backtracks and only throws a `RecoverableFail`.
|
|
6
|
-
*/
|
|
1
|
+
import type { Recoverable, Unrecoverable } from "../errors.js";
|
|
7
2
|
export declare class GenericParser {
|
|
8
|
-
/** The source code this parser is parsing. */
|
|
9
3
|
protected source: string;
|
|
10
|
-
/** The current position in the source code the parser is pointing to. */
|
|
11
4
|
protected i: number;
|
|
12
|
-
/** The number of characters in the source code. */
|
|
13
5
|
protected length: number;
|
|
14
|
-
/** Create a parser for parsing `source`. */
|
|
15
6
|
constructor(source: string);
|
|
16
|
-
/**
|
|
17
|
-
* Is the parser currently pointing at an invalid character?
|
|
18
|
-
*/
|
|
19
7
|
protected out_of_bounds(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Get the character the parser is currently pointing at, or `undefined` if the parser is out-of-bounds.
|
|
22
|
-
*/
|
|
23
8
|
protected get current(): string | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Get the character *after* the current one that the parser points at.
|
|
26
|
-
*/
|
|
27
9
|
protected next(): string | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Peek a snippet of the upcoming source text (for error messages).
|
|
30
|
-
*/
|
|
31
10
|
preview(): string;
|
|
32
|
-
/**
|
|
33
|
-
* Advance to the next character, skipping ignored characters.
|
|
34
|
-
*
|
|
35
|
-
* Errors if the parser is the out-of-bounds *before* advancing.
|
|
36
|
-
*/
|
|
37
11
|
protected advance(error_msg?: string): Unrecoverable<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Attempt to advance to the next character, skipping ignored characters.
|
|
40
|
-
*/
|
|
41
12
|
protected try_advance(): Recoverable<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Consume `raw`, erroring if `raw` was not found.
|
|
44
|
-
*/
|
|
45
13
|
protected consume(raw: string, error_msg?: string): Unrecoverable<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Attempt to consume `raw`, backtracking and throwing if `raw` was not found.
|
|
48
|
-
*/
|
|
49
14
|
protected try_consume(raw: string): Recoverable<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Consume 0 or more space characters.
|
|
52
|
-
*/
|
|
53
15
|
protected consume_spaces(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Consume 0 or more whitespace characters.
|
|
56
|
-
*
|
|
57
|
-
* Same as `.consume_spaces()`, but allows newlines.
|
|
58
|
-
*/
|
|
59
16
|
protected consume_whitespace(): void;
|
|
60
17
|
protected consume_end_of_block(error_msg?: string): Unrecoverable<void>;
|
|
61
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic-parser.d.ts","sourceRoot":"","sources":["../../src/parser/generic-parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"generic-parser.d.ts","sourceRoot":"","sources":["../../src/parser/generic-parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAa5D,qBAAa,aAAa;IAGxB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IAGzB,SAAS,CAAC,CAAC,EAAE,MAAM,CAAK;IAGxB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IAIzB,YAAY,MAAM,EAAE,MAAM,EAIzB;IAMD,SAAS,CAAC,aAAa,IAAI,OAAO,CAGjC;IAKD,SAAS,KAAK,OAAO,IAAI,MAAM,GAAG,SAAS,CAG1C;IAKD,SAAS,CAAC,IAAI,IAAI,MAAM,GAAG,SAAS,CAGnC;IAKM,OAAO,IAAI,MAAM,CAGvB;IAOD,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAYzD;IAKD,SAAS,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,CAAC,CAQzC;IAKD,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAsBtE;IAKD,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAepD;IAKD,SAAS,CAAC,cAAc,IAAI,IAAI,CAQ/B;IAOD,SAAS,CAAC,kBAAkB,IAAI,IAAI,CAQnC;IAED,SAAS,CAAC,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAgBtE;CACF"}
|
|
@@ -1,66 +1,36 @@
|
|
|
1
|
-
import { RecoverableFail, UnrecoverableError } from "../errors";
|
|
1
|
+
import { RecoverableFail, UnrecoverableError } from "../errors.js";
|
|
2
2
|
const IGNORED_CHARACTERS = new Set([
|
|
3
3
|
"\r",
|
|
4
4
|
]);
|
|
5
|
-
/**
|
|
6
|
-
* A stateful lazy parser, providing core methods for parsing.
|
|
7
|
-
*
|
|
8
|
-
* Many methods come in `<verb>` and `try_<verb>` pairs. On parsing failure, the former throws an `UnrecoverableError`, but the latter instead backtracks and only throws a `RecoverableFail`.
|
|
9
|
-
*/
|
|
10
5
|
export class GenericParser {
|
|
11
|
-
/** The source code this parser is parsing. */
|
|
12
6
|
source;
|
|
13
|
-
/** The current position in the source code the parser is pointing to. */
|
|
14
7
|
i = 0;
|
|
15
|
-
/** The number of characters in the source code. */
|
|
16
8
|
length;
|
|
17
|
-
/** Create a parser for parsing `source`. */
|
|
18
9
|
constructor(source) {
|
|
19
10
|
this.source = source;
|
|
20
11
|
this.length = source.length;
|
|
21
12
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Is the parser currently pointing at an invalid character?
|
|
24
|
-
*/
|
|
25
13
|
out_of_bounds() {
|
|
26
14
|
return this.i >= this.length;
|
|
27
15
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Get the character the parser is currently pointing at, or `undefined` if the parser is out-of-bounds.
|
|
30
|
-
*/
|
|
31
16
|
get current() {
|
|
32
17
|
return this.source.at(this.i);
|
|
33
18
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Get the character *after* the current one that the parser points at.
|
|
36
|
-
*/
|
|
37
19
|
next() {
|
|
38
20
|
return this.source.at(this.i + 1);
|
|
39
21
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Peek a snippet of the upcoming source text (for error messages).
|
|
42
|
-
*/
|
|
43
22
|
preview() {
|
|
44
23
|
return this.source.slice(this.i, this.i + 20) + "...";
|
|
45
24
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Advance to the next character, skipping ignored characters.
|
|
48
|
-
*
|
|
49
|
-
* Errors if the parser is the out-of-bounds *before* advancing.
|
|
50
|
-
*/
|
|
51
25
|
advance(error_msg) {
|
|
52
26
|
if (this.out_of_bounds()) {
|
|
53
27
|
throw new UnrecoverableError.UnexpectedEnd(error_msg ?? "Unexpected end of input");
|
|
54
28
|
}
|
|
55
29
|
this.i++;
|
|
56
|
-
// @ts-expect-error: `this.current == undefined` is a true negative
|
|
57
30
|
if (IGNORED_CHARACTERS.has(this.current)) {
|
|
58
31
|
this.advance();
|
|
59
32
|
}
|
|
60
33
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Attempt to advance to the next character, skipping ignored characters.
|
|
63
|
-
*/
|
|
64
34
|
try_advance() {
|
|
65
35
|
try {
|
|
66
36
|
this.advance();
|
|
@@ -69,9 +39,6 @@ export class GenericParser {
|
|
|
69
39
|
throw new RecoverableFail();
|
|
70
40
|
}
|
|
71
41
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Consume `raw`, erroring if `raw` was not found.
|
|
74
|
-
*/
|
|
75
42
|
consume(raw, error_msg) {
|
|
76
43
|
if (this.out_of_bounds()) {
|
|
77
44
|
throw new UnrecoverableError.UnexpectedEnd(`Unexpected end of input while trying to consume: \`${raw}\``);
|
|
@@ -85,9 +52,6 @@ export class GenericParser {
|
|
|
85
52
|
}
|
|
86
53
|
throw new UnrecoverableError.UnexpectedInput(error_msg ?? `Expected: \`${raw}\`, but found: \`${this.preview()}\``);
|
|
87
54
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Attempt to consume `raw`, backtracking and throwing if `raw` was not found.
|
|
90
|
-
*/
|
|
91
55
|
try_consume(raw) {
|
|
92
56
|
let init = this.i;
|
|
93
57
|
let ii = 0;
|
|
@@ -102,24 +66,14 @@ export class GenericParser {
|
|
|
102
66
|
this.i = init;
|
|
103
67
|
throw new RecoverableFail();
|
|
104
68
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Consume 0 or more space characters.
|
|
107
|
-
*/
|
|
108
69
|
consume_spaces() {
|
|
109
|
-
/* NOTE: Callers should be able to assume this is safe to call even when at end of input, since it should just match 0 characters */
|
|
110
70
|
if (this.out_of_bounds())
|
|
111
71
|
return;
|
|
112
72
|
while (this.current === " ") {
|
|
113
73
|
this.advance();
|
|
114
74
|
}
|
|
115
75
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Consume 0 or more whitespace characters.
|
|
118
|
-
*
|
|
119
|
-
* Same as `.consume_spaces()`, but allows newlines.
|
|
120
|
-
*/
|
|
121
76
|
consume_whitespace() {
|
|
122
|
-
/* NOTE: Callers should be able to assume this is safe to call even when at end of input, since it should just match 0 characters */
|
|
123
77
|
if (this.i >= this.length)
|
|
124
78
|
return;
|
|
125
79
|
while (this.current === " " || this.current === "\n") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic-parser.js","sourceRoot":"","sources":["../../src/parser/generic-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAIhE,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,IAAI;CACL,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"generic-parser.js","sourceRoot":"","sources":["../../src/parser/generic-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAIhE,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,IAAI;CACL,CAAC,CAAC;AAQH,MAAM,OAAO,aAAa;IAGd,MAAM,CAAS;IAGf,CAAC,GAAW,CAAC,CAAC;IAGd,MAAM,CAAS;IAIzB,YAAY,MAAc;QAExB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GA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IAAI,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QAElC,IAAI,CAAC,cAAc,EAAE,CAAC;QAEtB,IAAI,CAAC;YACH,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACT,IAAI,CAAC,CAAC,CAAC,YAAY,eAAe,CAAC;gBAAE,MAAM,CAAC,CAAC;YAE7C,MAAM,IAAI,kBAAkB,CAAC,WAAW,CACtC,SAAS,IAAI,uCAAuC,IAAI,CAAC,OAAO,EAAE,IAAI,CACvE,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
package/dist/parser/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* The parsing engine makes heavy use of exceptions for backtracking, which is *very unperformant*, but makes for *much more readable code*. Desmost isn't expecting to parse huge documents of source code, so I decided this is an acceptable trade-off.
|
|
5
|
-
*/
|
|
6
|
-
export { DesmostParser } from "./desmost-parser";
|
|
7
|
-
export { Ast } from "./ast";
|
|
1
|
+
export { DesmostParser } from "./desmost-parser.js";
|
|
2
|
+
export { Ast } from "./ast.js";
|
|
8
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/parser/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* The parsing engine makes heavy use of exceptions for backtracking, which is *very unperformant*, but makes for *much more readable code*. Desmost isn't expecting to parse huge documents of source code, so I decided this is an acceptable trade-off.
|
|
5
|
-
*/
|
|
6
|
-
export { DesmostParser } from "./desmost-parser";
|
|
7
|
-
export { Ast } from "./ast";
|
|
1
|
+
export { DesmostParser } from "./desmost-parser.js";
|
|
2
|
+
export { Ast } from "./ast.js";
|
|
8
3
|
//# sourceMappingURL=index.js.map
|
package/dist/parser/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "desmost",
|
|
3
3
|
"author": "Sup#2.0",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
|
|
7
7
|
"description": "A tiny DSL for compiling LaTeX to Desmos",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"desmos", "latex", "desmost"
|
|
10
10
|
],
|
|
11
11
|
|
|
12
|
-
"homepage": "https://github.
|
|
12
|
+
"homepage": "https://sup2point0.github.io/desmost",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/Sup2point0/desmost.git"
|
|
@@ -22,22 +22,28 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"./src/",
|
|
24
24
|
"./dist/",
|
|
25
|
-
"package.json"
|
|
25
|
+
"package.json",
|
|
26
|
+
"LICENCE"
|
|
26
27
|
],
|
|
27
28
|
"exports": {
|
|
28
29
|
".": {
|
|
29
30
|
"import": "./dist/index.js",
|
|
30
31
|
"types": "./dist/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./internal": {
|
|
34
|
+
"import": "./dist/index.internal.js",
|
|
35
|
+
"types": "./dist/index.internal.d.ts"
|
|
31
36
|
}
|
|
32
37
|
},
|
|
33
38
|
|
|
34
39
|
"scripts": {
|
|
35
|
-
"build":
|
|
40
|
+
"build": "nu build.nu",
|
|
41
|
+
"buildx": "nu build.nu full",
|
|
36
42
|
|
|
37
|
-
"test":
|
|
38
|
-
"testw":
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"testw": "vitest",
|
|
39
45
|
|
|
40
|
-
"check":
|
|
46
|
+
"check": "npx oxlint src"
|
|
41
47
|
},
|
|
42
48
|
|
|
43
49
|
"dependencies":
|
|
@@ -47,11 +53,11 @@
|
|
|
47
53
|
|
|
48
54
|
"devDependencies":
|
|
49
55
|
{
|
|
50
|
-
"@eslint/js": "^10.0",
|
|
51
56
|
"@types/desmos": "1.11",
|
|
52
57
|
"@types/node": "^26.0",
|
|
53
58
|
"oxlint": "^1.78",
|
|
54
59
|
"oxlint-tsgolint": "^7.0",
|
|
60
|
+
"tsc-alias": "^1.9",
|
|
55
61
|
"typescript": "^7.0",
|
|
56
62
|
"vitest": "^4.0"
|
|
57
63
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Ast } from "./parser";
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { type DesmostOptions } from "./options";
|
|
2
|
-
import { Ast } from "../parser";
|
|
3
|
-
/**
|
|
4
|
-
* Compile Desmost into Desmos.
|
|
5
|
-
*
|
|
6
|
-
* This calls the Desmost compiler: parsing and evaluating `source`, then injecting the results into an existing `desmos` instance. Pass in `options` to customise compilation.
|
|
7
|
-
*
|
|
8
|
-
* ## Example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* let calc = Desmos.GraphingCalculator();
|
|
12
|
-
*
|
|
13
|
-
* compile(calc, `/text{ sup world! }`);
|
|
14
|
-
*
|
|
15
|
-
* compile(calc, `/slider{ error! } :: t = 0`, {
|
|
16
|
-
* errors: "crash",
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function compile(
|
|
21
|
-
/** The Desmos calculator instance to compile into. */
|
|
22
|
-
desmos: Desmos.Calculator,
|
|
23
|
-
/** The Desmost source code to compile. */
|
|
24
|
-
source: string,
|
|
25
|
-
/** Compilation options. */
|
|
26
|
-
options?: DesmostOptions): void | DesmostDebug;
|
|
27
|
-
interface DesmostDebug {
|
|
28
|
-
duration: number;
|
|
29
|
-
ast: Ast[];
|
|
30
|
-
}
|
|
31
|
-
export {};
|
|
32
|
-
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAuB,MAAM,WAAW,CAAC;AAGrE,OAAO,EAAiB,GAAG,EAAE,MAAM,WAAW,CAAC;AAI/C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO;AACrB,sDAAsD;AACtD,MAAM,EAAE,MAAM,CAAC,UAAU;AAEzB,0CAA0C;AAC1C,MAAM,EAAE,MAAM;AAEd,2BAA2B;AAC3B,OAAO,CAAC,EAAE,cAAc,GACvB,IAAI,GAAG,YAAY,CAsFrB;AAGD,UAAU,YAAY;IAEpB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,GAAG,EAAE,CAAC;CACZ"}
|