desmost 0.7.3 → 0.8.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.
Files changed (167) 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 +15 -11
  8. package/dist/compiler/evaluate.js.map +1 -1
  9. package/dist/compiler/format.d.ts +13 -0
  10. package/dist/compiler/format.d.ts.map +1 -1
  11. package/dist/compiler/format.js +23 -0
  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 +20 -0
  20. package/dist/decompiler/decompile.d.ts.map +1 -0
  21. package/dist/decompiler/decompile.js +32 -0
  22. package/dist/decompiler/decompile.js.map +1 -0
  23. package/dist/decompiler/emit.d.ts +10 -0
  24. package/dist/decompiler/emit.d.ts.map +1 -0
  25. package/dist/decompiler/emit.js +37 -0
  26. package/dist/decompiler/emit.js.map +1 -0
  27. package/dist/decompiler/extract.d.ts +14 -0
  28. package/dist/decompiler/extract.d.ts.map +1 -0
  29. package/dist/decompiler/extract.js +63 -0
  30. package/dist/decompiler/extract.js.map +1 -0
  31. package/dist/decompiler/format.d.ts +3 -0
  32. package/dist/decompiler/format.d.ts.map +1 -0
  33. package/dist/decompiler/format.js +14 -0
  34. package/dist/decompiler/format.js.map +1 -0
  35. package/dist/decompiler/index.d.ts +2 -0
  36. package/dist/decompiler/index.d.ts.map +1 -0
  37. package/dist/decompiler/index.js +2 -0
  38. package/dist/decompiler/index.js.map +1 -0
  39. package/dist/desmos.d.ts +3 -0
  40. package/dist/desmos.d.ts.map +1 -1
  41. package/dist/desmos.js +3 -0
  42. package/dist/desmos.js.map +1 -1
  43. package/dist/errors.d.ts +18 -4
  44. package/dist/errors.d.ts.map +1 -1
  45. package/dist/errors.js +13 -1
  46. package/dist/errors.js.map +1 -1
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.internal.d.ts +2 -1
  50. package/dist/index.internal.d.ts.map +1 -1
  51. package/dist/index.internal.js +2 -1
  52. package/dist/index.internal.js.map +1 -1
  53. package/dist/index.js +1 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/magic/expr/index.js.map +1 -1
  56. package/dist/magic/expr/latex.d.ts.map +1 -1
  57. package/dist/magic/expr/latex.js +1 -0
  58. package/dist/magic/expr/latex.js.map +1 -1
  59. package/dist/magic/expr/text.d.ts.map +1 -1
  60. package/dist/magic/expr/text.js +1 -0
  61. package/dist/magic/expr/text.js.map +1 -1
  62. package/dist/magic/global/dark-mode.d.ts.map +1 -1
  63. package/dist/magic/global/dark-mode.js.map +1 -1
  64. package/dist/magic/global/desmos.d.ts +3 -1
  65. package/dist/magic/global/desmos.d.ts.map +1 -1
  66. package/dist/magic/global/desmos.js.map +1 -1
  67. package/dist/magic/global/index.d.ts +3 -0
  68. package/dist/magic/global/index.d.ts.map +1 -1
  69. package/dist/magic/global/index.js +3 -0
  70. package/dist/magic/global/index.js.map +1 -1
  71. package/dist/magic/global/viewport.d.ts.map +1 -1
  72. package/dist/magic/global/viewport.js +0 -1
  73. package/dist/magic/global/viewport.js.map +1 -1
  74. package/dist/magic/incantation.d.ts +44 -0
  75. package/dist/magic/incantation.d.ts.map +1 -1
  76. package/dist/magic/incantation.js +38 -0
  77. package/dist/magic/incantation.js.map +1 -1
  78. package/dist/magic/index.d.ts +7 -0
  79. package/dist/magic/index.d.ts.map +1 -1
  80. package/dist/magic/index.js +7 -0
  81. package/dist/magic/index.js.map +1 -1
  82. package/dist/magic/local/anim.d.ts.map +1 -1
  83. package/dist/magic/local/anim.js +1 -0
  84. package/dist/magic/local/anim.js.map +1 -1
  85. package/dist/magic/local/colour.d.ts.map +1 -1
  86. package/dist/magic/local/colour.js.map +1 -1
  87. package/dist/magic/local/dashed.d.ts.map +1 -1
  88. package/dist/magic/local/dashed.js.map +1 -1
  89. package/dist/magic/local/fill.d.ts.map +1 -1
  90. package/dist/magic/local/fill.js.map +1 -1
  91. package/dist/magic/local/hide.d.ts.map +1 -1
  92. package/dist/magic/local/hide.js.map +1 -1
  93. package/dist/magic/local/index.js.map +1 -1
  94. package/dist/magic/local/label.d.ts.map +1 -1
  95. package/dist/magic/local/label.js +1 -0
  96. package/dist/magic/local/label.js.map +1 -1
  97. package/dist/magic/local/line.d.ts.map +1 -1
  98. package/dist/magic/local/line.js.map +1 -1
  99. package/dist/magic/local/no-line.d.ts.map +1 -1
  100. package/dist/magic/local/no-line.js.map +1 -1
  101. package/dist/magic/local/point.d.ts.map +1 -1
  102. package/dist/magic/local/point.js.map +1 -1
  103. package/dist/magic/local/secret.d.ts.map +1 -1
  104. package/dist/magic/local/secret.js.map +1 -1
  105. package/dist/magic/local/slider.d.ts.map +1 -1
  106. package/dist/magic/local/slider.js +1 -0
  107. package/dist/magic/local/slider.js.map +1 -1
  108. package/dist/parser/ast.d.ts +9 -0
  109. package/dist/parser/ast.d.ts.map +1 -1
  110. package/dist/parser/ast.js +1 -0
  111. package/dist/parser/ast.js.map +1 -1
  112. package/dist/parser/desmost-parser.d.ts +101 -1
  113. package/dist/parser/desmost-parser.d.ts.map +1 -1
  114. package/dist/parser/desmost-parser.js +129 -2
  115. package/dist/parser/desmost-parser.js.map +1 -1
  116. package/dist/parser/generic-parser.d.ts +47 -0
  117. package/dist/parser/generic-parser.d.ts.map +1 -1
  118. package/dist/parser/generic-parser.js +50 -0
  119. package/dist/parser/generic-parser.js.map +1 -1
  120. package/dist/parser/index.d.ts.map +1 -1
  121. package/dist/parser/index.js.map +1 -1
  122. package/dist/utils.d.ts.map +1 -1
  123. package/dist/utils.js.map +1 -1
  124. package/package.json +5 -2
  125. package/src/compiler/compile.ts +124 -124
  126. package/src/compiler/evaluate.ts +86 -118
  127. package/src/compiler/format.ts +39 -6
  128. package/src/compiler/index.ts +0 -7
  129. package/src/compiler/options.ts +83 -77
  130. package/src/compiler/readme.md +5 -0
  131. package/src/decompiler/decompile.ts +48 -0
  132. package/src/decompiler/emit.ts +47 -0
  133. package/src/decompiler/extract.ts +100 -0
  134. package/src/decompiler/format.ts +20 -0
  135. package/src/decompiler/index.ts +1 -0
  136. package/src/decompiler/readme.md +34 -0
  137. package/src/desmos.ts +6 -6
  138. package/src/errors.ts +19 -19
  139. package/src/index.internal.ts +3 -1
  140. package/src/index.ts +1 -0
  141. package/src/magic/expr/index.ts +2 -2
  142. package/src/magic/expr/latex.ts +16 -16
  143. package/src/magic/expr/text.ts +13 -13
  144. package/src/magic/global/dark-mode.ts +10 -10
  145. package/src/magic/global/desmos.ts +18 -15
  146. package/src/magic/global/index.ts +8 -3
  147. package/src/magic/global/viewport.ts +19 -20
  148. package/src/magic/incantation.ts +94 -94
  149. package/src/magic/local/anim.ts +10 -10
  150. package/src/magic/local/colour.ts +26 -26
  151. package/src/magic/local/dashed.ts +9 -9
  152. package/src/magic/local/fill.ts +12 -12
  153. package/src/magic/local/hide.ts +9 -9
  154. package/src/magic/local/index.ts +11 -11
  155. package/src/magic/local/label.ts +51 -51
  156. package/src/magic/local/line.ts +16 -16
  157. package/src/magic/local/no-line.ts +9 -9
  158. package/src/magic/local/point.ts +16 -16
  159. package/src/magic/local/secret.ts +9 -9
  160. package/src/magic/local/slider.ts +15 -15
  161. package/src/magic/readme.md +5 -0
  162. package/src/parser/ast.ts +46 -46
  163. package/src/parser/desmost-parser.ts +550 -550
  164. package/src/parser/generic-parser.ts +176 -176
  165. package/src/parser/index.ts +0 -4
  166. package/src/parser/readme.md +21 -0
  167. package/src/utils.ts +33 -33
