desmost 0.1.0

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 (281) hide show
  1. package/dist/compiler/compile.d.ts +32 -0
  2. package/dist/compiler/compile.d.ts.map +1 -0
  3. package/dist/compiler/compile.js +101 -0
  4. package/dist/compiler/compile.js.map +1 -0
  5. package/dist/compiler/evaluate.d.ts +18 -0
  6. package/dist/compiler/evaluate.d.ts.map +1 -0
  7. package/dist/compiler/evaluate.js +83 -0
  8. package/dist/compiler/evaluate.js.map +1 -0
  9. package/dist/compiler/index.d.ts +3 -0
  10. package/dist/compiler/index.d.ts.map +1 -0
  11. package/dist/compiler/index.js +2 -0
  12. package/dist/compiler/index.js.map +1 -0
  13. package/dist/compiler/options.d.ts +54 -0
  14. package/dist/compiler/options.d.ts.map +1 -0
  15. package/dist/compiler/options.js +15 -0
  16. package/dist/compiler/options.js.map +1 -0
  17. package/dist/desmos.d.ts +12 -0
  18. package/dist/desmos.d.ts.map +1 -0
  19. package/dist/desmos.js +13 -0
  20. package/dist/desmos.js.map +1 -0
  21. package/dist/errors.d.ts +45 -0
  22. package/dist/errors.d.ts.map +1 -0
  23. package/dist/errors.js +38 -0
  24. package/dist/errors.js.map +1 -0
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +2 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/magic/expr/index.d.ts +3 -0
  30. package/dist/magic/expr/index.d.ts.map +1 -0
  31. package/dist/magic/expr/index.js +8 -0
  32. package/dist/magic/expr/index.js.map +1 -0
  33. package/dist/magic/expr/latex.d.ts +10 -0
  34. package/dist/magic/expr/latex.d.ts.map +1 -0
  35. package/dist/magic/expr/latex.js +16 -0
  36. package/dist/magic/expr/latex.js.map +1 -0
  37. package/dist/magic/expr/text.d.ts +9 -0
  38. package/dist/magic/expr/text.d.ts.map +1 -0
  39. package/dist/magic/expr/text.js +13 -0
  40. package/dist/magic/expr/text.js.map +1 -0
  41. package/dist/magic/global/dark-mode.d.ts +7 -0
  42. package/dist/magic/global/dark-mode.d.ts.map +1 -0
  43. package/dist/magic/global/dark-mode.js +11 -0
  44. package/dist/magic/global/dark-mode.js.map +1 -0
  45. package/dist/magic/global/desmos.d.ts +9 -0
  46. package/dist/magic/global/desmos.d.ts.map +1 -0
  47. package/dist/magic/global/desmos.js +11 -0
  48. package/dist/magic/global/desmos.js.map +1 -0
  49. package/dist/magic/global/index.d.ts +3 -0
  50. package/dist/magic/global/index.d.ts.map +1 -0
  51. package/dist/magic/global/index.js +10 -0
  52. package/dist/magic/global/index.js.map +1 -0
  53. package/dist/magic/global/viewport.d.ts +16 -0
  54. package/dist/magic/global/viewport.d.ts.map +1 -0
  55. package/dist/magic/global/viewport.js +12 -0
  56. package/dist/magic/global/viewport.js.map +1 -0
  57. package/dist/magic/incantation.d.ts +74 -0
  58. package/dist/magic/incantation.d.ts.map +1 -0
  59. package/dist/magic/incantation.js +81 -0
  60. package/dist/magic/incantation.js.map +1 -0
  61. package/dist/magic/index.d.ts +6 -0
  62. package/dist/magic/index.d.ts.map +1 -0
  63. package/dist/magic/index.js +5 -0
  64. package/dist/magic/index.js.map +1 -0
  65. package/dist/magic/local/anim.d.ts +7 -0
  66. package/dist/magic/local/anim.d.ts.map +1 -0
  67. package/dist/magic/local/anim.js +11 -0
  68. package/dist/magic/local/anim.js.map +1 -0
  69. package/dist/magic/local/colour.d.ts +12 -0
  70. package/dist/magic/local/colour.d.ts.map +1 -0
  71. package/dist/magic/local/colour.js +27 -0
  72. package/dist/magic/local/colour.js.map +1 -0
  73. package/dist/magic/local/dashed.d.ts +7 -0
  74. package/dist/magic/local/dashed.d.ts.map +1 -0
  75. package/dist/magic/local/dashed.js +10 -0
  76. package/dist/magic/local/dashed.js.map +1 -0
  77. package/dist/magic/local/fill.d.ts +13 -0
  78. package/dist/magic/local/fill.d.ts.map +1 -0
  79. package/dist/magic/local/fill.js +12 -0
  80. package/dist/magic/local/fill.js.map +1 -0
  81. package/dist/magic/local/hide.d.ts +7 -0
  82. package/dist/magic/local/hide.d.ts.map +1 -0
  83. package/dist/magic/local/hide.js +10 -0
  84. package/dist/magic/local/hide.js.map +1 -0
  85. package/dist/magic/local/index.d.ts +3 -0
  86. package/dist/magic/local/index.d.ts.map +1 -0
  87. package/dist/magic/local/index.js +24 -0
  88. package/dist/magic/local/index.js.map +1 -0
  89. package/dist/magic/local/line.d.ts +15 -0
  90. package/dist/magic/local/line.d.ts.map +1 -0
  91. package/dist/magic/local/line.js +17 -0
  92. package/dist/magic/local/line.js.map +1 -0
  93. package/dist/magic/local/no-line.d.ts +7 -0
  94. package/dist/magic/local/no-line.d.ts.map +1 -0
  95. package/dist/magic/local/no-line.js +10 -0
  96. package/dist/magic/local/no-line.js.map +1 -0
  97. package/dist/magic/local/point.d.ts +15 -0
  98. package/dist/magic/local/point.d.ts.map +1 -0
  99. package/dist/magic/local/point.js +17 -0
  100. package/dist/magic/local/point.js.map +1 -0
  101. package/dist/magic/local/secret.d.ts +7 -0
  102. package/dist/magic/local/secret.d.ts.map +1 -0
  103. package/dist/magic/local/secret.js +10 -0
  104. package/dist/magic/local/secret.js.map +1 -0
  105. package/dist/magic/local/slider.d.ts +15 -0
  106. package/dist/magic/local/slider.d.ts.map +1 -0
  107. package/dist/magic/local/slider.js +13 -0
  108. package/dist/magic/local/slider.js.map +1 -0
  109. package/dist/parser/ast.d.ts +40 -0
  110. package/dist/parser/ast.d.ts.map +1 -0
  111. package/dist/parser/ast.js +13 -0
  112. package/dist/parser/ast.js.map +1 -0
  113. package/dist/parser/desmost-parser.d.ts +105 -0
  114. package/dist/parser/desmost-parser.d.ts.map +1 -0
  115. package/dist/parser/desmost-parser.js +379 -0
  116. package/dist/parser/desmost-parser.js.map +1 -0
  117. package/dist/parser/generic-parser.d.ts +62 -0
  118. package/dist/parser/generic-parser.d.ts.map +1 -0
  119. package/dist/parser/generic-parser.js +143 -0
  120. package/dist/parser/generic-parser.js.map +1 -0
  121. package/dist/parser/index.d.ts +8 -0
  122. package/dist/parser/index.d.ts.map +1 -0
  123. package/dist/parser/index.js +8 -0
  124. package/dist/parser/index.js.map +1 -0
  125. package/dist/src/compiler/compile.d.ts +32 -0
  126. package/dist/src/compiler/compile.d.ts.map +1 -0
  127. package/dist/src/compiler/compile.js +101 -0
  128. package/dist/src/compiler/compile.js.map +1 -0
  129. package/dist/src/compiler/evaluate.d.ts +18 -0
  130. package/dist/src/compiler/evaluate.d.ts.map +1 -0
  131. package/dist/src/compiler/evaluate.js +83 -0
  132. package/dist/src/compiler/evaluate.js.map +1 -0
  133. package/dist/src/compiler/index.d.ts +3 -0
  134. package/dist/src/compiler/index.d.ts.map +1 -0
  135. package/dist/src/compiler/index.js +2 -0
  136. package/dist/src/compiler/index.js.map +1 -0
  137. package/dist/src/compiler/options.d.ts +54 -0
  138. package/dist/src/compiler/options.d.ts.map +1 -0
  139. package/dist/src/compiler/options.js +15 -0
  140. package/dist/src/compiler/options.js.map +1 -0
  141. package/dist/src/desmos.d.ts +12 -0
  142. package/dist/src/desmos.d.ts.map +1 -0
  143. package/dist/src/desmos.js +13 -0
  144. package/dist/src/desmos.js.map +1 -0
  145. package/dist/src/errors.d.ts +45 -0
  146. package/dist/src/errors.d.ts.map +1 -0
  147. package/dist/src/errors.js +38 -0
  148. package/dist/src/errors.js.map +1 -0
  149. package/dist/src/index.d.ts +2 -0
  150. package/dist/src/index.d.ts.map +1 -0
  151. package/dist/src/index.js +2 -0
  152. package/dist/src/index.js.map +1 -0
  153. package/dist/src/magic/expr/index.d.ts +3 -0
  154. package/dist/src/magic/expr/index.d.ts.map +1 -0
  155. package/dist/src/magic/expr/index.js +8 -0
  156. package/dist/src/magic/expr/index.js.map +1 -0
  157. package/dist/src/magic/expr/latex.d.ts +10 -0
  158. package/dist/src/magic/expr/latex.d.ts.map +1 -0
  159. package/dist/src/magic/expr/latex.js +16 -0
  160. package/dist/src/magic/expr/latex.js.map +1 -0
  161. package/dist/src/magic/expr/text.d.ts +9 -0
  162. package/dist/src/magic/expr/text.d.ts.map +1 -0
  163. package/dist/src/magic/expr/text.js +13 -0
  164. package/dist/src/magic/expr/text.js.map +1 -0
  165. package/dist/src/magic/global/dark-mode.d.ts +7 -0
  166. package/dist/src/magic/global/dark-mode.d.ts.map +1 -0
  167. package/dist/src/magic/global/dark-mode.js +11 -0
  168. package/dist/src/magic/global/dark-mode.js.map +1 -0
  169. package/dist/src/magic/global/desmos.d.ts +9 -0
  170. package/dist/src/magic/global/desmos.d.ts.map +1 -0
  171. package/dist/src/magic/global/desmos.js +11 -0
  172. package/dist/src/magic/global/desmos.js.map +1 -0
  173. package/dist/src/magic/global/index.d.ts +3 -0
  174. package/dist/src/magic/global/index.d.ts.map +1 -0
  175. package/dist/src/magic/global/index.js +10 -0
  176. package/dist/src/magic/global/index.js.map +1 -0
  177. package/dist/src/magic/global/viewport.d.ts +16 -0
  178. package/dist/src/magic/global/viewport.d.ts.map +1 -0
  179. package/dist/src/magic/global/viewport.js +12 -0
  180. package/dist/src/magic/global/viewport.js.map +1 -0
  181. package/dist/src/magic/incantation.d.ts +74 -0
  182. package/dist/src/magic/incantation.d.ts.map +1 -0
  183. package/dist/src/magic/incantation.js +81 -0
  184. package/dist/src/magic/incantation.js.map +1 -0
  185. package/dist/src/magic/index.d.ts +6 -0
  186. package/dist/src/magic/index.d.ts.map +1 -0
  187. package/dist/src/magic/index.js +5 -0
  188. package/dist/src/magic/index.js.map +1 -0
  189. package/dist/src/magic/local/anim.d.ts +7 -0
  190. package/dist/src/magic/local/anim.d.ts.map +1 -0
  191. package/dist/src/magic/local/anim.js +11 -0
  192. package/dist/src/magic/local/anim.js.map +1 -0
  193. package/dist/src/magic/local/colour.d.ts +12 -0
  194. package/dist/src/magic/local/colour.d.ts.map +1 -0
  195. package/dist/src/magic/local/colour.js +27 -0
  196. package/dist/src/magic/local/colour.js.map +1 -0
  197. package/dist/src/magic/local/dashed.d.ts +7 -0
  198. package/dist/src/magic/local/dashed.d.ts.map +1 -0
  199. package/dist/src/magic/local/dashed.js +10 -0
  200. package/dist/src/magic/local/dashed.js.map +1 -0
  201. package/dist/src/magic/local/fill.d.ts +13 -0
  202. package/dist/src/magic/local/fill.d.ts.map +1 -0
  203. package/dist/src/magic/local/fill.js +12 -0
  204. package/dist/src/magic/local/fill.js.map +1 -0
  205. package/dist/src/magic/local/hide.d.ts +7 -0
  206. package/dist/src/magic/local/hide.d.ts.map +1 -0
  207. package/dist/src/magic/local/hide.js +10 -0
  208. package/dist/src/magic/local/hide.js.map +1 -0
  209. package/dist/src/magic/local/index.d.ts +3 -0
  210. package/dist/src/magic/local/index.d.ts.map +1 -0
  211. package/dist/src/magic/local/index.js +24 -0
  212. package/dist/src/magic/local/index.js.map +1 -0
  213. package/dist/src/magic/local/line.d.ts +15 -0
  214. package/dist/src/magic/local/line.d.ts.map +1 -0
  215. package/dist/src/magic/local/line.js +17 -0
  216. package/dist/src/magic/local/line.js.map +1 -0
  217. package/dist/src/magic/local/no-line.d.ts +7 -0
  218. package/dist/src/magic/local/no-line.d.ts.map +1 -0
  219. package/dist/src/magic/local/no-line.js +10 -0
  220. package/dist/src/magic/local/no-line.js.map +1 -0
  221. package/dist/src/magic/local/point.d.ts +15 -0
  222. package/dist/src/magic/local/point.d.ts.map +1 -0
  223. package/dist/src/magic/local/point.js +17 -0
  224. package/dist/src/magic/local/point.js.map +1 -0
  225. package/dist/src/magic/local/secret.d.ts +7 -0
  226. package/dist/src/magic/local/secret.d.ts.map +1 -0
  227. package/dist/src/magic/local/secret.js +10 -0
  228. package/dist/src/magic/local/secret.js.map +1 -0
  229. package/dist/src/magic/local/slider.d.ts +15 -0
  230. package/dist/src/magic/local/slider.d.ts.map +1 -0
  231. package/dist/src/magic/local/slider.js +13 -0
  232. package/dist/src/magic/local/slider.js.map +1 -0
  233. package/dist/src/parser/ast.d.ts +40 -0
  234. package/dist/src/parser/ast.d.ts.map +1 -0
  235. package/dist/src/parser/ast.js +13 -0
  236. package/dist/src/parser/ast.js.map +1 -0
  237. package/dist/src/parser/desmost-parser.d.ts +105 -0
  238. package/dist/src/parser/desmost-parser.d.ts.map +1 -0
  239. package/dist/src/parser/desmost-parser.js +379 -0
  240. package/dist/src/parser/desmost-parser.js.map +1 -0
  241. package/dist/src/parser/generic-parser.d.ts +62 -0
  242. package/dist/src/parser/generic-parser.d.ts.map +1 -0
  243. package/dist/src/parser/generic-parser.js +143 -0
  244. package/dist/src/parser/generic-parser.js.map +1 -0
  245. package/dist/src/parser/index.d.ts +8 -0
  246. package/dist/src/parser/index.d.ts.map +1 -0
  247. package/dist/src/parser/index.js +8 -0
  248. package/dist/src/parser/index.js.map +1 -0
  249. package/package.json +58 -0
  250. package/src/compiler/compile.ts +127 -0
  251. package/src/compiler/evaluate.ts +121 -0
  252. package/src/compiler/index.ts +2 -0
  253. package/src/compiler/options.ts +77 -0
  254. package/src/desmos.ts +13 -0
  255. package/src/errors.ts +46 -0
  256. package/src/index.ts +1 -0
  257. package/src/magic/.template.ts +22 -0
  258. package/src/magic/expr/index.ts +11 -0
  259. package/src/magic/expr/latex.ts +24 -0
  260. package/src/magic/expr/text.ts +19 -0
  261. package/src/magic/global/dark-mode.ts +17 -0
  262. package/src/magic/global/desmos.ts +20 -0
  263. package/src/magic/global/index.ts +13 -0
  264. package/src/magic/global/viewport.ts +25 -0
  265. package/src/magic/incantation.ts +142 -0
  266. package/src/magic/index.ts +6 -0
  267. package/src/magic/local/anim.ts +17 -0
  268. package/src/magic/local/colour.ts +38 -0
  269. package/src/magic/local/dashed.ts +16 -0
  270. package/src/magic/local/fill.ts +24 -0
  271. package/src/magic/local/hide.ts +16 -0
  272. package/src/magic/local/index.ts +27 -0
  273. package/src/magic/local/line.ts +29 -0
  274. package/src/magic/local/no-line.ts +16 -0
  275. package/src/magic/local/point.ts +29 -0
  276. package/src/magic/local/secret.ts +16 -0
  277. package/src/magic/local/slider.ts +27 -0
  278. package/src/parser/ast.ts +60 -0
  279. package/src/parser/desmost-parser.ts +486 -0
  280. package/src/parser/generic-parser.ts +191 -0
  281. package/src/parser/index.ts +8 -0
