@cortex-js/compute-engine 0.4.2 → 0.4.3

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 (132) hide show
  1. package/README.md +2 -2
  2. package/dist/compute-engine.esm.js +22446 -16214
  3. package/dist/compute-engine.js +22449 -16222
  4. package/dist/compute-engine.min.esm.js +2 -7
  5. package/dist/compute-engine.min.js +2 -7
  6. package/dist/math-json.esm.js +4336 -10528
  7. package/dist/math-json.js +4353 -10531
  8. package/dist/math-json.min.esm.js +2 -7
  9. package/dist/math-json.min.js +2 -7
  10. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  11. package/dist/types/common/signals.d.ts +90 -0
  12. package/dist/types/compute-engine/assume.d.ts +21 -6
  13. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +107 -0
  14. package/dist/types/compute-engine/boxed-expression/box.d.ts +56 -0
  15. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +39 -0
  16. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +8 -0
  17. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -0
  18. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +93 -0
  19. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +83 -0
  20. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +21 -0
  21. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +23 -0
  22. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +98 -0
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +74 -0
  24. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  25. package/dist/types/compute-engine/boxed-expression/order.d.ts +52 -0
  26. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +15 -0
  27. package/dist/types/compute-engine/boxed-expression/utils.d.ts +37 -0
  28. package/dist/types/compute-engine/compute-engine.d.ts +233 -97
  29. package/dist/types/compute-engine/cost-function.d.ts +3 -0
  30. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +11 -0
  31. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +9 -0
  32. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +17 -0
  33. package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +9 -0
  34. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +2 -12
  35. package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
  36. package/dist/types/compute-engine/dictionary/core.d.ts +2 -2
  37. package/dist/types/compute-engine/dictionary/dictionary.d.ts +18 -11
  38. package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
  39. package/dist/types/compute-engine/dictionary/polynomials.d.ts +2 -0
  40. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +2 -0
  41. package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
  42. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +2 -2
  43. package/dist/types/compute-engine/domain-utils.d.ts +30 -0
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +4 -0
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +2 -0
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -0
  53. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  54. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +57 -0
  55. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +23 -0
  56. package/dist/types/compute-engine/latex-syntax/parse.d.ts +198 -0
  57. package/dist/types/compute-engine/latex-syntax/public.d.ts +550 -0
  58. package/dist/types/{common → compute-engine/latex-syntax}/serialize-number.d.ts +2 -3
  59. package/dist/types/{latex-syntax → compute-engine/latex-syntax}/serializer-style.d.ts +2 -1
  60. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +43 -0
  61. package/dist/types/{latex-syntax/core → compute-engine/latex-syntax}/tokenizer.d.ts +2 -2
  62. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  63. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +12 -0
  64. package/dist/types/compute-engine/numerics/numeric.d.ts +35 -0
  65. package/dist/types/compute-engine/numerics/primes.d.ts +2 -0
  66. package/dist/types/compute-engine/public.d.ts +1076 -434
  67. package/dist/types/compute-engine/rules.d.ts +16 -6
  68. package/dist/types/compute-engine/simplify-rules.d.ts +17 -0
  69. package/dist/types/compute-engine/symbolic/expand.d.ts +11 -0
  70. package/dist/types/compute-engine/symbolic/flatten.d.ts +7 -0
  71. package/dist/types/compute-engine/symbolic/negate.d.ts +12 -0
  72. package/dist/types/compute-engine/symbolic/polynomials.d.ts +52 -0
  73. package/dist/types/compute-engine/symbolic/product.d.ts +45 -0
  74. package/dist/types/compute-engine/symbolic/sum.d.ts +25 -0
  75. package/dist/types/compute-engine/symbolic/utils.d.ts +47 -0
  76. package/dist/types/compute-engine.d.ts +3 -5
  77. package/dist/types/math-json/math-json-format.d.ts +101 -0
  78. package/dist/types/math-json/utils.d.ts +97 -0
  79. package/dist/types/math-json.d.ts +5 -3
  80. package/package.json +27 -26
  81. package/dist/cortex.esm.js +0 -20989
  82. package/dist/cortex.js +0 -21011
  83. package/dist/cortex.min.esm.js +0 -7
  84. package/dist/cortex.min.js +0 -7
  85. package/dist/types/common/debug.d.ts +0 -28
  86. package/dist/types/common/utils.d.ts +0 -153
  87. package/dist/types/compute-engine/canonical-forms.d.ts +0 -74
  88. package/dist/types/compute-engine/dictionary/domains.d.ts +0 -26
  89. package/dist/types/compute-engine/dictionary/utils.d.ts +0 -5
  90. package/dist/types/compute-engine/domains.d.ts +0 -4
  91. package/dist/types/compute-engine/evaluate.d.ts +0 -13
  92. package/dist/types/compute-engine/expression-map.d.ts +0 -11
  93. package/dist/types/compute-engine/internal-compute-engine.d.ts +0 -108
  94. package/dist/types/compute-engine/numeric-complex.d.ts +0 -2
  95. package/dist/types/compute-engine/numeric-decimal.d.ts +0 -12
  96. package/dist/types/compute-engine/numeric.d.ts +0 -21
  97. package/dist/types/compute-engine/numerical-eval.d.ts +0 -5
  98. package/dist/types/compute-engine/order.d.ts +0 -18
  99. package/dist/types/compute-engine/patterns.d.ts +0 -22
  100. package/dist/types/compute-engine/predicates.d.ts +0 -42
  101. package/dist/types/compute-engine/simplify.d.ts +0 -6
  102. package/dist/types/compute-engine/utils.d.ts +0 -15
  103. package/dist/types/cortex/formatter.d.ts +0 -165
  104. package/dist/types/cortex/parse-cortex.d.ts +0 -5
  105. package/dist/types/cortex/reserved-words.d.ts +0 -1
  106. package/dist/types/cortex/serialize-cortex.d.ts +0 -14
  107. package/dist/types/cortex.d.ts +0 -8
  108. package/dist/types/latex-syntax/definitions-algebra.d.ts +0 -2
  109. package/dist/types/latex-syntax/definitions-arithmetic.d.ts +0 -3
  110. package/dist/types/latex-syntax/definitions-calculus.d.ts +0 -2
  111. package/dist/types/latex-syntax/definitions-core.d.ts +0 -3
  112. package/dist/types/latex-syntax/definitions-inequalities.d.ts +0 -2
  113. package/dist/types/latex-syntax/definitions-other.d.ts +0 -3
  114. package/dist/types/latex-syntax/definitions-sets.d.ts +0 -2
  115. package/dist/types/latex-syntax/definitions-symbols.d.ts +0 -3
  116. package/dist/types/latex-syntax/definitions-trigonometry.d.ts +0 -3
  117. package/dist/types/latex-syntax/definitions.d.ts +0 -40
  118. package/dist/types/latex-syntax/latex-syntax.d.ts +0 -27
  119. package/dist/types/latex-syntax/parse.d.ts +0 -138
  120. package/dist/types/latex-syntax/public.d.ts +0 -456
  121. package/dist/types/latex-syntax/serializer.d.ts +0 -26
  122. package/dist/types/latex-syntax/utils.d.ts +0 -10
  123. package/dist/types/point-free-parser/characters.d.ts +0 -25
  124. package/dist/types/point-free-parser/combinators.d.ts +0 -46
  125. package/dist/types/point-free-parser/core-combinators.d.ts +0 -78
  126. package/dist/types/point-free-parser/grammar.d.ts +0 -12
  127. package/dist/types/point-free-parser/identifier-parsers.d.ts +0 -7
  128. package/dist/types/point-free-parser/numeric-parsers.d.ts +0 -8
  129. package/dist/types/point-free-parser/parsers.d.ts +0 -130
  130. package/dist/types/point-free-parser/string-parsers.d.ts +0 -29
  131. package/dist/types/point-free-parser/whitespace-parsers.d.ts +0 -17
  132. package/dist/types/public.d.ts +0 -163