@@ -3,27 +3,27 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
3
3
 
4
4
  interface LineOptions
5
5
  {
6
- style?: keyof typeof Desmos.Styles; // TODO allow raw enum
7
- width?: number;
8
- opacity?: number;
6
+ style?: keyof typeof Desmos.Styles; // TODO allow raw enum
7
+ width?: number;
8
+ opacity?: number;
9
9
  }
10
10
 
11
11
 
12
12
  export class LineIncantation extends ArgIncantation<LOCAL>
13
13
  {
14
- override readonly description
15
- = "Change line styles for a rendered block."
14
+ override readonly description
15
+ = "Change line styles for a rendered block."
16
16
 
17
- override readonly identifier = "line"
18
- override readonly requires_arg = true
19
- override readonly arg_type = Incantation.ArgType.OBJECT
17
+ override readonly identifier = "line"
18
+ override readonly requires_arg = true
19
+ override readonly arg_type = Incantation.ArgType.OBJECT
20
20
 
21
- override apply(target: Desmos.ExpressionState, data: LineOptions)
22
- {
23
- super.require_expr_type(target.type, "expression");
24
-
25
- if (data.style != undefined) target.lineStyle = data.style;
26
- if (data.width != undefined) target.lineWidth = data.width;
27
- if (data.opacity != undefined) target.lineOpacity = data.opacity;
28
- }
21
+ override apply(target: Desmos.ExpressionState, data: LineOptions)
22
+ {
23
+ super.require_expr_type(target.type, "expression");
24
+
25
+ if (data.style != undefined) target.lineStyle = data.style;
26
+ if (data.width != undefined) target.lineWidth = data.width;
27
+ if (data.opacity != undefined) target.lineOpacity = data.opacity;
28
+ }
29
29
  }