@@ -0,0 +1,62 @@
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
+ */
7
+ export declare class GenericParser {
8
+ /** The source code this parser is parsing. */
9
+ protected source: string;
10
+ /** The current position in the source code the parser is pointing to. */
11
+ protected i: number;
12
+ /** The number of characters in the source code. */
13
+ protected length: number;
14
+ /** Create a parser for parsing `source`. */
15
+ constructor(source: string);
16
+ /**
17
+ * Is the parser currently pointing at an invalid character?
18
+ */
19
+ 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
+ protected get current(): string | undefined;
24
+ /**
25
+ * Get the character *after* the current one that the parser points at.
26
+ */
27
+ protected next(): string | undefined;
28
+ /**
29
+ * Peek a snippet of the upcoming source text (for error messages).
30
+ */
31
+ 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
+ protected advance(error_msg?: string): Unrecoverable<void>;
38
+ /**
39
+ * Attempt to advance to the next character, skipping ignored characters.
40
+ */
41
+ protected try_advance(): Recoverable<void>;
42
+ /**
43
+ * Consume `raw`, erroring if `raw` was not found.
44
+ */
45
+ 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
+ protected try_consume(raw: string): Recoverable<void>;
50
+ /**
51
+ * Consume 0 or more space characters.
52
+ */
53
+ protected consume_spaces(): void;
54
+ /**
55
+ * Consume 0 or more whitespace characters.
56
+ *
57
+ * Same as `.consume_spaces()`, but allows newlines.
58
+ */
59
+ protected consume_whitespace(): void;
60
+ protected consume_end_of_block(error_msg?: string): Unrecoverable<void>;
61
+ }
62
+ //# sourceMappingURL=generic-parser.d.ts.map
@@ -0,0 +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;AAQ5D;;;;GAIG;AACH,qBAAa,aAAa;IAExB,8CAA8C;IAC9C,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IAEzB,yEAAyE;IACzE,SAAS,CAAC,CAAC,EAAE,MAAM,CAAK;IAExB,mDAAmD;IACnD,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IAGzB,4CAA4C;IAC5C,YAAY,MAAM,EAAE,MAAM,EAIzB;IAGD;;OAEG;IACH,SAAS,CAAC,aAAa,IAAI,OAAO,CAGjC;IAED;;OAEG;IACH,SAAS,KAAK,OAAO,IAAI,MAAM,GAAG,SAAS,CAG1C;IAED;;OAEG;IACH,SAAS,CAAC,IAAI,IAAI,MAAM,GAAG,SAAS,CAGnC;IAED;;OAEG;IACI,OAAO,IAAI,MAAM,CAGvB;IAED;;;;OAIG;IACH,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAYzD;IAED;;OAEG;IACH,SAAS,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,CAAC,CAQzC;IAED;;OAEG;IACH,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAsBtE;IAED;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAepD;IAED;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,IAAI,CAQ/B;IAED;;;;OAIG;IACH,SAAS,CAAC,kBAAkB,IAAI,IAAI,CAQnC;IAED,SAAS,CAAC,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAgBtE;CACF"}
@@ -0,0 +1,143 @@
1
+ import { RecoverableFail, UnrecoverableError } from "../errors";
2
+ const IGNORED_CHARACTERS = new Set([
3
+ "\r",
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
+ export class GenericParser {
11
+ /** The source code this parser is parsing. */
12
+ source;
13
+ /** The current position in the source code the parser is pointing to. */
14
+ i = 0;
15
+ /** The number of characters in the source code. */
16
+ length;
17
+ /** Create a parser for parsing `source`. */
18
+ constructor(source) {
19
+ this.source = source;
20
+ this.length = source.length;
21
+ }
22
+ /**
23
+ * Is the parser currently pointing at an invalid character?
24
+ */
25
+ out_of_bounds() {
26
+ return this.i >= this.length;
27
+ }
28
+ /**
29
+ * Get the character the parser is currently pointing at, or `undefined` if the parser is out-of-bounds.
30
+ */
31
+ get current() {
32
+ return this.source.at(this.i);
33
+ }
34
+ /**
35
+ * Get the character *after* the current one that the parser points at.
36
+ */
37
+ next() {
38
+ return this.source.at(this.i + 1);
39
+ }
40
+ /**
41
+ * Peek a snippet of the upcoming source text (for error messages).
42
+ */
43
+ preview() {
44
+ return this.source.slice(this.i, this.i + 20) + "...";
45
+ }
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
+ advance(error_msg) {
52
+ if (this.out_of_bounds()) {
53
+ throw new UnrecoverableError.UnexpectedEnd(error_msg ?? "Unexpected end of input");
54
+ }
55
+ this.i++;
56
+ // @ts-expect-error: `this.current == undefined` is a true negative
57
+ if (IGNORED_CHARACTERS.has(this.current)) {
58
+ this.advance();
59
+ }
60
+ }
61
+ /**
62
+ * Attempt to advance to the next character, skipping ignored characters.
63
+ */
64
+ try_advance() {
65
+ try {
66
+ this.advance();
67
+ }
68
+ catch {
69
+ throw new RecoverableFail();
70
+ }
71
+ }
72
+ /**
73
+ * Consume `raw`, erroring if `raw` was not found.
74
+ */
75
+ consume(raw, error_msg) {
76
+ if (this.out_of_bounds()) {
77
+ throw new UnrecoverableError.UnexpectedEnd(`Unexpected end of input while trying to consume: \`${raw}\``);
78
+ }
79
+ let ii = 0;
80
+ while (this.current === raw[ii]) {
81
+ this.advance(`Unexpected end of input while trying to consume: \`${raw}\``);
82
+ ii++;
83
+ if (ii === raw.length)
84
+ return;
85
+ }
86
+ throw new UnrecoverableError.UnexpectedInput(error_msg ?? `Expected: \`${raw}\`, but found: \`${this.preview()}\``);
87
+ }
88
+ /**
89
+ * Attempt to consume `raw`, backtracking and throwing if `raw` was not found.
90
+ */
91
+ try_consume(raw) {
92
+ let init = this.i;
93
+ let ii = 0;
94
+ while (this.current === raw[ii]) {
95
+ this.try_advance();
96
+ ii++;
97
+ if (ii === raw.length)
98
+ return;
99
+ if (this.i === this.length)
100
+ break;
101
+ }
102
+ this.i = init;
103
+ throw new RecoverableFail();
104
+ }
105
+ /**
106
+ * Consume 0 or more space characters.
107
+ */
108
+ 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
+ if (this.out_of_bounds())
111
+ return;
112
+ while (this.current === " ") {
113
+ this.advance();
114
+ }
115
+ }
116
+ /**
117
+ * Consume 0 or more whitespace characters.
118
+ *
119
+ * Same as `.consume_spaces()`, but allows newlines.
120
+ */
121
+ 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
+ if (this.i >= this.length)
124
+ return;
125
+ while (this.current === " " || this.current === "\n") {
126
+ this.advance();
127
+ }
128
+ }
129
+ consume_end_of_block(error_msg) {
130
+ if (this.i >= this.length)
131
+ return;
132
+ this.consume_spaces();
133
+ try {
134
+ this.try_consume("\n");
135
+ }
136
+ catch (e) {
137
+ if (!(e instanceof RecoverableFail))
138
+ throw e;
139
+ throw new UnrecoverableError.ExcessInput(error_msg ?? `Expected end of block, but found: \`${this.preview()}\``);
140
+ }
141
+ }
142
+ }
143
+ //# sourceMappingURL=generic-parser.js.map
@@ -0,0 +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;AAGH;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAExB,8CAA8C;IACpC,MAAM,CAAS;IAEzB,yEAAyE;IAC/D,CAAC,GAAW,CAAC,CAAC;IAExB,mDAAmD;IACzC,MAAM,CAAS;IAGzB,4CAA4C;IAC5C,YAAY,MAAc;QAExB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAGD;;OAEG;IACO,aAAa;QAErB,OAAO,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAc,OAAO;QAEnB,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACO,IAAI;QAEZ,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACI,OAAO;QAEZ,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC;I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AC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Implements `DesmostParser`, the Desmost parsing engine.
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";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Implements `DesmostParser`, the Desmost parsing engine.
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";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,32 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,101 @@
1
+ import { set_default_options } from "./options";
2
+ import { evaluate_global_incantation, evaluate_expr, evaluate_error } from "./evaluate";
3
+ import { DesmostParser, Ast } from "../parser";
4
+ import { UnrecoverableError } from "../errors";
5
+ /**
6
+ * Compile Desmost into Desmos.
7
+ *
8
+ * This calls the Desmost compiler: parsing and evaluating `source`, then injecting the results into an existing `desmos` instance. Pass in `options` to customise compilation.
9
+ *
10
+ * ## Example
11
+ *
12
+ * ```ts
13
+ * let calc = Desmos.GraphingCalculator();
14
+ *
15
+ * compile(calc, `/text{ sup world! }`);
16
+ *
17
+ * compile(calc, `/slider{ error! } :: t = 0`, {
18
+ * errors: "crash",
19
+ * });
20
+ * ```
21
+ */
22
+ export function compile(
23
+ /** The Desmos calculator instance to compile into. */
24
+ desmos,
25
+ /** The Desmost source code to compile. */
26
+ source,
27
+ /** Compilation options. */
28
+ options) {
29
+ if (desmos == undefined) {
30
+ console.error(`Desmost: No \`Desmos.Calculator\` instance provided, aborting compilation!`);
31
+ return;
32
+ }
33
+ if (source == undefined) {
34
+ console.error(`Desmost: No source code provided, aborting compilation!`);
35
+ return;
36
+ }
37
+ let t_init = performance.now();
38
+ let ast = [];
39
+ let opts = set_default_options(options);
40
+ let parser = new DesmostParser(source, opts);
41
+ /* To aggregate errors at the start, we need a target to retroactively inject errors into */
42
+ if (opts.place_errors === "start") {
43
+ desmos.setExpression({ id: "deferred-start", latex: "" });
44
+ }
45
+ let errors = [];
46
+ try {
47
+ while (true) {
48
+ let r = parser.parse_next();
49
+ if (r === null)
50
+ break;
51
+ if (opts.debug) {
52
+ ast.push(r);
53
+ }
54
+ let defer;
55
+ switch (r.kind) {
56
+ case Ast.Kind.INCANTATION_INVOCATION:
57
+ defer = evaluate_global_incantation(r, desmos, opts);
58
+ break;
59
+ case Ast.Kind.EXPRESSION:
60
+ defer = evaluate_expr(r, desmos, opts);
61
+ break;
62
+ case Ast.Kind.INVALID_INCANTATION:
63
+ defer = evaluate_error(r.error, desmos, opts);
64
+ break;
65
+ }
66
+ if (defer !== undefined) {
67
+ errors.push(defer);
68
+ }
69
+ }
70
+ }
71
+ catch (e) {
72
+ if (e instanceof UnrecoverableError) {
73
+ errors = [e.message];
74
+ }
75
+ else {
76
+ throw e;
77
+ }
78
+ }
79
+ if (errors.length > 0) {
80
+ let expr = {
81
+ type: "text",
82
+ text: errors.join("\n\n"),
83
+ };
84
+ switch (opts.place_errors) {
85
+ case "start":
86
+ desmos.setExpression({ ...expr, id: "deferred-start" });
87
+ break;
88
+ case "end":
89
+ case "inline":
90
+ desmos.setExpression(expr);
91
+ break;
92
+ }
93
+ }
94
+ if (opts.debug) {
95
+ return {
96
+ duration: performance.now() - t_init,
97
+ ast,
98
+ };
99
+ }
100
+ }
101
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../src/compiler/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAExF,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAG/C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO;AACrB,sDAAsD;AACtD,MAAyB;AAEzB,0CAA0C;AAC1C,MAAc;AAEd,2BAA2B;AAC3B,OAAwB;IAGxB,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,4EAA4E,CAAC,CAAC;QAC5F,OAAO;IACT,CAAC;IAED,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QACzE,OAAO;IACT,CAAC;IAED,IAAI,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAC/B,IAAI,GAAG,GAAG,EAAE,CAAC;IAEb,IAAI,IAAI,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,MAAM,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE7C,4FAA4F;IAC5F,IAAI,IAAI,CAAC,YAAY,KAAK,OAAO,EAAE,CAAC;QAClC,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,MAAM,GAAG,EAAE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QAEF,QAAQ,IAAI,CAAC,YAAY,EAAE,CAAC;YAC1B,KAAK,OAAO;gBACV,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;gBACxD,MAAM;YACR,KAAK,KAAK,CAAC;YACX,KAAK,QAAQ;gBACX,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;gBAC3B,MAAM;QACV,CAAC;IACH,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,OAAO;YACL,QAAQ,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,MAAM;YACpC,GAAG;SACJ,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { DesmostOptions } from "./options";
2
+ import { Ast } from "../parser";
3
+ import { UnrecoverableError, type Unrecoverable } from "../errors";
4
+ /**
5
+ * Evaluate arguments (if any) to a global incantation `invocation`, then apply the incantation to `desmos`.
6
+ */
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
+ */
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
+ */
17
+ export declare function evaluate_error(error: UnrecoverableError, desmos: Desmos.Calculator, options: Required<DesmostOptions>): Unrecoverable<void | string>;
18
+ //# sourceMappingURL=evaluate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../src/compiler/evaluate.ts"],"names":[],"mappings":"AAAA,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,CACzC,UAAU,EAAE,GAAG,CAAC,qBAAqB,EACrC,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAChC,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CAiB9B;AAGD;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAChC,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CAgC9B;AAGD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,MAAM,CAAC,UAAU,EACzB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,GAChC,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,CAuB9B"}
@@ -0,0 +1,83 @@
1
+ import { Ast } from "../parser";
2
+ import { UnrecoverableError } from "../errors";
3
+ /**
4
+ * Evaluate arguments (if any) to a global incantation `invocation`, then apply the incantation to `desmos`.
5
+ */
6
+ export function evaluate_global_incantation(invocation, desmos, options) {
7
+ let data = undefined;
8
+ if ("arg_raw" in invocation && invocation.arg_raw != undefined) {
9
+ try {
10
+ data = invocation.incantation.evaluate_arg(invocation.arg_raw);
11
+ }
12
+ catch (e) {
13
+ let msg = evaluate_error(e, desmos, options);
14
+ if (msg != undefined) {
15
+ return msg;
16
+ }
17
+ }
18
+ }
19
+ invocation.incantation.apply(desmos, data);
20
+ }
21
+ /**
22
+ * Evaluate arguments (if any) to local incantation invocations on `expr`, then add `expr` to `desmos`.
23
+ */
24
+ export function evaluate_expr(expr, desmos, options) {
25
+ let errors = [];
26
+ for (let invocation of expr.incantations) {
27
+ if (invocation.kind === Ast.Kind.INVALID_INCANTATION) {
28
+ let msg = evaluate_error(invocation.error, desmos, { ...options, place_errors: "start" });
29
+ if (msg != undefined) {
30
+ errors.push(msg);
31
+ }
32
+ continue;
33
+ }
34
+ let data = undefined;
35
+ if ("arg_raw" in invocation && invocation.arg_raw != undefined) {
36
+ try {
37
+ data = invocation.incantation.evaluate_arg(invocation.arg_raw);
38
+ }
39
+ catch (e) {
40
+ errors.push(format_error(e, options));
41
+ if (invocation.incantation.requires_arg)
42
+ continue;
43
+ }
44
+ }
45
+ invocation.incantation.apply(expr.data, data);
46
+ }
47
+ if (errors.length > 0) {
48
+ desmos.setExpression({ type: "text", text: errors.join("\n\n") });
49
+ }
50
+ desmos.setExpression(expr.data);
51
+ }
52
+ /**
53
+ * Handle an `InvalidInvocation`, respecting the user's preferences in `options`.
54
+ *
55
+ * If the user set `place_errors: start` or `place_errors: end`, this returns the formatted error message for deferred aggregation.
56
+ */
57
+ export function evaluate_error(error, desmos, options) {
58
+ switch (options.errors) {
59
+ case "crash":
60
+ throw error;
61
+ case "suppress":
62
+ console.error(error);
63
+ break;
64
+ default: switch (options.place_errors) {
65
+ case "end":
66
+ case "start":
67
+ return format_error(error, options);
68
+ default:
69
+ desmos.setExpression({
70
+ type: "text",
71
+ text: format_error(error, options),
72
+ });
73
+ break;
74
+ }
75
+ }
76
+ }
77
+ function format_error(e, options) {
78
+ let prefix = options.error_prefix;
79
+ let sep = (prefix === "" || prefix.endsWith("\n")) ? "" : " ";
80
+ return `${prefix}${sep}${e.name}: ${e.message}`;
81
+ // TODO maybe include stack? (configurable?)
82
+ }
83
+ //# sourceMappingURL=evaluate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../../src/compiler/evaluate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAA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QACV,CAAC;IACH,CAAC;AACH,CAAC;AAGD,SAAS,YAAY,CACnB,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;IAChD,4CAA4C;AAC9C,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { compile } from "./compile";
2
+ export type { DesmostOptions } from "./options";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ export { compile } from "./compile";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,54 @@
1
+ /** Options to customise Desmost compilation. */
2
+ export interface DesmostOptions {
3
+ /**
4
+ * How should errors be *surfaced*?
5
+ *
6
+ * Errors will always be logged to console for the developer; this setting affects how they visually reach the end user.
7
+ *
8
+ * - `surface` (default): Blocks that result in errors will become Desmos text expressions containing the error message, leaving other expressions unaffected.
9
+ * - `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.
10
+ * - `suppress`: Silently fail on the frontend (if you wish to give the illusion that everything is fine).
11
+ */
12
+ errors?: "surface" | "crash" | "suppress";
13
+ /**
14
+ * Where should errors be placed?
15
+ *
16
+ * - `inline` (default): Alongside or in place of the expression that produced it.
17
+ * - `end`: All aggregated at the end of the Desmos expressions list.
18
+ * - `start`: All aggregated at the start of the Desmos expressions list.
19
+ */
20
+ place_errors?: "inline" | "end" | "start";
21
+ /**
22
+ * The prefix to prepend to error blocks. Defaults to `[DESMOST ERROR]\n`. Provide a blank string if you wish for no prefix to be added.
23
+ */
24
+ error_prefix?: string;
25
+ /**
26
+ * Should comments be ignored, instead of turned into text expressions?
27
+ *
28
+ * Defaults to `false`, meaning comments are kept.
29
+ */
30
+ ignore_comments?: boolean;
31
+ /**
32
+ * Should all line breaks be ignored, instead of kept as blank expressions.
33
+ *
34
+ * Defaults to `false`, meaning all blank lines are kept.
35
+ */
36
+ ignore_line_breaks?: boolean;
37
+ /**
38
+ * Should trailing blank lines at the end of the source be ignored, instead of kept as blank expressions?
39
+ *
40
+ * Defaults to `false`, meaning trailing blank lines are kept.
41
+ */
42
+ ignore_trailing_blanks?: boolean;
43
+ /**
44
+ * Return debug diagnostics? This includes the unevaluated AST, and performance diagnostics.
45
+ *
46
+ * Defaults to `false`.
47
+ */
48
+ debug?: boolean;
49
+ }
50
+ /**
51
+ * Fill in `options` with Desmost's defaults to produce a complete `DesmostOptions` config.
52
+ */
53
+ export declare function set_default_options(options: Partial<DesmostOptions> | undefined): Required<DesmostOptions>;
54
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/compiler/options.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,MAAM,WAAW,cAAc;IAE7B;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,UAAU,CAAA;IAEzC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAA;IAEzC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAEhC;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAGD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,CAe1G"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Fill in `options` with Desmost's defaults to produce a complete `DesmostOptions` config.
3
+ */
4
+ export function set_default_options(options) {
5
+ options ??= {};
6
+ options.errors ??= "surface";
7
+ options.place_errors ??= "inline";
8
+ options.error_prefix ??= "[DESMOST ERROR]\n";
9
+ options.ignore_comments ??= false;
10
+ options.ignore_line_breaks ??= false;
11
+ options.ignore_trailing_blanks ??= false;
12
+ options.debug ??= false;
13
+ return options;
14
+ }
15
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/compiler/options.ts"],"names":[],"mappings":"AA0DA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA4C;IAE9E,OAAO,KAAK,EAAE,CAAC;IAEf,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC;IAC7B,OAAO,CAAC,YAAY,KAAK,QAAQ,CAAC;IAClC,OAAO,CAAC,YAAY,KAAK,mBAAmB,CAAC;IAE7C,OAAO,CAAC,eAAe,KAAK,KAAK,CAAC;IAClC,OAAO,CAAC,kBAAkB,KAAK,KAAK,CAAC;IACrC,OAAO,CAAC,sBAAsB,KAAK,KAAK,CAAC;IAEzC,OAAO,CAAC,KAAK,KAAK,KAAK,CAAC;IAExB,OAAO,OAAmC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The Desmos API (currently) is browser-only, so we polyfill the API objects we need here for the server-side.
3
+ */
4
+ export declare enum DesmosColour {
5
+ RED = "#c74440",
6
+ BLUE = "#2d70b3",
7
+ GREEN = "#388c46",
8
+ PURPLE = "#6042a6",
9
+ ORANGE = "#fa7e19",
10
+ BLACK = "#000000"
11
+ }
12
+ //# sourceMappingURL=desmos.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"desmos.d.ts","sourceRoot":"","sources":["../../src/desmos.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,YAAY;IAEtB,GAAG,YAAe;IAClB,IAAI,YAAc;IAClB,KAAK,YAAa;IAClB,MAAM,YAAY;IAClB,MAAM,YAAY;IAClB,KAAK,YAAa;CACnB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The Desmos API (currently) is browser-only, so we polyfill the API objects we need here for the server-side.
3
+ */
4
+ export var DesmosColour;
5
+ (function (DesmosColour) {
6
+ DesmosColour["RED"] = "#c74440";
7
+ DesmosColour["BLUE"] = "#2d70b3";
8
+ DesmosColour["GREEN"] = "#388c46";
9
+ DesmosColour["PURPLE"] = "#6042a6";
10
+ DesmosColour["ORANGE"] = "#fa7e19";
11
+ DesmosColour["BLACK"] = "#000000";
12
+ })(DesmosColour || (DesmosColour = {}));
13
+ //# sourceMappingURL=desmos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"desmos.js","sourceRoot":"","sources":["../../src/desmos.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAN,IAAY,YAQX;AARD,WAAY,YAAY;IAEtB,+BAAkB,CAAA;IAClB,gCAAkB,CAAA;IAClB,iCAAkB,CAAA;IAClB,kCAAkB,CAAA;IAClB,kCAAkB,CAAA;IAClB,iCAAkB,CAAA;AACpB,CAAC,EARW,YAAY,KAAZ,YAAY,QAQvB"}