desmost 0.8.0 → 0.8.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.
Files changed (92) hide show
  1. package/dist/compiler/compile.d.ts +25 -1
  2. package/dist/compiler/compile.d.ts.map +1 -1
  3. package/dist/compiler/compile.js +32 -2
  4. package/dist/compiler/compile.js.map +1 -1
  5. package/dist/compiler/evaluate.d.ts +11 -0
  6. package/dist/compiler/evaluate.d.ts.map +1 -1
  7. package/dist/compiler/evaluate.js +14 -0
  8. package/dist/compiler/evaluate.js.map +1 -1
  9. package/dist/compiler/format.d.ts +11 -0
  10. package/dist/compiler/format.d.ts.map +1 -1
  11. package/dist/compiler/format.js +14 -1
  12. package/dist/compiler/format.js.map +1 -1
  13. package/dist/compiler/index.d.ts.map +1 -1
  14. package/dist/compiler/index.js.map +1 -1
  15. package/dist/compiler/options.d.ts +79 -0
  16. package/dist/compiler/options.d.ts.map +1 -1
  17. package/dist/compiler/options.js +18 -11
  18. package/dist/compiler/options.js.map +1 -1
  19. package/dist/decompiler/decompile.d.ts +11 -0
  20. package/dist/decompiler/decompile.d.ts.map +1 -1
  21. package/dist/decompiler/decompile.js +11 -0
  22. package/dist/decompiler/decompile.js.map +1 -1
  23. package/dist/decompiler/emit.d.ts +6 -0
  24. package/dist/decompiler/emit.d.ts.map +1 -1
  25. package/dist/decompiler/emit.js +9 -0
  26. package/dist/decompiler/emit.js.map +1 -1
  27. package/dist/decompiler/extract.d.ts +9 -0
  28. package/dist/decompiler/extract.d.ts.map +1 -1
  29. package/dist/decompiler/extract.js +11 -1
  30. package/dist/decompiler/extract.js.map +1 -1
  31. package/dist/decompiler/format.js +6 -3
  32. package/dist/decompiler/format.js.map +1 -1
  33. package/dist/desmos.d.ts +3 -0
  34. package/dist/desmos.d.ts.map +1 -1
  35. package/dist/desmos.js +3 -0
  36. package/dist/desmos.js.map +1 -1
  37. package/dist/errors.d.ts +18 -4
  38. package/dist/errors.d.ts.map +1 -1
  39. package/dist/errors.js +13 -1
  40. package/dist/errors.js.map +1 -1
  41. package/dist/index.internal.d.ts +1 -1
  42. package/dist/index.internal.d.ts.map +1 -1
  43. package/dist/index.internal.js +1 -1
  44. package/dist/index.internal.js.map +1 -1
  45. package/dist/magic/expr/latex.js +1 -0
  46. package/dist/magic/expr/latex.js.map +1 -1
  47. package/dist/magic/expr/text.js +1 -0
  48. package/dist/magic/expr/text.js.map +1 -1
  49. package/dist/magic/global/desmos.d.ts +3 -1
  50. package/dist/magic/global/desmos.d.ts.map +1 -1
  51. package/dist/magic/global/desmos.js.map +1 -1
  52. package/dist/magic/incantation.d.ts +44 -0
  53. package/dist/magic/incantation.d.ts.map +1 -1
  54. package/dist/magic/incantation.js +38 -0
  55. package/dist/magic/incantation.js.map +1 -1
  56. package/dist/magic/index.d.ts +7 -0
  57. package/dist/magic/index.d.ts.map +1 -1
  58. package/dist/magic/index.js +7 -0
  59. package/dist/magic/index.js.map +1 -1
  60. package/dist/magic/local/anim.js +1 -0
  61. package/dist/magic/local/anim.js.map +1 -1
  62. package/dist/magic/local/label.js +1 -0
  63. package/dist/magic/local/label.js.map +1 -1
  64. package/dist/magic/local/slider.js +1 -0
  65. package/dist/magic/local/slider.js.map +1 -1
  66. package/dist/parser/ast.d.ts +9 -0
  67. package/dist/parser/ast.d.ts.map +1 -1
  68. package/dist/parser/ast.js +1 -0
  69. package/dist/parser/ast.js.map +1 -1
  70. package/dist/parser/desmost-parser.d.ts +101 -1
  71. package/dist/parser/desmost-parser.d.ts.map +1 -1
  72. package/dist/parser/desmost-parser.js +128 -1
  73. package/dist/parser/desmost-parser.js.map +1 -1
  74. package/dist/parser/generic-parser.d.ts +47 -0
  75. package/dist/parser/generic-parser.d.ts.map +1 -1
  76. package/dist/parser/generic-parser.js +50 -0
  77. package/dist/parser/generic-parser.js.map +1 -1
  78. package/dist/parser/index.d.ts.map +1 -1
  79. package/dist/parser/index.js.map +1 -1
  80. package/package.json +5 -2
  81. package/src/compiler/format.ts +6 -1
  82. package/src/compiler/index.ts +0 -7
  83. package/src/compiler/options.ts +18 -15
  84. package/src/compiler/readme.md +5 -0
  85. package/src/decompiler/readme.md +34 -0
  86. package/src/errors.ts +7 -7
  87. package/src/index.internal.ts +1 -1
  88. package/src/magic/global/desmos.ts +4 -1
  89. package/src/magic/readme.md +5 -0
  90. package/src/parser/ast.ts +3 -3
  91. package/src/parser/index.ts +0 -4
  92. package/src/parser/readme.md +21 -0