@@ -3,14 +3,14 @@ import { Incantation, type LOCAL } from "../incantation";
3
3
 
4
4
  export class NoLineIncantation extends Incantation<LOCAL>
5
5
  {
6
- override readonly description
7
- = "Disable rendering lines for a block."
8
-
9
- override readonly identifier = "no-line"
6
+ override readonly description
7
+ = "Disable rendering lines for a block."
8
+
9
+ override readonly identifier = "no-line"
10
10
 
11
- override apply(target: Desmos.ExpressionState)
12
- {
13
- super.require_expr_type(target.type, "expression");
14
- target.lines = false;
15
- }
11
+ override apply(target: Desmos.ExpressionState)
12
+ {
13
+ super.require_expr_type(target.type, "expression");
14
+ target.lines = false;
15
+ }
16
16
  }
@@ -3,27 +3,27 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
3
3
 
4
4
  interface PointStyles
5
5
  {
6
- style?: keyof typeof Desmos.Styles;
7
- size?: number;
8
- opacity?: number;
6
+ style?: keyof typeof Desmos.Styles;
7
+ size?: number;
8
+ opacity?: number;
9
9
  }
10
10
 
11
11
 
12
12
  export class PointIncantation extends ArgIncantation<LOCAL>
13
13
  {
14
- override readonly description
15
- = ""
16
-
17
- override readonly identifier = "point"
18
- override readonly requires_arg = true
19
- override readonly arg_type = Incantation.ArgType.OBJECT
14
+ override readonly description
15
+ = ""
16
+
17
+ override readonly identifier = "point"
18
+ override readonly requires_arg = true
19
+ override readonly arg_type = Incantation.ArgType.OBJECT
20
20
 
21
- override apply(target: Desmos.ExpressionState, data: Partial<PointStyles>)
22
- {
23
- super.require_expr_type(target.type, "expression");
21
+ override apply(target: Desmos.ExpressionState, data: Partial<PointStyles>)
22
+ {
23
+ super.require_expr_type(target.type, "expression");
24
24
 
25
- if (data.style != undefined) target.pointStyle = data.style;
26
- if (data.size != undefined) target.pointSize = data.size;
27
- if (data.opacity != undefined) target.pointOpacity = data.opacity;
28
- }
25
+ if (data.style != undefined) target.pointStyle = data.style;
26
+ if (data.size != undefined) target.pointSize = data.size;
27
+ if (data.opacity != undefined) target.pointOpacity = data.opacity;
28
+ }
29
29
  }