@@ -1,456 +0,0 @@
1
- /* 0.4.2 */
2
- export declare type LatexToken = string | '<{>' | '<}>' | '<space>' | '<$>' | '<$$>';
3
- export declare type LatexString = string;
4
- /**
5
- * Custom parser function.
6
- *
7
- * It is triggered by a latex fragment (the `latex` argument). When invoked,
8
- * the scanner points right after that latex fragment. The scanner should be
9
- * moved, by calling `scanner.next()` for every consumed token.
10
- *
11
- * If it was in an infix or postfix context, `lhs` will represent the
12
- * left-hand side argument. In a prefix or matchfix context, `lhs` is `null`.
13
- *
14
- * The function should return a tuple:
15
- *
16
- * - Its first element is an unprocessed left-hand side, if any. If the
17
- * left-hand-side has been consumed (for example if this was a valid infix
18
- * operator), the first element of the tuple should be `null`.
19
- *
20
- * - Its second element is the resulting expression.
21
- *
22
- */
23
- export declare type ParserFunction<T extends number = number> = (lhs: Expression<T> | null, scanner: Scanner<T>, minPrec: number) => [lhs: Expression<T> | null, result: Expression<T> | null];
24
- /**
25
- * Maps a string of Latex tokens to a function or symbol and vice-versa.
26
- *
27
- */
28
- export declare type LatexDictionaryEntry<T extends number = number> = {
29
- /**
30
- * Map a function or symbol name to this record.
31
- *
32
- * Each record should have at least a `name` or a `trigger`
33
- */
34
- name?: string;
35
- /**
36
- * Map one or more latex tokens to this record.
37
- *
38
- * As a shortcut, if the trigger is a LatexToken, it is assumed to be a symbol.
39
- *
40
- * There can be multiple entries (for example '+' is both an infix and a
41
- * prefix)
42
- */
43
- trigger?: LatexToken | {
44
- symbol?: LatexToken | LatexToken[];
45
- matchfix?: LatexToken | LatexToken[];
46
- /**
47
- * Infix position, with an operand before and an operand after: `a ⊛ b`.
48
- *
49
- * Example: `+`, `\times`
50
- */
51
- infix?: LatexToken | LatexToken[];
52
- /**
53
- * Prefix position, with an operand after: `⊛ a`
54
- *
55
- * Example: `-`, `\not`
56
- */
57
- prefix?: LatexToken | LatexToken[];
58
- /**
59
- * Postfix position, with an operand before: `a⊛`
60
- */
61
- postfix?: LatexToken | LatexToken[];
62
- /**
63
- * Superfix position (in a superscript), with the base of the
64
- * superscript as the operand: `a^{⊛}`
65
- */
66
- superfix?: LatexToken | LatexToken[];
67
- /**
68
- * Subfix position (in a subscript), with the base of the
69
- * subscript as the operand: `a_{⊛}`
70
- */
71
- subfix?: LatexToken | LatexToken[];
72
- /**
73
- * The name of an environment, as used in `\begin{matrix}` where
74
- * `"matrix"` is the name of the environment.
75
- *
76
- */
77
- environment?: string;
78
- };
79
- /**
80
- * A function that returns an expression, or an expression
81
- */
82
- parse?: Expression<T> | ParserFunction<T>;
83
- /**
84
- * The Latex to serialize.
85
- */
86
- serialize?: SerializerFunction<T> | LatexString;
87
- /**
88
- * If `trigger` is `'infix'``
89
- * - **`both`**: a + b + c -> +(a, b, c)
90
- * - **`left`**: a / b / c -> /(/(a, b), c)
91
- * - **`right`**: a = b = c -> =(a, =(b, c))
92
- * - **`non`**: a < b < c -> syntax error
93
- *
94
- * - a `both`-associative operator has an unlimited number of arguments
95
- * - a `left`, `right` or `non` associative operator has at most two arguments
96
- */
97
- associativity?: 'right' | 'left' | 'non' | 'both';
98
- /** If `trigger` is `'infix'`` */
99
- precedence?: number;
100
- /**
101
- * If `trigger` is `'symbol'``.
102
- * Indicate if this symbol can be followed by arguments.
103
- * The presence of arguments will indicate that the arguments should be
104
- * applied to the symbol. Otherwise, the invisible operator is applied
105
- * to the symbol and the arguments.
106
- *
107
- * If `arguments` is `"group"`:
108
- *
109
- * "f(x)" -> `["f", "x"]`
110
- * "f x" -> `["multiply", "f", "x"]`
111
- *
112
- * If `arguments` is `""`:
113
- *
114
- * "f(x)" -> `["multiply", "f", ["group", "x"]]`
115
- * "f x" -> `["multiply", "f", "x"]`
116
- *
117
- * If `arguments` is `"group/primary"` and the symbol is followed either
118
- * by a group or by a primary (prefix + symbol + subsupfix + postfix).
119
- * Used for trig functions. i.e. `\sin x` vs `\sin(x)`:
120
- *
121
- * "f(x)" -> `["f", "x"]`
122
- * "f x" -> `["f", "x"]`
123
- *
124
- */
125
- arguments?: 'group' | 'implicit' | '';
126
- /**
127
- * If `trigger` is `'symbol'``.
128
- *
129
- * If a Latex command (i.e. the trigger starts with `\`, e.g. `\sqrt`)
130
- * indicates the number of optional arguments expected (indicate with
131
- * square brackets).
132
- *
133
- * For example, for the `\sqrt` command, 1: `\sqrt[3]{x}`
134
- *
135
- */
136
- optionalLatexArg?: number;
137
- /**
138
- * If `trigger` is `'symbol'``.
139
- *
140
- * If a Latex command (i.e. the trigger starts with `\`, e.g. `\frac`)
141
- * indicates the number of required arguments expected (indicated with
142
- * curly braces).
143
- *
144
- * For example, for the `\frac` command, 2: `\frac{1}{n}`
145
- *
146
- */
147
- requiredLatexArg?: number;
148
- /**
149
- * If `trigger` is `'matchfix'``.
150
- */
151
- separator?: LatexString;
152
- closeFence?: LatexToken | LatexToken[];
153
- };
154
- export declare type LatexDictionary<T extends number = number> = LatexDictionaryEntry<T>[];
155
- export declare type ParseLatexOptions = {
156
- /**
157
- * If a symbol follows a number, consider them separated by this
158
- * invisible operator.
159
- *
160
- * Default: `"Multiply"`
161
- */
162
- invisibleOperator?: string;
163
- /**
164
- * If true, ignore space characters.
165
- *
166
- */
167
- skipSpace?: boolean;
168
- /**
169
- * When an unknown latex command is encountered, attempt to parse
170
- * any arguments it may have.
171
- *
172
- * For example, `\foo{x+1}` would produce `['\foo', ['Add', 'x', 1]]` if
173
- * this property is true, `['LatexSymbols', '\foo', '<{>', 'x', '+', 1, '<{>']`
174
- * otherwise.
175
- */
176
- parseArgumentsOfUnknownLatexCommands?: boolean;
177
- /**
178
- * When a number is encountered, parse it.
179
- *
180
- * Otherwise, return each token making up the number (minus sign, digits,
181
- * decimal separator, etc...)
182
- */
183
- parseNumbers?: boolean;
184
- /**
185
- * If this setting is not empty, when a number is immediately followed by a
186
- * fraction, assume that the fraction should be added to the number, that
187
- * is that there is an invisible plus operator between the two.
188
- *
189
- * For example with `2\frac{3}{4}`:
190
- * - when `invisiblePlusOperator` is `"add"` : `["add", 2, ["divide", 3, 4]]`
191
- * - when `invisiblePlusOperator` is `""`: `["multiply", 2, ["divide", 3, 4]]`
192
- */
193
- invisiblePlusOperator?: string;
194
- /**
195
- * When a token is encountered at a position where a symbol could be
196
- * parsed, if the token matches `promoteUnknownSymbols` it will be
197
- * accepted as a symbol (an `unknown-symbol` error will still be triggered
198
- * so that the caller can be notified). Otherwise, the symbol is rejected.
199
- */
200
- promoteUnknownSymbols?: RegExp;
201
- /**
202
- * When one of these commands is encountered, it is skipped.
203
- *
204
- * Useful for purely presentational commands such as `\displaystyle`
205
- */
206
- ignoreCommands?: LatexToken[];
207
- /**
208
- * When one these commands is encountered, its argument is parsed,
209
- * as if the command was not present.
210
- *
211
- * Useful for some presentational commands such as `\left`, `\bigl`, etc...
212
- */
213
- idempotentCommands?: LatexToken[];
214
- /**
215
- * When a token is encountered at a position that could match
216
- * a function call, and it is followed by an apply function operator
217
- * (typically, parentheses), consider them to a be a function if the
218
- * string of tokens match this regular expression.
219
- *
220
- * While this is a convenient shortcut, it is recommended to more explicitly
221
- * define custom functions by providing an entry for them in a function
222
- * dictionary (providing additional information about their arguments, etc...)
223
- * and in a Latex translation dictionary (indicating what Latex markup
224
- * corresponds to the function).
225
- *
226
- * Example:
227
- *
228
- * By default, `f(x)` is parsed as `["Multiply", "f", "x"]`.
229
- *
230
- * After...
231
- *
232
- * ```
233
- * promoteUnknownFunctions = /^[fg]$/
234
- * ```
235
- *
236
- * ... `f(x)` is parsed as `["f", "x"]`
237
- *
238
- *
239
- */
240
- promoteUnknownFunctions?: RegExp;
241
- /**
242
- * If true, the expression will be decorated with the Latex
243
- * fragments corresponding to each elements of the expression
244
- */
245
- preserveLatex?: boolean;
246
- };
247
- export declare type SerializeLatexOptions = {
248
- /**
249
- * Latex string used to render an invisible multiply, e.g. in '2x'.
250
- * Leave it empty to join the adjacent terms, or use `\cdot` to insert
251
- * a `\cdot` operator between them, i.e. `2\cdot x`.
252
- *
253
- * Empty by default.
254
- */
255
- invisibleMultiply?: LatexString;
256
- /**
257
- * Latex string used for an invisible plus, e.g. in '1 3/4'.
258
- * Leave it empty to join the main number and the fraction, i.e. render it
259
- * as `1\frac{3}{4}`, or use `+` to insert a `+` operator between them, i.e.
260
- * `1+\frac{3}{4}`
261
- *
262
- * Empty by default.
263
- */
264
- invisiblePlus?: LatexString;
265
- /**
266
- * Latex string used for an explicit multiply operator,
267
- *
268
- * Default: `\times`
269
- */
270
- multiply?: LatexString;
271
- };
272
- export declare type NumberFormattingOptions = {
273
- precision?: number;
274
- positiveInfinity?: string;
275
- negativeInfinity?: string;
276
- notANumber?: string;
277
- /**
278
- * A string representing the decimal marker, the string separating
279
- * the whole portion of a number from the fractional portion, i.e.
280
- * the '.' in '3.1415'.
281
- *
282
- * Default: `"."`
283
- */
284
- decimalMarker?: string;
285
- /**
286
- * A string representing the separator between groups of digits,
287
- * used to improve readability of numbers with lots of digits.
288
- *
289
- * Default: `","`
290
- */
291
- groupSeparator?: string;
292
- exponentProduct?: string;
293
- beginExponentMarker?: string;
294
- endExponentMarker?: string;
295
- notation?: 'engineering' | 'auto' | 'scientific';
296
- truncationMarker?: string;
297
- beginRepeatingDigits?: string;
298
- endRepeatingDigits?: string;
299
- imaginaryNumber?: string;
300
- };
301
- /**
302
- * To customize the parsing and serializing of Latex syntax, create a `LatexSyntax`
303
- * instance.
304
- */
305
- export declare class LatexSyntax<T extends number = number> {
306
- /**
307
- *
308
- * @param onError - Called when a non-fatal error is encountered. When parsing,
309
- * the parser will attempt to recover and continue.
310
- *
311
- */
312
- constructor(options?: NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions & {
313
- onError?: ErrorListener<ErrorCode>;
314
- dictionary?: LatexDictionary;
315
- });
316
- /**
317
- * Return a Latex dictionary suitable for the specified category, or `"all"`
318
- * for all categories (`"arithmetic"`, `"algebra"`, etc...).
319
- *
320
- * A Latex dictionary is needed to translate between Latex and MathJSON.
321
- *
322
- * Each entry in the dictionary indicate how a Latex token (or string of
323
- * tokens) should be parsed into a MathJSON expression.
324
- *
325
- * For example an entry can define that the `\pi` Latex token should map to the
326
- * symbol `"Pi"`, or that the token `-` should map to the function
327
- * `["Negate",...]` when in a prefix position and to the function
328
- * `["Subtract", ...]` when in an infix position.
329
- *
330
- * Furthermore, the information in each dictionary entry is used to serialize
331
- * the Latex string corresponding to a MathJSON expression.
332
- *
333
- * Use the value returned by this function to the `options` argument of the
334
- * constructor.
335
- */
336
- static getDictionary(domain?: DictionaryCategory | 'all'): Readonly<LatexDictionary<any>>;
337
- parse(latex: LatexString): Expression<T>;
338
- serialize(expr: Expression<T>): LatexString;
339
- }
340
- export interface Serializer<T extends number = number> {
341
- readonly onError: ErrorListener<ErrorCode>;
342
- readonly options: Required<SerializeLatexOptions>;
343
- /** "depth" of the expression:
344
- * - 0 for the root
345
- * - 1 for the arguments of the root
346
- * - 2 for the arguments of the arguments of the root
347
- * - etc...
348
- *
349
- * This allows for variation of the Latex serialized based
350
- * on the depth of the expression, for example using `\Bigl(`
351
- * for the top level, and `\bigl(` or `(` for others.
352
- */
353
- level: number;
354
- /** Output a Latex string representing the expression */
355
- serialize: (expr: Expression<T> | null) => string;
356
- wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none'): string;
357
- /** Add a group fence around the expression if it is
358
- * an operator of precedence less than or equal to `prec`.
359
- */
360
- wrap: (expr: Expression<T> | null, prec?: number) => string;
361
- /** Add a group fence around the expression if it is
362
- * short (not a function)
363
- */
364
- wrapShort(expr: Expression<T> | null): string;
365
- }
366
- export declare type SerializerFunction<T extends number = number> = (serializer: Serializer<T>, expr: T | Expression<T>) => string;
367
- export interface Scanner<T extends number = number> {
368
- readonly onError: ErrorListener<ErrorCode>;
369
- readonly options: Required<ParseLatexOptions>;
370
- index: number;
371
- readonly atEnd: boolean;
372
- /** Return the next token, without advancing the index */
373
- readonly peek: LatexToken;
374
- /** Return an array of string corresponding to tokens ahead.
375
- * The index is unchanged.
376
- */
377
- lookAhead(): string[];
378
- /** Return the next token and advance the index */
379
- next(): LatexToken;
380
- /** Return a latex string before the index */
381
- latexBefore(): string;
382
- /** Return a latex string after the index */
383
- latexAfter(): string;
384
- /** If there are any space, advance the index until a non-space is encountered */
385
- skipSpace(): boolean;
386
- /** If the next token matches the target advance and return true. Otherwise
387
- * return false */
388
- match(target: LatexToken): boolean;
389
- matchAny(targets: LatexToken[]): LatexToken;
390
- matchWhile(targets: LatexToken[]): LatexToken[];
391
- /** If the next token matches a `+` or `-` sign, return it and advance the index.
392
- * Otherwise return `''` and do not advance */
393
- matchSign(): string;
394
- matchDecimalDigits(): string;
395
- matchSignedInteger(): string;
396
- matchExponent(): string;
397
- matchNumber(): string;
398
- matchTabular(): null | Expression<T>;
399
- applyOperator(op: string, lhs: Expression<T> | null, rhs: Expression<T> | null): NonNullable<[Expression<T> | null, Expression<T> | null]>;
400
- applyInvisibleOperator(lhs: Expression<T> | null, rhs: Expression<T> | null): Expression<T> | null;
401
- /** If the next tokens correspond to an optional argument,
402
- * enclosed with `[` and `]` return the content of the argument
403
- * as an expression and advance the index past the closing `]`.
404
- * Otherwise, return null
405
- */
406
- matchOptionalLatexArgument(): Expression<T> | null;
407
- matchRequiredLatexArgument(): Expression<T> | null;
408
- matchArguments(kind: '' | 'group' | 'implicit'): Expression<T>[] | null;
409
- matchSupsub(lhs: Expression<T> | null): Expression<T> | null;
410
- /**
411
- * <primary> :=
412
- * (<number> | <symbol> | <latex-command> | <function-call> | <matchfix-expr>)
413
- * (<subsup> | <postfix-operator>)*
414
- *
415
- * <matchfix-expr> :=
416
- * <matchfix-op-open> <expression> <matchfix-op-close>
417
- *
418
- * <function-call> ::=
419
- * | <function><matchfix-op-group-open><expression>[',' <expression>]<matchfix-op-group-close>
420
- *
421
- * If not a primary, return `null` and do not advance the index.
422
- */
423
- matchPrimary(minPrec?: number): Expression<T> | null;
424
- /**
425
- * Parse an expression:
426
- *
427
- * <expression> ::=
428
- * | <prefix-op> <expression>
429
- * | <primary>
430
- * | <primary> <infix-op> <expression>
431
- *
432
- * Stop when an operator of precedence less than `minPrec` is encountered
433
- *
434
- * `minPrec` is 0 by default.
435
- */
436
- matchExpression(minPrec?: number): Expression<T> | null;
437
- matchBalancedExpression(open: LatexToken, close: LatexToken, onError?: ErrorListener<ErrorCode>): Expression<T> | null;
438
- }
439
- /**
440
- * Parse a Latex string and return a corresponding MathJSON expression.
441
- *
442
- * @param onError - Called when a non-fatal error is encountered while parsing.
443
- * The parsing will attempt to recover and continue.
444
- *
445
- */
446
- export declare function parse<T extends number = number>(latex: LatexString, options?: NumberFormattingOptions & ParseLatexOptions & {
447
- onError?: ErrorListener<ErrorCode>;
448
- }): Expression<T>;
449
- /**
450
- * Serialize a MathJSON expression as a Latex string.
451
- *
452
- */
453
- export declare function serialize<T extends number = number>(expr: Expression<T>, options?: NumberFormattingOptions & SerializeLatexOptions & {
454
- dictionary?: Readonly<LatexDictionary<T>>;
455
- onError?: ErrorListener<ErrorCode>;
456
- }): LatexString;
@@ -1,26 +0,0 @@
1
- /* 0.4.2 */
2
- import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
3
- import { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './definitions';
4
- export declare class Serializer<T extends number = number> implements Serializer<T> {
5
- readonly dictionary: IndexedLatexDictionary<T>;
6
- readonly onError: ErrorListener<ErrorCode>;
7
- readonly options: Required<NumberFormattingOptions> & Required<SerializeLatexOptions>;
8
- level: number;
9
- constructor(options: Required<NumberFormattingOptions> & Required<SerializeLatexOptions>, dictionary: IndexedLatexDictionary<T>, onError: ErrorListener<ErrorCode>);
10
- /**
11
- * Serialize the expression, and if the expression is an operator
12
- * of precedence less than or equal to prec, wrap it in some paren.
13
- * @todo: don't wrap abs
14
- */
15
- wrap(expr: Expression<T> | null, prec?: number): string;
16
- /** If this is a "short" expression (atomic), wrap it.
17
- *
18
- */
19
- wrapShort(expr: Expression<T> | null): string;
20
- wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none'): string;
21
- serializeSymbol(expr: Expression<T>, def?: IndexedLatexDictionaryEntry<T>): string;
22
- serializeDictionary(dict: {
23
- [key: string]: Expression<T>;
24
- }): string;
25
- serialize(expr: T | Expression<T> | null): LatexString;
26
- }
@@ -1,10 +0,0 @@
1
- /* 0.4.2 */
2
- export declare const DEFAULT_LATEX_NUMBER_OPTIONS: Required<NumberFormattingOptions>;
3
- export declare const DEFAULT_PARSE_LATEX_OPTIONS: Required<ParseLatexOptions>;
4
- export declare const DEFAULT_SERIALIZE_LATEX_OPTIONS: Required<SerializeLatexOptions>;
5
- export declare function appendLatex(src: string, s: string): string;
6
- /**
7
- * Replace '#1', '#2' in the latex template stings with the corresponding
8
- * values from `replacement`, in a Latex syntax safe manner (i.e. inserting spaces when needed)
9
- */
10
- export declare function replaceLatex(template: string, replacement: string[]): string;
@@ -1,25 +0,0 @@
1
- /* 0.4.2 */
2
- export declare const REVERSED_ESCAPED_CHARS: Map<number, number>;
3
- export declare const HEX_DIGITS: Map<number, number>;
4
- export declare const DIGITS: Map<number, number>;
5
- export declare const SUPERSCRIPT_UNICODE: Map<number, string>;
6
- export declare const SUBSCRIPT_UNICODE: Map<number, string>;
7
- export declare const VULGAR_FRACTIONS_UNICODE: Map<number, string>;
8
- export declare const FANCY_UNICODE: Map<number, string>;
9
- export declare const REVERSE_FANCY_UNICODE: Map<string, number[]>;
10
- export declare function isLinebreak(c: number): boolean;
11
- /** Most restrictive whitespace only TAB or SPACE */
12
- export declare function isInlineSpace(c: number): boolean;
13
- export declare function isPatternWhitespace(c: number): boolean;
14
- /** Everything in pattern white space, plus some other
15
- * characters considered whitespace */
16
- export declare function isWhitespace(c: number): boolean;
17
- export declare function isSyntax(c: number): boolean;
18
- /** A 'break' character is an whitespace, operator, punctuation, bracket, etc..
19
- * It indicates the end of an identifier (or number).
20
- */
21
- export declare function isBreak(c: number): boolean;
22
- export declare function isIdentifierContinueProhibited(c: number): boolean;
23
- export declare function isIdentifierStartProhibited(c: number): boolean;
24
- export declare function isInvisible(c: number): boolean;
25
- export declare function codePointLength(code: number): number;
@@ -1,46 +0,0 @@
1
- /* 0.4.2 */
2
- /**
3
- * An element bracketed by open and close delimiters.
4
- *
5
- */
6
- export declare function between<IR>(open: string, something: string | Combinator<IR>, close: string): Combinator<IR>;
7
- export declare function manySeparatedBetween<IR>(open: string, something: string | Combinator<IR>, separator: string, close: string, f: (values: Result<IR>[]) => IR): Combinator<IR>;
8
- /**
9
- * 0 or more elements, separated and bracketed with open and close delimiters
10
- * */
11
- export declare function someSeparatedBetween<IR>(open: string, something: string | Combinator<IR>, separator: string, close: string, f: (values: (IR | undefined | null)[]) => IR): Combinator<IR>;
12
- /**
13
- * Combinator for a table of operators.
14
- * Each operator has a precedence, and can be either a prefix,
15
- * suffix, left-associating infix, or right-association infix.
16
- *
17
- * Prefix and suffix have no whitespace between the operator and its term.
18
- *
19
- * Infix have either whitespace on both sides *or* no whitespace.
20
- *
21
- * This requirement is necessary to parse multi-line statements without
22
- * requiring statement separators.
23
- *
24
- */
25
- export declare type OpRecord<U> = [
26
- data: U,
27
- op: string,
28
- prec: number,
29
- assoc?: 'prefix' | 'suffix' | 'left' | 'right'
30
- ];
31
- export declare type OpsTable<U> = OpRecord<U>[];
32
- /**
33
- * Return the ops sorted by length of the symbol so that,
34
- * e.g. '<<-' is before '<-'
35
- */
36
- /**
37
- * A sequence of prefix, infix and suffix operators with `term`
38
- * operands.
39
- *
40
- * The `f` mapping function is called according to the specified
41
- * precedence info in the `OpsTable`
42
- */
43
- export declare function operatorSequence<IR, U>(ops: OpsTable<U>, term: string | Combinator<IR>, f: (op: U, lhs?: IR, rhs?: IR) => IR): Combinator<IR>;
44
- /**
45
- * Parse a prefix operator
46
- */
@@ -1,78 +0,0 @@
1
- /* 0.4.2 */
2
- export declare function normalize<IR>(c: string | Combinator | ((parser: Parser) => Result<IR>)): string | ((parser: Parser) => Result<IR>);
3
- export declare function description(c: string | Combinator): string;
4
- export declare function parseCodepoint(parser: Parser, value: number): Result<string>;
5
- export declare function codepoint(value: number): Combinator<string>;
6
- /**
7
- * Apply a function to one or more results.
8
- *
9
- * Similar to an _action_ with YACC/Bison.
10
- *
11
- * Compute the semantic value of the whole construct from the semantic
12
- * values of its parts.
13
- */
14
- /**
15
- *
16
- * Combine one or more results into a single result using the `f()` function.
17
- *
18
- * Keep all the diagnostics (if any of the results has an error, the overall
19
- * result is an error).
20
- * If there are no results, the result is empty (not a failure).
21
- */
22
- export declare function combine<T>(parser: Parser, f: (...results: Result[]) => T, results: Result[], errors?: Result[], msg?: DiagnosticMessage | ((Parser: any) => DiagnosticMessage)): Result<T>;
23
- export declare function parseString(parser: Parser, value: string): Result<string>;
24
- /** Combinator for a sequence of one or more characters */
25
- export declare function literal(value: string): Combinator<string>;
26
- /** Combinator that accepts a "fancy" Unicode alternative for
27
- * "value".
28
- *
29
- * Value can consist of more than one character, for example "!=".
30
- * It will match the corresponding "≠" fancy version. The fancy
31
- * versions include the characters listed in FANCY_UNICODE. The
32
- * fancy version is assumed to be a single Unicode character.
33
- *
34
- * Note that superscript numbers and subscript numbers are not
35
- * included since they need to be handled contextually.
36
- */
37
- export declare function fancyLiteral(value: string): Combinator<string>;
38
- export declare function regex(regex: RegExp): Combinator<string>;
39
- /**
40
- * Generator for an ordered, non-empty, sequence of elements separated
41
- * by whitespace.
42
- *
43
- * If the first one fails, the sequence fails (softly).
44
- * After the first one, if a generator fails, the sequence returns an
45
- * error.
46
- */
47
- export declare function sequence<IR>(cs: (string | Combinator)[], f: (...results: Result[]) => IR): Combinator<IR>;
48
- /**
49
- * Explore multiple alternatives.
50
- * Select the one that advances the most.
51
- */
52
- export declare function best<IR>(cs: Combinator[]): Combinator<IR>;
53
- /**
54
- * Explore multiple alternatives.
55
- * Select the first one that matches.
56
- *
57
- */
58
- export declare function either<IR = any>(cs: (string | Combinator)[], f?: (result: Result) => IR): Combinator;
59
- /**
60
- * 1 or more `something`
61
- */
62
- export declare function many<IR>(something: Combinator<IR>, f: (...results: Result<IR>[]) => IR): Combinator<IR>;
63
- /**
64
- * 0 or more `something`.
65
- *
66
- * The parser of this combinator will never fail (since ø is an acceptable match).
67
- * If there are 0 something, the parser will return an Ignore result.
68
- */
69
- export declare function some<IR>(something: string | Combinator<IR>, f: (...results: Result<IR>[]) => IR): Combinator<IR>;
70
- /**
71
- * Succeeds even if `something` fails
72
- */
73
- export declare function maybe<T>(something: Combinator<T> | string): Combinator<T>;
74
- /**
75
- * Return an error if `something` is a failure
76
- */
77
- export declare function must<T>(something: string | Combinator<T>, inMsg?: DiagnosticMessage | ((Parser: any) => DiagnosticMessage)): Combinator<T>;
78
- export declare function eof(): Combinator<boolean>;
@@ -1,12 +0,0 @@
1
- /* 0.4.2 */
2
- export declare class Grammar<IR> implements Rules {
3
- private rules;
4
- private ruleDescription;
5
- constructor();
6
- /** Define a new rule or a rule description */
7
- rule<T = IR>(name: string, def: ((Parser: any) => Result<T>) | string | Combinator<T>): void;
8
- toString(): string;
9
- parse<T = IR>(rule: string, parser: string | Parser, url?: string): Result<T>;
10
- has(rule: string): boolean;
11
- get(rule: string): (Parser: any) => Result<IR>;
12
- }
@@ -1,7 +0,0 @@
1
- /* 0.4.2 */
2
- export declare function parseIdentifier(parser: Parser): Result<string>;
3
- /** A verbatim identifier is enclosed in backticks and can
4
- * include characters that are otherwise invalid (such as `+`).
5
- * It can also include escape sequences.
6
- */
7
- export declare function parseVerbatimIdentifier(parser: Parser): Result<string>;
@@ -1,8 +0,0 @@
1
- /* 0.4.2 */
2
- export declare function parseExponent(parser: Parser, prefix: 'e' | 'p'): Result<number>;
3
- export declare function applyExponent(parser: Parser, start: number, value: number): Result<number>;
4
- export declare function parseBinaryNumber(parser: Parser): Result<number>;
5
- export declare function parseHexadecimalNumber(parser: Parser): Result<number>;
6
- export declare function parseFloatingPointNumber(parser: Parser): Result<number>;
7
- export declare function parseNumber(parser: Parser): Result<number>;
8
- export declare function parseSignedNumber(parser: Parser): Result<number>;