@@ -1,9 +1,33 @@
1
1
  import { type DesmostOptions } from "./options.js";
2
2
  import { Ast } from "../parser/index.js";
3
+ /** Debug diagnostics returned from `compile()`. */
3
4
  export interface DesmostDebug {
4
5
  duration: number;
5
6
  num_blocks: number;
6
7
  ast: Ast[];
7
8
  }
8
- export declare function compile(desmos: Desmos.Calculator, source: string, options?: DesmostOptions): void | DesmostDebug;
9
+ /**
10
+ * Compile Desmost into Desmos.
11
+ *
12
+ * This calls the Desmost compiler: parsing and evaluating `source`, then injecting the results into an existing `desmos` instance. Pass in `options` to customise compilation.
13
+ *
14
+ * ## Example
15
+ *
16
+ * ```ts
17
+ * let calc = Desmos.GraphingCalculator();
18
+ *
19
+ * compile(calc, `/text{ sup world! }`);
20
+ *
21
+ * compile(calc, `/slider{ error! } :: t = 0`, {
22
+ * errors: "crash",
23
+ * });
24
+ * ```
25
+ */
26
+ export declare function compile(
27
+ /** The Desmos calculator instance to compile into. */
28
+ desmos: Desmos.Calculator,
29
+ /** The Desmost source code to compile. */
30
+ source: string,
31
+ /** Compilation options. */
32
+ options?: DesmostOptions): void | DesmostDebug;
9
33
  //# 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,EAAiB,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAiB,GAAG,EAAE,MAAM,WAAW,CAAC;AAI/C,MAAM,WAAW,YAAY;IAE5B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,GAAG,EAAE,CAAC;CACX;AAoBD,wBAAgB,OAAO,CAEtB,MAAM,EAAE,MAAM,CAAC,UAAU,EAGzB,MAAM,EAAE,MAAM,EAGd,OAAO,CAAC,EAAE,cAAc,GACtB,IAAI,GAAG,YAAY,CAkHrB"}
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;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,2BAA2B;AAC3B,OAAO,CAAC,EAAE,cAAc,GACtB,IAAI,GAAG,YAAY,CAkHrB"}
@@ -1,7 +1,30 @@
1
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
- export function compile(desmos, source, options) {
4
+ /**
5
+ * Compile Desmost into Desmos.
6
+ *
7
+ * This calls the Desmost compiler: parsing and evaluating `source`, then injecting the results into an existing `desmos` instance. Pass in `options` to customise compilation.
8
+ *
9
+ * ## Example
10
+ *
11
+ * ```ts
12
+ * let calc = Desmos.GraphingCalculator();
13
+ *
14
+ * compile(calc, `/text{ sup world! }`);
15
+ *
16
+ * compile(calc, `/slider{ error! } :: t = 0`, {
17
+ * errors: "crash",
18
+ * });
19
+ * ```
20
+ */
21
+ export function compile(
22
+ /** The Desmos calculator instance to compile into. */
23
+ desmos,
24
+ /** The Desmost source code to compile. */
25
+ source,
26
+ /** Compilation options. */
27
+ options) {
5
28
  if (desmos == undefined) {
6
29
  console.error(`Desmost: No \`Desmos.Calculator\` instance provided, aborting compilation!`);
7
30
  return;
@@ -18,11 +41,16 @@ export function compile(desmos, source, options) {
18
41
  }
19
42
  let parser = new DesmostParser(source, opts);
20
43
  let errors = [];
44
+ /* To aggregate errors at the start, we need a target to retroactively inject errors into */
21
45
  if (opts.place_errors === "start") {
22
- desmos.setExpression({ id: "deferred-start", latex: " " });
46
+ desmos.setExpression({ id: "deferred-start", latex: " " }); // FIXME check if ` ` needed
23
47
  }
48
+ /* Keep track of whether we're still evaluating leading blank expressions, which might be ignored. */
24
49
  let seen_non_blank = false;
50
+ /** The number of pending blank expressions to add. */
25
51
  let pending_blanks = 0;
52
+ /* 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. */
53
+ /* 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. */
26
54
  try {
27
55
  while (true) {
28
56
  let r = parser.parse_next();
@@ -32,12 +60,14 @@ export function compile(desmos, source, options) {
32
60
  num_blocks++;
33
61
  ast.push(r);
34
62
  }
63
+ /** An error message to leave for aggregation later. */
35
64
  let defer = undefined;
36
65
  switch (r.kind) {
37
66
  case Ast.Kind.INCANTATION_INVOCATION:
38
67
  defer = evaluate_global_incantation(r, desmos, opts);
39
68
  break;
40
69
  case Ast.Kind.EXPRESSION:
70
+ // @ts-expect-error: outdated types
41
71
  if (r.data.latex === " ") {
42
72
  if (opts.ignore_all_blanks)
43
73
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,aAAa,EAAE,MAAM,WAA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CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,IAAI,IAAI,GAA2B;YAClC,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SACzB,CAAC;QAEF,QAAQ,IAAI,CAAC,YAAY,EAAE,CAAC;YAC3B,KAAK,OAAO;gBACX,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;gBACxD,MAAM;YACP,KAAK,KAAK,CAAC;YACX,KAAK,QAAQ;gBACZ,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;gBAC3B,MAAM;QACR,CAAC;IACF,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO;YACN,QAAQ,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,MAAO;YACrC,UAAU,EAAE,UAAW;YACvB,GAAG,EAAE,GAAI;SACT,CAAC;IACH,CAAC;AACF,CAAC;AAGD,SAAS,oBAAoB,CAAC,MAAyB,EAAE,KAAa;IAErE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACtC,CAAC;AACF,CAAC"}
@@ -1,7 +1,18 @@
1
1
  import type { DesmostOptions } from "./options.js";
2
2
  import { Ast } from "../parser/index.js";
3
3
  import { UnrecoverableError, type Unrecoverable } from "../errors.js";
4
+ /**
5
+ * Evaluate arguments (if any) to a global incantation `invocation`, then apply the incantation to `desmos`.
6
+ */
4
7
  export declare function evaluate_global_incantation(invocation: Ast.IncantationInvocation, desmos: Desmos.Calculator, options: Required<DesmostOptions>): Unrecoverable<void | string>;
8
+ /**
9
+ * Evaluate arguments (if any) to local incantation invocations on `expr`, then add `expr` to `desmos`.
10
+ */
5
11
  export declare function evaluate_expr(expr: Ast.Expression, desmos: Desmos.Calculator, options: Required<DesmostOptions>): Unrecoverable<void | string>;
12
+ /**
13
+ * Handle an `InvalidInvocation`, respecting the user's preferences in `options`.
14
+ *
15
+ * If the user set `place_errors: start` or `place_errors: end`, this returns the formatted error message for deferred aggregation.
16
+ */
6
17
  export declare function evaluate_error(error: UnrecoverableError, desmos: Desmos.Calculator, options: Required<DesmostOptions>): Unrecoverable<void | string>;
7
18
  //# sourceMappingURL=evaluate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/compiler/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAMnE,wBAAgB,2BAA2B,CAC1C,UAAU,EAAE,GAAG,CAAC,qBAAqB,EACrC,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAC/B,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CAe9B;AAMD,wBAAgB,aAAa,CAC5B,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAC/B,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CA4C9B;AAQD,wBAAgB,cAAc,CAC7B,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAC/B,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CAuB9B"}
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/compiler/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAGnE;;GAEG;AACH,wBAAgB,2BAA2B,CAC1C,UAAU,EAAE,GAAG,CAAC,qBAAqB,EACrC,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAC/B,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,QAAQ,CAAC,cAAc,CAAC,GAC/B,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CA4C9B;AAGD;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAC/B,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CAuB9B"}
@@ -1,6 +1,9 @@
1
1
  import { format_error, normalise_latex, prettify_latex } from "./format.js";
2
2
  import { Ast } from "../parser/index.js";
3
3
  import { UnrecoverableError } from "../errors.js";
4
+ /**
5
+ * Evaluate arguments (if any) to a global incantation `invocation`, then apply the incantation to `desmos`.
6
+ */
4
7
  export function evaluate_global_incantation(invocation, desmos, options) {
5
8
  let data = undefined;
6
9
  if ("arg_raw" in invocation && invocation.arg_raw != undefined) {
@@ -14,6 +17,9 @@ export function evaluate_global_incantation(invocation, desmos, options) {
14
17
  }
15
18
  invocation.incantation.apply(desmos, data);
16
19
  }
20
+ /**
21
+ * Evaluate arguments (if any) to local incantation invocations on `expr`, then add `expr` to `desmos`.
22
+ */
17
23
  export function evaluate_expr(expr, desmos, options) {
18
24
  let errors = [];
19
25
  for (let invocation of expr.incantations) {
@@ -40,14 +46,22 @@ export function evaluate_expr(expr, desmos, options) {
40
46
  if (errors.length > 0) {
41
47
  desmos.setExpression({ type: "text", text: errors.join("\n\n") });
42
48
  }
49
+ // @ts-expect-error: outdated types
43
50
  if (expr.data.latex != undefined) {
51
+ // @ts-expect-error: outdated types
44
52
  expr.data.latex = normalise_latex(expr.data.latex);
45
53
  if (options.prettify) {
54
+ // @ts-expect-error: outdated types
46
55
  expr.data.latex = prettify_latex(expr.data.latex);
47
56
  }
48
57
  }
49
58
  desmos.setExpression(expr.data);
50
59
  }
60
+ /**
61
+ * Handle an `InvalidInvocation`, respecting the user's preferences in `options`.
62
+ *
63
+ * If the user set `place_errors: start` or `place_errors: end`, this returns the formatted error message for deferred aggregation.
64
+ */
51
65
  export function evaluate_error(error, desmos, options) {
52
66
  switch (options.errors) {
53
67
  case "crash":
@@ -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;AAMnE,MAAM,UAAU,2BAA2B,CAC1C,UAAqC,EACrC,MAAyB,EACzB,OAAiC;IAGjC,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,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACV,IAAI,GAAG,GA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EAAE,CAAC;QACxB,KAAK,OAAO;YACX,MAAM,KAAK,CAAC;QAEb,KAAK,UAAU;YACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,MAAM;QAEP,OAAO,CAAC,CAAC,QAAQ,OAAO,CAAC,YAAY,EAAE,CAAC;YACvC,KAAK,KAAK,CAAC;YACX,KAAK,OAAO;gBACX,OAAO,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAErC;gBACC,MAAM,CAAC,aAAa,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,17 @@
1
1
  import type { DesmostOptions } from "./options.js";
2
2
  import { UnrecoverableError } from "../errors.js";
3
3
  export declare function format_error(e: UnrecoverableError, options: Required<DesmostOptions>): string;
4
+ /**
5
+ * Remove line breaks from `latex` so Desmos can properly consume it.
6
+ */
4
7
  export declare function normalise_latex(latex: string): string;
8
+ /**
9
+ * Prettify `latex` to render nicely in Desmos, reflecting how you would type directly into Desmos.
10
+ *
11
+ * This includes:
12
+ *
13
+ * - Replace `()`, `[]`, etc. with `\left(\right)`
14
+ * - Replace `min()`, `max()`, etc. with `\operatorname{min}()`
15
+ */
5
16
  export declare function prettify_latex(latex: string): string;
6
17
  //# sourceMappingURL=format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/compiler/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAG/C,wBAAgB,YAAY,CAC3B,CAAC,EAAE,kBAAkB,EACrB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAC/B,MAAM,CAOR;AAMD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIrD;AAWD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAYpD"}
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/compiler/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAG/C,wBAAgB,YAAY,CAC3B,CAAC,EAAE,kBAAkB,EACrB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAC/B,MAAM,CAOR;AAGD;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIrD;AAGD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiBpD"}
@@ -3,16 +3,29 @@ export function format_error(e, options) {
3
3
  let prefix = options.error_prefix;
4
4
  let sep = (prefix === "" || prefix.endsWith("\n")) ? "" : " ";
5
5
  return `${prefix}${sep}${e.name}: ${e.message}`;
6
+ // TODO maybe include stack? (configurable?)
6
7
  }
8
+ /**
9
+ * Remove line breaks from `latex` so Desmos can properly consume it.
10
+ */
7
11
  export function normalise_latex(latex) {
8
12
  latex = latex.replaceAll(/\s+/g, " ");
9
13
  return latex;
10
14
  }
15
+ /**
16
+ * Prettify `latex` to render nicely in Desmos, reflecting how you would type directly into Desmos.
17
+ *
18
+ * This includes:
19
+ *
20
+ * - Replace `()`, `[]`, etc. with `\left(\right)`
21
+ * - Replace `min()`, `max()`, etc. with `\operatorname{min}()`
22
+ */
11
23
  export function prettify_latex(latex) {
12
24
  latex = latex.replaceAll(/(?<!\\left)(\(|\[|\\\{)/g, "\\left$1");
13
25
  latex = latex.replaceAll(/(?<!\\right)(\)|\]|\\\})/g, "\\right$1");
14
26
  latex = latex.replaceAll(/(:|,)(?!\\ ) */g, "$1\\ ");
15
- latex = latex.replaceAll(/(?<=[^\w]|^)\\?(mean|median|count|total|repeat|join|sort|shuffle|unique|mod|ceil|floor|round|sign) ?(?=\(|\\left\()/g, "\\operatorname{$1}");
27
+ latex = latex.replaceAll(/(?<=[^\w]|^)\\?(length|mean|median|count|total|repeat|join|sort|shuffle|unique|mod|ceil|floor|round|sign) ?(?=\(|\\left\()/g, "\\operatorname{$1}");
28
+ latex = latex.replaceAll(/\s(and|or)\s/g, "\\operatorname{$1}");
16
29
  return latex;
17
30
  }
18
31
  //# sourceMappingURL=format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/compiler/format.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAG/C,MAAM,UAAU,YAAY,CAC3B,CAAqB,EACrB,OAAiC;IAGjC,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,OAAO,GAAG,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;AAEjD,CAAC;AAMD,MAAM,UAAU,eAAe,CAAC,KAAa;IAE5C,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACtC,OAAO,KAAK,CAAC;AACd,CAAC;AAWD,MAAM,UAAU,cAAc,CAAC,KAAa;IAE3C,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,0BAA0B,EAAE,UAAU,CAAC,CAAC;IACjE,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAC;IACnE,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE,OAAO,CAAC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d,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,YAAY,EAAE,cAAc,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;AACpC,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
@@ -1,13 +1,92 @@
1
+ /**
2
+ * Options to customise Desmost compilation.
3
+ *
4
+ * To customise compilation, pass in a `DesmostOptions` object as the last argument to `compile()`:
5
+ *
6
+ * ```ts
7
+ * compile(calc, source, { errors: "crash" });
8
+ * ```
9
+ */
1
10
  export interface DesmostOptions {
11
+ /**
12
+ * How should errors be *surfaced* to the end user?
13
+ *
14
+ * - `surface` (default): Blocks that result in errors will become Desmos text expressions containing the error message, leaving other expressions unaffected.
15
+ *
16
+ * - `crash`: The entire compilation to Desmos will terminate with a single error message. This means you don't get any output at all, but errors are also immediately obvious.
17
+ * - Note that this will *clear all expressions* in the calculator instance.
18
+ *
19
+ * - `suppress`: Silently fail on the frontend (if you wish to give the illusion that everything is fine).
20
+ */
2
21
  errors?: "surface" | "crash" | "suppress";
22
+ /**
23
+ * Where should errors be placed?
24
+ *
25
+ * - `inline` (default): Alongside or in place of the expression that produced it.
26
+ * - `end`: All aggregated at the end of the Desmos expressions list.
27
+ * - `start`: All aggregated at the start of the Desmos expressions list.
28
+ */
3
29
  place_errors?: "inline" | "end" | "start";
30
+ /**
31
+ * The prefix to prepend to error blocks.
32
+ *
33
+ * Defaults to `[DESMOST ERROR]\n`.
34
+ *
35
+ * Provide a `""` blank string if you wish for no prefix to be added.
36
+ */
4
37
  error_prefix?: string;
38
+ /**
39
+ * Prettify LaTeX output so it renders nicely in the Desmos editor?
40
+ *
41
+ * Defaults to `true`, meaning LaTeX is prettified.
42
+ */
5
43
  prettify?: boolean;
44
+ /**
45
+ * Should `%` LaTeX comments be ignored, instead of turned into text expressions (notes)?
46
+ *
47
+ * Defaults to `false`, meaning comments are kept.
48
+ */
6
49
  ignore_comments?: boolean;
50
+ /**
51
+ * Should all line breaks be ignored, instead of kept as blank expressions?
52
+ *
53
+ * Defaults to `false`, meaning all blank lines are kept.
54
+ */
7
55
  ignore_all_blanks?: boolean;
56
+ /**
57
+ * Should trailing blank lines at the start of the source be kept as blank expressions?
58
+ *
59
+ * Defaults to `false`, meaning leading blank lines are ignored.
60
+ */
8
61
  keep_leading_blanks?: boolean;
62
+ /**
63
+ * Should trailing blank lines at the end of the source be kept as blank expressions?
64
+ *
65
+ * Defaults to `false`, meaning trailing blank lines are ignored.
66
+ */
9
67
  keep_trailing_blanks?: boolean;
68
+ /**
69
+ * Return debug diagnostics?
70
+ *
71
+ * This includes the unevaluated AST and performance diagnostics.
72
+ *
73
+ * Defaults to `false`, meaning `compile()` returns `void`.
74
+ */
10
75
  debug?: boolean;
11
76
  }
77
+ export declare const DEFAULT_OPTIONS: {
78
+ errors: string;
79
+ place_errors: string;
80
+ error_prefix: string;
81
+ prettify: boolean;
82
+ ignore_comments: boolean;
83
+ ignore_all_blanks: boolean;
84
+ keep_leading_blanks: boolean;
85
+ keep_trailing_blanks: boolean;
86
+ debug: boolean;
87
+ };
88
+ /**
89
+ * Fill in `options` with Desmost's defaults to produce a complete `DesmostOptions` config.
90
+ */
12
91
  export declare function fill_defaults(options: Partial<DesmostOptions> | undefined): Required<DesmostOptions>;
13
92
  //# 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;IAY9B,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,QAAQ,CAAC,EAAE,OAAO,CAAA;IAOlB,eAAe,CAAC,EAAE,OAAO,CAAA;IAOzB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAO3B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAO7B,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAS9B,KAAK,CAAC,EAAE,OAAO,CAAA;CACf;AAMD,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,CAiBpG"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/compiler/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAE9B;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;IAEzC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAA;IAEzC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAE3B;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAE7B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAE9B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CACf;AAGD,eAAO,MAAM,eAAe;;;;;;;;;;CAW3B,CAAC;AAGF;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,CAMpG"}
@@ -1,14 +1,21 @@
1
+ export const DEFAULT_OPTIONS = {
2
+ errors: "surface",
3
+ place_errors: "inline",
4
+ error_prefix: "[DESMOST ERROR]\n",
5
+ prettify: true,
6
+ ignore_comments: false,
7
+ ignore_all_blanks: false,
8
+ keep_leading_blanks: false,
9
+ keep_trailing_blanks: false,
10
+ debug: false,
11
+ };
12
+ /**
13
+ * Fill in `options` with Desmost's defaults to produce a complete `DesmostOptions` config.
14
+ */
1
15
  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.prettify ??= true;
7
- out.ignore_comments ??= false;
8
- out.ignore_all_blanks ??= false;
9
- out.keep_leading_blanks ??= false;
10
- out.keep_trailing_blanks ??= false;
11
- out.debug ??= false;
12
- return out;
16
+ return {
17
+ ...DEFAULT_OPTIONS,
18
+ ...options,
19
+ };
13
20
  }
14
21
  //# sourceMappingURL=options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/compiler/options.ts"],"names":[],"mappings":"AA0FA,MAAM,UAAU,aAAa,CAAC,OAA4C;IAEzE,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,QAAQ,KAAK,IAAI,CAAC;IAEtB,GAAG,CAAC,eAAe,KAAK,KAAK,CAAC;IAC9B,GAAG,CAAC,iBAAiB,KAAK,KAAK,CAAC;IAChC,GAAG,CAAC,mBAAmB,KAAK,KAAK,CAAC;IAClC,GAAG,CAAC,oBAAoB,KAAK,KAAK,CAAC;IACnC,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC;IAEpB,OAAO,GAA+B,CAAC;AACxC,CAAC"}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/compiler/options.ts"],"names":[],"mappings":"AAuFA,MAAM,CAAC,MAAM,eAAe,GAC5B;IACG,MAAM,EAAE,SAAS;IACjB,YAAY,EAAE,QAAQ;IACtB,YAAY,EAAE,mBAAmB;IACjC,QAAQ,EAAE,IAAI;IACd,eAAe,EAAE,KAAK;IACtB,iBAAiB,EAAE,KAAK;IACxB,mBAAmB,EAAE,KAAK;IAC1B,oBAAoB,EAAE,KAAK;IAC3B,KAAK,EAAE,KAAK;CACd,CAAC;AAGF;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAA4C;IAEvE,OAAO;QACJ,GAAG,eAAe;QAClB,GAAG,OAAO;KACgB,CAAC;AACjC,CAAC"}
@@ -3,7 +3,18 @@ export interface SemiStructuredAst {
3
3
  globals: Ast.IncantationInvocation[];
4
4
  locals: Ast.Expression[];
5
5
  }
6
+ /**
7
+ * Decompile Desmos into raw Desmost source code.
8
+ *
9
+ * 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
+ */
6
11
  export declare function decompile(desmos: Desmos.Calculator, blank: Desmos.Calculator): string;
12
+ /**
13
+ * Decompile `desmos` into a semi-structured AST.
14
+ */
7
15
  export declare function desmos_to_ast(desmos: Desmos.Calculator, blank: Desmos.Calculator): SemiStructuredAst;
16
+ /**
17
+ * Emit the Desmost source code representation of `ast`.
18
+ */
8
19
  export declare function ast_to_source(ast: SemiStructuredAst): string;
9
20
  //# sourceMappingURL=decompile.d.ts.map
@@ -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;AAGhC,MAAM,WAAW,iBAAiB;IAE/B,OAAO,EAAE,GAAG,CAAC,qBAAqB,EAAE,CAAC;IACvC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC;CACzB;AAQD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAGrF;AAKD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,iBAAiB,CASpG;AAKD,wBAAgB,aAAa,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,CAO5D"}
1
+ {"version":3,"file":"decompile.d.ts","sourceRoot":"","sources":["../../src/decompiler/decompile.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGhC,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,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAGrF;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,9 +1,17 @@
1
1
  import { emit_global_incantation, emit_expression } from "./emit.js";
2
2
  import { extract_settings, extract_viewport, extract_expression } from "./extract.js";
3
3
  import { Ast } from "../parser/index.js";
4
+ /**
5
+ * Decompile Desmos into raw Desmost source code.
6
+ *
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
+ */
4
9
  export function decompile(desmos, blank) {
5
10
  return ast_to_source(desmos_to_ast(desmos, blank));
6
11
  }
12
+ /**
13
+ * Decompile `desmos` into a semi-structured AST.
14
+ */
7
15
  export function desmos_to_ast(desmos, blank) {
8
16
  return {
9
17
  globals: [
@@ -13,6 +21,9 @@ export function desmos_to_ast(desmos, blank) {
13
21
  locals: desmos.getExpressions().map(extract_expression),
14
22
  };
15
23
  }
24
+ /**
25
+ * Emit the Desmost source code representation of `ast`.
26
+ */
16
27
  export function ast_to_source(ast) {
17
28
  return (ast.globals.map(emit_global_incantation).join("\n")
18
29
  + "\n\n"
@@ -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;AAehC,MAAM,UAAU,SAAS,CAAC,MAAyB,EAAE,KAAwB;IAE5E,OAAO,aAAa,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AACpD,CAAC;AAKD,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,I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AC,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,4 +1,10 @@
1
1
  import type { Ast } from "../parser/index.js";
2
+ /**
3
+ * Emit the source code for a global incantation `invocation`.
4
+ */
2
5
  export declare function emit_global_incantation(invocation?: Ast.IncantationInvocation): string;
6
+ /**
7
+ * Emit the source code for an `expr`.
8
+ */
3
9
  export declare function emit_expression(expr?: Ast.Expression): string;
4
10
  //# sourceMappingURL=emit.d.ts.map
@@ -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;AAMrC,wBAAgB,uBAAuB,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,qBAAqB,GAAG,MAAM,CAQtF;AAMD,wBAAgB,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,UAAU,GAAG,MAAM,CA0B7D"}
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,CA0B7D"}
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Emit the source code for a global incantation `invocation`.
3
+ */
1
4
  export function emit_global_incantation(invocation) {
2
5
  if (invocation == undefined)
3
6
  return "";
@@ -5,9 +8,13 @@ export function emit_global_incantation(invocation) {
5
8
  let arg_raw = invocation.arg_raw;
6
9
  return `/${ident}{\n ${arg_raw}\n}`;
7
10
  }
11
+ /**
12
+ * Emit the source code for an `expr`.
13
+ */
8
14
  export function emit_expression(expr) {
9
15
  if (expr == undefined)
10
16
  return "";
17
+ // TODO
11
18
  let locals = [];
12
19
  let sep = expr.incantations.length > 0 ? " :: " : "";
13
20
  let content;
@@ -16,10 +23,12 @@ export function emit_expression(expr) {
16
23
  content = `/text{ ${expr.data.text} }`;
17
24
  break;
18
25
  default:
26
+ // @ts-expect-error: outdated types
19
27
  if (expr.data.latex?.trim() === "") {
20
28
  content = "";
21
29
  }
22
30
  else {
31
+ // @ts-expect-error: outdated types
23
32
  content = expr.data.latex ?? "?";
24
33
  }
25
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/decompiler/emit.ts"],"names":[],"mappings":"AAMA,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;AAMD,MAAM,UAAU,eAAe,CAAC,IAAqB;IAEpD,IAAI,IAAI,IAAI,SAAS;QAAE,OAAO,EAAE,CAAC;IAG/B,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,UAAU,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;YACvC,MAAM;QACT;YA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C;gBAClC,OAAO,GAAG,EAAE,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACL,mCAAmC;gBACnC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC;YACpC,CAAC;IACP,CAAC;IAED,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,OAAO,EAAE,CAAC;AAChD,CAAC"}
@@ -1,5 +1,14 @@
1
1
  import { Ast } from "../parser/index.js";
2
+ /**
3
+ * Extract a `/desmos` incantation from the settings of `desmos`.
4
+ */
2
5
  export declare function extract_settings(desmos: Desmos.Calculator, blank: Desmos.Calculator): Ast.IncantationInvocation | null;
6
+ /**
7
+ * Extract a `/viewport` incantation from the viewport bounds of `desmos`.
8
+ */
3
9
  export declare function extract_viewport(desmos: Desmos.Calculator, blank: Desmos.Calculator): Ast.IncantationInvocation | null;
10
+ /**
11
+ * Extract an expression and the local incantations that reproduce its state.
12
+ */
4
13
  export declare function extract_expression(expression: Desmos.ExpressionState): Ast.Expression;
5
14
  //# sourceMappingURL=extract.d.ts.map
@@ -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;AAQhC,wBAAgB,gBAAgB,CAC7B,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,KAAK,EAAE,MAAM,CAAC,UAAU,GACxB,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAuBlC;AAKD,wBAAgB,gBAAgB,CAC7B,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,KAAK,EAAE,MAAM,CAAC,UAAU,GACxB,GAAG,CAAC,qBAAqB,GAAG,IAAI,CAkBlC;AAKD,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,eAAe,GAAG,GAAG,CAAC,UAAU,CAuBrF"}
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/decompiler/extract.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAKhC;;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,6 +1,9 @@
1
1
  import { stringify_json5, prettify_source } from "./format.js";
2
2
  import { Ast } from "../parser/index.js";
3
3
  import { DesmosIncantation, ViewportIncantation } from "../magic/global/index.js";
4
+ /**
5
+ * Extract a `/desmos` incantation from the settings of `desmos`.
6
+ */
4
7
  export function extract_settings(desmos, blank) {
5
8
  let defaults = blank.settings;
6
9
  let arg_raw = stringify_json5(desmos.settings, (k, v) => (v === defaults[k]
@@ -16,6 +19,9 @@ export function extract_settings(desmos, blank) {
16
19
  arg_raw,
17
20
  };
18
21
  }
22
+ /**
23
+ * Extract a `/viewport` incantation from the viewport bounds of `desmos`.
24
+ */
19
25
  export function extract_viewport(desmos, blank) {
20
26
  let defaults = blank.graphpaperBounds.mathCoordinates;
21
27
  let { left, right, bottom, top } = desmos.graphpaperBounds.mathCoordinates;
@@ -28,8 +34,12 @@ export function extract_viewport(desmos, blank) {
28
34
  arg_raw,
29
35
  };
30
36
  }
37
+ /**
38
+ * Extract an expression and the local incantations that reproduce its state.
39
+ */
31
40
  export function extract_expression(expression) {
32
41
  let data;
42
+ // @ts-expect-error: outdated types
33
43
  if (expression.latex?.trim() === "") {
34
44
  data = { latex: ` ` };
35
45
  }
@@ -43,7 +53,7 @@ export function extract_expression(expression) {
43
53
  return {
44
54
  kind: Ast.Kind.EXPRESSION,
45
55
  data,
46
- incantations: [],
56
+ incantations: [], // TODO
47
57
  };
48
58
  }
49
59
  function is_insignificant(key, value) {
@@ -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;AAEhC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAMzE,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;AAKD,MAAM,UAAU,gBAAgB,CAC7B,MAAyB,EACzB,KAAwB;IAGxB,IAAI,QAAQ,GAAG,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC;IACxD,IAAI,EAAE,IAAI,EAAE,KAAK,E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