@@ -3,14 +3,14 @@ import { Incantation, type LOCAL } from "../incantation";
3
3
 
4
4
  export class SecretIncantation extends Incantation<LOCAL>
5
5
  {
6
- override readonly description
7
- = "Turn a block into a secret expression, which is hidden from the end user."
8
-
9
- override readonly identifier = "secret"
6
+ override readonly description
7
+ = "Turn a block into a secret expression, which is hidden from the end user."
8
+
9
+ override readonly identifier = "secret"
10
10
 
11
- override apply(target: Desmos.ExpressionState)
12
- {
13
- super.require_expr_type(target.type, "expression");
14
- target.secret = true;
15
- }
11
+ override apply(target: Desmos.ExpressionState)
12
+ {
13
+ super.require_expr_type(target.type, "expression");
14
+ target.secret = true;
15
+ }
16
16
  }
@@ -3,25 +3,25 @@ import { Incantation, ArgIncantation, type LOCAL } from "../incantation";
3
3
 
4
4
  interface SliderBounds
5
5
  {
6
- min?: number | string;
7
- max?: number | string;
8
- step?: number | string;
6
+ min?: number | string;
7
+ max?: number | string;
8
+ step?: number | string;
9
9
  }
10
10
 
11
11
 
12
12
  export class SliderIncantation extends ArgIncantation<LOCAL>
13
13
  {
14
- override readonly description
15
- = "Set the bounds of the slider for a variable."
16
-
17
- override readonly identifier = "slider"
18
- override readonly requires_arg = true
19
- override readonly arg_type = Incantation.ArgType.OBJECT
14
+ override readonly description
15
+ = "Set the bounds of the slider for a variable."
16
+
17
+ override readonly identifier = "slider"
18
+ override readonly requires_arg = true
19
+ override readonly arg_type = Incantation.ArgType.OBJECT
20
20
 
21
- override apply(target: Desmos.ExpressionState, data: SliderBounds)
22
- {
23
- super.require_expr_type(target.type, "expression");
24
- // @ts-expect-error: outdated types
25
- target.sliderBounds = data;
26
- }
21
+ override apply(target: Desmos.ExpressionState, data: SliderBounds)
22
+ {
23
+ super.require_expr_type(target.type, "expression");
24
+ // @ts-expect-error: outdated types
25
+ target.sliderBounds = data;
26
+ }
27
27
  }
@@ -0,0 +1,5 @@
1
+ # Incantations
2
+
3
+ This module implements how incantations are represented, and the individual logic for every incantation in Desmost.
4
+
5
+ Each incantation is defined in its own file as a class deriving from `ArgIncantation` or `Incantation`. They can then implement whatever logic they require for `apply()` and `evaluate_arg()`.
package/src/parser/ast.ts CHANGED
@@ -4,57 +4,57 @@ import { Incantation, ArgIncantation } from "../magic";
4
4
 
5
5
  export namespace Ast
6
6
  {
7
- /** What kind of parse result this is. */
8
- export enum Kind
9
- {
10
- EXPRESSION = "Expression",
11
- INCANTATION_INVOCATION = "Incantation-Invocation",
12
- INVALID_INCANTATION = "Invalid-Incantation",
13
- }
7
+ /** What kind of AST node this is. */
8
+ export enum Kind
9
+ {
10
+ EXPRESSION = "Expression",
11
+ INCANTATION_INVOCATION = "Incantation-Invocation",
12
+ INVALID_INCANTATION = "Invalid-Incantation",
13
+ }
14
14
 
15
-
16
- /** A Desmos expression to add to the calculator. */
17
- export interface Expression
18
- {
19
- kind: Kind.EXPRESSION
20
- data: Desmos.ExpressionState
21
- incantations: Array<
22
- | IncantationInvocation<Incantation.Effect.LOCAL>
23
- | InvalidInvocation
24
- >
25
- }
15
+
16
+ /** A Desmos expression to add to the calculator. */
17
+ export interface Expression
18
+ {
19
+ kind: Kind.EXPRESSION
20
+ data: Desmos.ExpressionState
21
+ incantations: Array<
22
+ | IncantationInvocation<Incantation.Effect.LOCAL>
23
+ | InvalidInvocation
24
+ >
25
+ }
26
26
 
27
27
 
28
- /** A pending incantation invocation that requires applying its argument (if any), then applying its effect. */
29
- export type IncantationInvocation<Effect extends Incantation.Effect = Incantation.Effect> =
30
- | {
31
- kind: Kind.INCANTATION_INVOCATION
32
- incantation: Incantation<Effect>
33
- arg_raw: undefined
34
- }
35
- | {
36
- kind: Kind.INCANTATION_INVOCATION
37
- incantation: ArgIncantation<Effect>
38
- arg_raw: string | undefined
39
- };
28
+ /** A pending incantation invocation that requires applying its argument (if any), then applying its effect. */
29
+ export type IncantationInvocation<Effect extends Incantation.Effect = Incantation.Effect> =
30
+ | {
31
+ kind: Kind.INCANTATION_INVOCATION
32
+ incantation: Incantation<Effect>
33
+ arg_raw: undefined
34
+ }
35
+ | {
36
+ kind: Kind.INCANTATION_INVOCATION
37
+ incantation: ArgIncantation<Effect>
38
+ arg_raw: string | undefined
39
+ };
40
40
 
41
- /**
42
- * An invalid invantation invocation that raised an error when parsed.
43
- *
44
- * This will be propogated to the user as an extra Desmos text expression (unless they have `errors: false` configured).
45
- */
46
- export interface InvalidInvocation
47
- {
48
- kind: Kind.INVALID_INCANTATION
49
- incantation: Incantation
50
- arg_raw?: string
51
- error: UnrecoverableError
52
- }
41
+ /**
42
+ * An invalid invantation invocation that raised an error when parsed.
43
+ *
44
+ * This will be propogated to the user as an extra Desmos text expression (unless they have `errors: "suppress"` configured).
45
+ */
46
+ export interface InvalidInvocation
47
+ {
48
+ kind: Kind.INVALID_INCANTATION
49
+ incantation: Incantation
50
+ arg_raw?: string
51
+ error: UnrecoverableError
52
+ }
53
53
  }
54
54
 
55
- /** An abstract object produced by parsing a block of source code. */
55
+ /** An abstract object produced by the parser. */
56
56
  export type Ast =
57
- | Ast.Expression
58
- | Ast.IncantationInvocation
59
- | Ast.InvalidInvocation
57
+ | Ast.Expression
58
+ | Ast.IncantationInvocation
59
+ | Ast.InvalidInvocation
60
60
  ;