@cortex-js/compute-engine 0.12.4 → 0.12.6

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 (89) hide show
  1. package/dist/compute-engine.esm.js +916 -782
  2. package/dist/compute-engine.js +916 -782
  3. package/dist/compute-engine.min.esm.js +916 -782
  4. package/dist/compute-engine.min.js +916 -782
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.js +2 -2
  7. package/dist/math-json.min.esm.js +2 -2
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  10. package/dist/types/common/signals.d.ts +1 -1
  11. package/dist/types/common/utils.d.ts +1 -1
  12. package/dist/types/compute-engine/assume.d.ts +1 -1
  13. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +2 -2
  19. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  29. package/dist/types/compute-engine/compute-engine.d.ts +8 -6
  30. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  31. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +14 -9
  43. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +2 -2
  44. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
  45. package/dist/types/compute-engine/latex-syntax/parse.d.ts +102 -75
  46. package/dist/types/compute-engine/latex-syntax/public.d.ts +138 -136
  47. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +4 -4
  50. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  51. package/dist/types/compute-engine/library/arithmetic-add.d.ts +1 -1
  52. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  53. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +1 -1
  54. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  55. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  56. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  57. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  58. package/dist/types/compute-engine/library/core.d.ts +1 -1
  59. package/dist/types/compute-engine/library/domains.d.ts +2 -1
  60. package/dist/types/compute-engine/library/library.d.ts +1 -1
  61. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  62. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  63. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  64. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  65. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  66. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  67. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  68. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  69. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  70. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  71. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  72. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  73. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  74. package/dist/types/compute-engine/public.d.ts +102 -5
  75. package/dist/types/compute-engine/rules.d.ts +1 -1
  76. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  77. package/dist/types/compute-engine/solve.d.ts +1 -1
  78. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  79. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  80. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  81. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  82. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  83. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  84. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  85. package/dist/types/compute-engine.d.ts +2 -2
  86. package/dist/types/math-json/math-json-format.d.ts +1 -1
  87. package/dist/types/math-json/utils.d.ts +2 -1
  88. package/dist/types/math-json.d.ts +2 -2
  89. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import type { IComputeEngine } from '../public';
4
4
  /**
@@ -50,14 +50,14 @@ export type Terminator = {
50
50
  * otherwise.
51
51
  *
52
52
  */
53
- export type EnvironmentParseHandler = (parser: Parser, reqArgs: Expression[], optArgs: Expression[]) => Expression | null;
54
- export type IdentifierParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
53
+ export type ExpressionParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
54
+ export type PrefixParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
55
+ export type SymbolParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
55
56
  export type FunctionParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
56
- export type PostfixParseHandler = (parser: Parser, lhs: Expression) => Expression | null;
57
- export type PrefixParseHandler = (parser: Parser, until: Terminator) => Expression | null;
58
- export type InfixParseHandler = (parser: Parser, until: Terminator, lhs: Expression) => Expression | null;
57
+ export type EnvironmentParseHandler = (parser: Parser, reqArgs: Expression[], optArgs: Expression[]) => Expression | null;
58
+ export type PostfixParseHandler = (parser: Parser, lhs: Expression, until?: Terminator) => Expression | null;
59
+ export type InfixParseHandler = (parser: Parser, lhs: Expression, until: Terminator) => Expression | null;
59
60
  export type MatchfixParseHandler = (parser: Parser, body: Expression) => Expression | null;
60
- export type ParseHandler = IdentifierParseHandler | FunctionParseHandler | EnvironmentParseHandler | PostfixParseHandler | PrefixParseHandler | InfixParseHandler | MatchfixParseHandler;
61
61
  export type LatexArgumentType = '{expression}' /** A required math mode expression */ | '[expression]' /** An optional math mode expression */ | '{text}' /** A required expression in text mode */ | '[text]' /** An optional expression in text mode */ | '{unit}' /** A required unit expression, e.g. `3em` */ | '[unit]' /** An optional unit expression, e.g. `3em` */ | '{glue}' /** A required glue expression, e.g. `25 mu plus 3em ` */ | '[glue]' /** An optional glue expression, e.g. `25 mu plus 3em ` */ | '{string}' /** A required text string, terminated by a non-literal token */ | '[string]' /** An optional text string, terminated by a non-literal token */ | '{color}' /** A required color expression, e.g. `red` or `#00ff00` */ | '[color]'; /** An optional color expression, e.g. `red` or `#00ff00` */
62
62
  /**
63
63
  * Maps a string of LaTeX tokens to a function or symbol and vice-versa.
@@ -93,8 +93,13 @@ export type BaseEntry = {
93
93
  * If no `serialize` handler is provided, the `trigger` property is used
94
94
  */
95
95
  serialize?: LatexString | SerializeHandler;
96
+ parse?: Expression | ExpressionParseHandler;
97
+ };
98
+ export type ExpressionEntry = Omit<BaseEntry, 'parse'> & {
99
+ kind: 'expression';
100
+ parse: Expression | ExpressionParseHandler;
96
101
  };
97
- export type MatchfixEntry = BaseEntry & {
102
+ export type MatchfixEntry = Omit<BaseEntry, 'parse'> & {
98
103
  kind: 'matchfix';
99
104
  /**
100
105
  * If `kind` is `'matchfix'`: the `closeDelimiter` and `openDelimiter`
@@ -106,9 +111,9 @@ export type MatchfixEntry = BaseEntry & {
106
111
  * The argument of the handler is the body, i.e. the content between
107
112
  * the open delimiter and the close delimiter.
108
113
  */
109
- parse: MatchfixParseHandler;
114
+ parse?: MatchfixParseHandler;
110
115
  };
111
- export type InfixEntry = BaseEntry & {
116
+ export type InfixEntry = Omit<BaseEntry, 'parse'> & {
112
117
  /**
113
118
  * Infix position, with an operand before and an operand after: `a ⊛ b`.
114
119
  *
@@ -127,11 +132,9 @@ export type InfixEntry = BaseEntry & {
127
132
  */
128
133
  associativity?: 'right' | 'left' | 'non' | 'both';
129
134
  precedence?: number;
130
- /**
131
- */
132
- parse: string | InfixParseHandler;
135
+ parse?: string | InfixParseHandler;
133
136
  };
134
- export type PostfixEntry = BaseEntry & {
137
+ export type PostfixEntry = Omit<BaseEntry, 'parse'> & {
135
138
  /**
136
139
  * Postfix position, with an operand before: `a ⊛`
137
140
  *
@@ -139,9 +142,9 @@ export type PostfixEntry = BaseEntry & {
139
142
  */
140
143
  kind: 'postfix';
141
144
  precedence?: number;
142
- parse: PostfixParseHandler;
145
+ parse?: PostfixParseHandler;
143
146
  };
144
- export type PrefixEntry = BaseEntry & {
147
+ export type PrefixEntry = Omit<BaseEntry, 'parse'> & {
145
148
  /**
146
149
  * Prefix position, with an operand after: `⊛ a`
147
150
  *
@@ -149,21 +152,21 @@ export type PrefixEntry = BaseEntry & {
149
152
  */
150
153
  kind: 'prefix';
151
154
  precedence: number;
152
- parse: PrefixParseHandler;
155
+ parse?: PrefixParseHandler;
153
156
  };
154
157
  /**
155
158
  * A LaTeX dictionary entry for an environment, that is a LaTeX
156
159
  * construct using `\begin{...}...\end{...}`.
157
160
  */
158
- export type EnvironmentEntry = BaseEntry & {
161
+ export type EnvironmentEntry = Omit<BaseEntry, 'parse'> & {
159
162
  kind: 'environment';
160
163
  parse: EnvironmentParseHandler;
161
164
  };
162
- export type IdentifierEntry = BaseEntry & {
163
- kind: 'identifier';
165
+ export type SymbolEntry = Omit<BaseEntry, 'parse'> & {
166
+ kind: 'symbol';
164
167
  /** Used for appropriate wrapping (i.e. when to surround it with parens) */
165
168
  precedence?: number;
166
- parse: Expression | IdentifierParseHandler;
169
+ parse: Expression | SymbolParseHandler;
167
170
  };
168
171
  /**
169
172
  * A function has the following form:
@@ -176,21 +179,16 @@ export type IdentifierEntry = BaseEntry & {
176
179
  * inverse functions postfix (i.e. ^{-1}), use a custom parse handler with a
177
180
  * base entry.
178
181
  */
179
- export type FunctionEntry = BaseEntry & {
182
+ export type FunctionEntry = Omit<BaseEntry, 'parse'> & {
180
183
  kind: 'function';
181
184
  trigger: string;
182
- parse: Expression | FunctionParseHandler;
183
- };
184
- /**
185
- * A simple LaTeX dictionary entry, for example for a command like `\pi`.
186
- */
187
- export type DefaultEntry = BaseEntry & {
188
- precedence?: number;
189
- parse?: Expression | IdentifierParseHandler;
185
+ parse?: Expression | FunctionParseHandler;
190
186
  };
191
- export type LatexDictionaryEntry = DefaultEntry | MatchfixEntry | InfixEntry | PostfixEntry | PrefixEntry | IdentifierEntry | FunctionEntry | EnvironmentEntry;
187
+ export type LatexDictionaryEntry = BaseEntry | ExpressionEntry | MatchfixEntry | InfixEntry | PostfixEntry | PrefixEntry | SymbolEntry | FunctionEntry | EnvironmentEntry;
192
188
  /** @internal */
193
- export declare function isIdentifierEntry(entry: LatexDictionaryEntry): entry is IdentifierEntry;
189
+ export declare function isExpressionEntry(entry: LatexDictionaryEntry): entry is ExpressionEntry;
190
+ /** @internal */
191
+ export declare function isSymbolEntry(entry: LatexDictionaryEntry): entry is SymbolEntry;
194
192
  /** @internal */
195
193
  export declare function isFunctionEntry(entry: LatexDictionaryEntry): entry is FunctionEntry;
196
194
  /** @internal */
@@ -438,151 +436,140 @@ export type SerializeHandler = (serializer: Serializer, expr: Expression) => str
438
436
  export interface Parser {
439
437
  readonly options: Required<ParseLatexOptions>;
440
438
  readonly computeEngine?: IComputeEngine;
439
+ /** The index of the current token */
441
440
  index: number;
442
- /** True if the last token has been reached */
441
+ /** True if the last token has been reached.
442
+ * Consider also `atTerminator()`.
443
+ */
443
444
  readonly atEnd: boolean;
445
+ /** Return true if the terminator condition is met or if the last token
446
+ * has been reached.
447
+ */
448
+ atTerminator(t: Terminator | undefined): boolean;
444
449
  /** Return the next token, without advancing the index */
445
450
  readonly peek: LatexToken;
446
- /** Return true if the terminator condition is met */
447
- atTerminator(t: Terminator | undefined): boolean;
451
+ /** Return the next token and advance the index */
452
+ nextToken(): LatexToken;
448
453
  /** Return an array of string corresponding to tokens ahead.
449
454
  * The index is unchanged.
450
455
  */
451
456
  lookAhead(): string[];
452
- /** Return the next token and advance the index */
453
- next(): LatexToken;
454
- /** Return a LaTeX string before the index */
455
- latexBefore(): string;
456
- /** Return a LaTeX string after the index */
457
- latexAfter(): string;
457
+ /** Return a string representation of the expression
458
+ between `start` and `end` (default: the whole expression) */
459
+ latex(start: number, end?: number): string;
460
+ /** Return an error expression with the specified code and arguments */
461
+ error(code: string | [string, ...Expression[]], fromToken: number): Expression;
458
462
  /** If there are any space, advance the index until a non-space is encountered */
459
463
  skipSpace(): boolean;
460
- addBoundary(boundary: LatexToken[]): void;
461
- removeBoundary(): void;
462
- matchBoundary(): boolean;
463
- boundaryError(msg: string | [string, ...Expression[]]): Expression;
464
+ /** Skip over "visual space" which
465
+ includes space tokens, empty groups `{}`, and commands such as `\,` and `\!` */
466
+ skipVisualSpace(): void;
467
+ /** If the next token matches the target advance and return true. Otherwise
468
+ * return false */
469
+ match(token: LatexToken): boolean;
470
+ /** Return true if the next tokens match the argument, an array of tokens, or null otherwise */
471
+ matchAll(tokens: LatexToken[]): boolean;
472
+ /** Return the next token if it matches any of the token in the argument or null otherwise */
473
+ matchAny(tokens: LatexToken[]): LatexToken;
464
474
  /** If the next token is a character, return it and advance the index
465
475
  * This includes plain characters (e.g. 'a', '+'...), characters
466
476
  * defined in hex (^^ and ^^^^), the `\char` and `\unicode` command.
467
477
  */
468
478
  matchChar(): string | null;
469
- /** Return a CSS color. Handle the various color formats supported by the
470
- * `xcolor` package.
471
- */
472
- matchColor(background?: boolean): string | null;
473
479
  /**
474
- * Return a LaTeX dimension.
480
+ * Parse an expression in aLaTeX group enclosed in curly brackets `{}`.
481
+ * These are often used as arguments to LaTeX commands, for example
482
+ * `\frac{1}{2}`.
475
483
  *
484
+ * Return `null` if none was found
485
+ * Return `['Sequence']` if an empty group `{}` was found
476
486
  */
477
- matchLatexDimension(): string | null;
478
- /** If the next token matches the target advance and return true. Otherwise
479
- * return false */
480
- match(tokens: LatexToken): boolean;
481
- matchAll(tokens: LatexToken | LatexToken[]): boolean;
482
- matchAny(tokens: LatexToken[]): LatexToken;
483
- matchSequence(tokens: LatexToken[]): LatexToken[];
484
- /** If the next token matches a `+` or `-` sign, return it and advance the index.
485
- * Otherwise return `''` and do not advance */
486
- matchOptionalSign(): string;
487
- matchDecimalDigits(): string;
488
- matchSignedInteger(): string;
489
- matchExponent(): string;
490
- matchNumber(): string;
491
- /** Parse a tabular environment, until `\end{endName}`
492
- */
493
- matchTabular(endName: string): null | Expression[][];
494
- applyInvisibleOperator(terminator: Terminator, lhs: Expression | null): Expression | null;
495
- /** Some LaTeX commands (but not all) can accept an argument without braces,
496
- * for example `^` , `\sqrt` or `\frac`.
487
+ parseGroup(): Expression | null;
488
+ /**
489
+ * Some LaTeX commands (but not all) can accept arguments as single
490
+ * tokens (i.e. without braces), for example `^2`, `\sqrt3` or `\frac12`
497
491
  *
498
- * The following tokens are excluded from consideration to fail early when
499
- * encountering a likely syntax error, for example `x^(2)` (instead of
500
- * `x^{2}`). With `(` in the list of excluded tokens, the match will fail
501
- * and the error can be recovered.
492
+ * This argument will usually be a single token, but can be a sequence of
493
+ * tokens (e.g. `\sqrt\frac12` or `\sqrt\mathrm{speed}`).
502
494
  *
503
- * The excluded tokens are `!"#$%&(),/;:?@[]`|~", `\left` and `\bigl`
495
+ * The following tokens are excluded from consideration in order to fail
496
+ * early when encountering a likely syntax error, for example `x^(2)`
497
+ * instead of `x^{2}`. With `(` in the list of excluded tokens, the
498
+ * match will fail and the error can be recovered.
499
+ *
500
+ * The excluded tokens include `!"#$%&(),/;:?@[]`|~", `\left`, `\bigl`, etc...
504
501
  */
505
- matchSingleAtomArgument(): Expression | null;
502
+ parseToken(): Expression | null;
506
503
  /**
504
+ * Parse an expression enclosed in a LaTeX optional group enclosed in square brackets `[]`.
507
505
  *
508
- * Match a LaTeX expression enclosed in `[]`
509
- *
510
- * Otherwise, return `null`.
506
+ * Return `null` if none was found.
511
507
  */
512
- matchLatexOptionalGroup(): Expression | null;
508
+ parseOptionalGroup(): Expression | null;
513
509
  /**
514
- * Match a LaTeX group enclosed in `{}`
510
+ * Some LaTeX commands have arguments that are not interpreted as
511
+ * expressions, but as strings. For example, `\begin{array}{ccc}` (both
512
+ * `array` and `ccc` are strings), `\color{red}` or `\operatorname{lim sup}`.
515
513
  *
516
- * Return null if no argument was found
517
- * Return `['Sequence']` if an empty argument `{}` was found
514
+ * If the next token is the start of a group (`{`), return the content
515
+ * of the group as a string. This may include white space, and it may need
516
+ * to be trimmed at the start and end of the string.
517
+ *
518
+ * LaTeX commands are typically not allowed inside a string group (for example,
519
+ * `\alpha` would result in an error), but we do not enforce this.
518
520
  */
519
- matchLatexGroup(): Expression | null;
521
+ parseStringGroup(): string | null;
520
522
  /**
521
- * - 'enclosure' : will look for an argument inside an enclosure (an open/close fence)
522
- * - 'implicit': either an expression inside a pair of `()`, or just a primary
523
- * (i.e. we interpret `\cos x + 1` as `\cos(x) + 1`)
523
+ * A symbol can be:
524
+ * - a single-letter identifier: `x`
525
+ * - a single LaTeX command: `\pi`
526
+ * - a multi-letter identifier: `\mathrm{speed}`
524
527
  */
525
- matchArguments(kind: '' | 'implicit' | 'enclosure', until?: Terminator): Expression[] | null;
526
- matchStringArgument(): string | null;
527
- matchPrimeSuffix(): number;
528
- /** Parse function 'id' followed optionally by some prefix (primes, etc
529
- * and an argument list in an enclosure. */
530
- matchFunctionSuffix(id: string): Expression;
531
- /** If matches the normalized open delimiter, returns the
532
- * expected closing delimiter.
528
+ parseSymbol(until?: Partial<Terminator>): Expression | null;
529
+ /**
530
+ * Parse an expression in a tabular format, where rows are separated by `\\`
531
+ * and columns by `&`.
533
532
  *
534
- * For example, if `openDelim` is `(`, and `closeDelim` is `)` it would match
535
- * `\left\lparen` and return `['\right', '\rparen']`, which can be matched
536
- * with `matchAll()`
533
+ * Return rows of sparse columns: empty rows are indicated with `Nothing`,
534
+ * and empty cells are also indicated with `Nothing`.
537
535
  */
538
- matchOpenDelimiter(openDelim: Delimiter, closeDelim: Delimiter): LatexToken[] | null;
539
- matchMiddleDelimiter(delimiter: '|' | ':' | LatexToken): boolean;
536
+ parseTabular(): null | Expression[][];
540
537
  /**
541
- * Match a sequence superfix/subfix operator, e.g. `^{*}`
542
- *
543
- * Superfix and subfix need special handling:
538
+ * Parse an argument list, for example: `(12, x+1)` or `\left(x\right)`
544
539
  *
545
- * - they act mostly like an infix operator, but they are commutative, i.e.
546
- * `x_a^b` should be parsed identically to `x^b_a`.
547
- *
548
- * - furthermore, in LaTeX `x^a^b` parses the same as `x^a{}^b`.
540
+ * - 'enclosure' : will look for arguments inside an enclosure
541
+ * (an open/close fence) (**default**)
542
+ * - 'implicit': either an expression inside a pair of `()`, or just a primary
543
+ * (i.e. we interpret `\cos x + 1` as `\cos(x) + 1`)
549
544
  *
545
+ * Return an array of expressions, one for each argument, or `null` if no
546
+ * argument was found.
550
547
  */
551
- matchSupsub(lhs: Expression | null): Expression | null;
548
+ parseArguments(kind?: 'implicit' | 'enclosure', until?: Terminator): Expression[] | null;
552
549
  /**
550
+ * Parse a postfix operator, such as `'` or `!`.
553
551
  *
554
- * ```
555
- * <primary> :=
556
- * (<number> | <symbol> | <latex-command> | <function-call> | <matchfix-expr>)
557
- * (<subsup> | <postfix-operator>)*
558
- * ```
559
- *
560
- * ```
561
- * <matchfix-expr> :=
562
- * <matchfix-op-open> <expression> <matchfix-op-close>
563
- *```
552
+ * Prefix, infix and matchfix operators are handled by `parseExpression()`
564
553
  *
565
- *```
566
- * <function-call> ::=
567
- * | <function><matchfix-op-group-open><expression>[',' <expression>]<matchfix-op-group-close>
568
- *```
569
- * If not a primary, return `null` and do not advance the index.
570
554
  */
571
- matchPrimary(): Expression | null;
572
- /**
573
- * A symbol can be:
574
- * - a single-letter variable: `x`
575
- * - a single LaTeX command: `\pi`
576
- */
577
- matchSymbol(until?: Terminator): Expression | null;
555
+ parsePostfixOperator(lhs: Expression | null, until?: Partial<Terminator>): Expression | null;
578
556
  /**
579
557
  * Parse an expression:
580
558
  *
581
559
  * ```
582
560
  * <expression> ::=
561
+ * | <primary> ( <infix-op> <expression> )?
583
562
  * | <prefix-op> <expression>
584
- * | <primary>
585
- * | <primary> <infix-op> <expression>
563
+ *
564
+ * <primary> :=
565
+ * (<number> | <symbol> | <function-call> | <matchfix-expr>)
566
+ * (<subsup> | <postfix-operator>)*
567
+ *
568
+ * <matchfix-expr> :=
569
+ * <matchfix-op-open> <expression> <matchfix-op-close>
570
+ *
571
+ * <function-call> ::=
572
+ * | <function><matchfix-op-group-open><expression>[',' <expression>]<matchfix-op-group-close>
586
573
  * ```
587
574
  *
588
575
  * This is the top-level parsing entry point.
@@ -592,8 +579,23 @@ export interface Parser {
592
579
  *
593
580
  * `until` is `{ minPrec:0 }` by default.
594
581
  */
595
- matchExpression(until?: Partial<Terminator>): Expression | null;
596
- latex(start: number, end?: number): string;
597
- /** Return an error expression with the specified code and arguments */
598
- error(code: string | [string, ...Expression[]], fromToken: number): Expression;
582
+ parseExpression(until?: Partial<Terminator>): Expression | null;
583
+ /**
584
+ * Boundaries are used to detect the end of an expression.
585
+ *
586
+ * They are used for unusual syntactic constructs, for example
587
+ * `\int \sin x dx` where the `dx` is not an argument to the `\sin`
588
+ * function, but a boundary of the integral.
589
+ *
590
+ * They are also useful when handling syntax errors and recovery.
591
+ *
592
+ * For example, `\begin{bmatrix} 1 & 2 { \end{bmatrix}` has an
593
+ * extraneous `{`, but the parser will attempt to recover and continue
594
+ * parsing when it encounters the `\end{bmatrix}` boundary.
595
+ */
596
+ addBoundary(boundary: LatexToken[]): void;
597
+ removeBoundary(): void;
598
+ get atBoundary(): boolean;
599
+ matchBoundary(): boolean;
600
+ boundaryError(msg: string | [string, ...Expression[]]): Expression;
599
601
  }
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  import { NumberFormattingOptions } from './public';
3
3
  export declare function serializeNumber(expr: Expression | null, options: NumberFormattingOptions): string;
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare function getApplyFunctionStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
3
3
  export declare function getGroupStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
4
4
  export declare function getRootStyle(_expr: Expression | null, level: number): 'radical' | 'quotient' | 'solidus';
@@ -1,7 +1,7 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  import { WarningSignalHandler } from '../../common/signals';
3
3
  import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
4
- import { IndexedLatexDictionary, IndexedIdentifierEntry, IndexedFunctionEntry } from './dictionary/definitions';
4
+ import { IndexedLatexDictionary, IndexedSymbolEntry, IndexedFunctionEntry } from './dictionary/definitions';
5
5
  export declare class Serializer {
6
6
  readonly onError: WarningSignalHandler;
7
7
  options: NumberFormattingOptions & SerializeLatexOptions;
@@ -25,8 +25,8 @@ export declare class Serializer {
25
25
  wrapShort(expr: Expression | null): string;
26
26
  wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none', fence?: string): string;
27
27
  wrapArguments(expr: Expression): string;
28
- serializeSymbol(expr: Expression, def?: IndexedIdentifierEntry | IndexedFunctionEntry): string;
29
- serializeFunction(expr: Expression, def?: IndexedFunctionEntry | IndexedIdentifierEntry): string;
28
+ serializeSymbol(expr: Expression, def?: IndexedSymbolEntry | IndexedFunctionEntry): string;
29
+ serializeFunction(expr: Expression, def?: IndexedFunctionEntry | IndexedSymbolEntry): string;
30
30
  serializeDictionary(dict: {
31
31
  [key: string]: Expression;
32
32
  }): string;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  * ## Reference
3
3
  * TeX source code:
4
4
  * {@link http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.web | Tex.web}
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  /** The canonical form of `Add`:
3
3
  * - removes `0`
4
4
  * - capture complex numbers (a + ib or ai +b)
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  /**
3
3
  * Canonical form of 'Divide' (and 'Rational')
4
4
  * - remove denominator of 1
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  /** The canonical form of `Multiply`:
3
3
  * - remove `1`
4
4
  * - combine literal integers and rationals
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  /**
3
3
  *
4
4
  */
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const ARITHMETIC_LIBRARY: IdTable[];
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const CALCULUS_LIBRARY: IdTable[];
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const COLLECTIONS_LIBRARY: IdTable;
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const CORE_LIBRARY: IdTable[];
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const DOMAIN_CONSTRUCTORS: string[];
3
3
  export declare const DOMAIN_ALIAS: {
4
4
  NumericFunction: (string | string[])[];
@@ -13,3 +13,4 @@ export declare function isSubdomainLiteral(lhs: string, rhs: string): boolean;
13
13
  /** Return all the domain literals that are an ancestor of `dom`
14
14
  */
15
15
  export declare function ancestors(dom: string): string[];
16
+ export declare function domainSetsLibrary(): IdTable;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  import { IComputeEngine, IdTable } from '../public';
3
3
  export declare function getStandardLibrary(categories: LibraryCategory[] | LibraryCategory | 'all'): Readonly<IdTable>[];
4
4
  export declare const LIBRARIES: {
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const LOGIC_LIBRARY: IdTable;
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const POLYNOMIALS_LIBRARY: IdTable[];
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare function randomExpression(level?: number): Expression;
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const RELOP_LIBRARY: IdTable;
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const SETS_LIBRARY: IdTable;
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare const TRIGONOMETRY_LIBRARY: IdTable[];
@@ -1,3 +1,3 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare function isSymbolDefinition(def: BoxedSymbolDefinition | BoxedFunctionDefinition | SymbolDefinition | FunctionDefinition | undefined | null): def is BoxedSymbolDefinition;
3
3
  export declare function isFunctionDefinition(def: BoxedSymbolDefinition | BoxedFunctionDefinition | SymbolDefinition | FunctionDefinition | undefined | null): def is BoxedFunctionDefinition;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare function bigint(a: Decimal | number | bigint | string): bigint;
3
3
  export declare function gcd(a: bigint, b: bigint): bigint;
4
4
  export declare function lcm(a: bigint, b: bigint): bigint;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  import { IComputeEngine } from '../public';
3
3
  export declare function gcd(a: Decimal, b: Decimal): Decimal;
4
4
  export declare function lcm(a: Decimal, b: Decimal): Decimal;
@@ -1,3 +1,3 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare function gamma(c: Complex): Complex;
3
3
  export declare function lngamma(c: Complex): Complex;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  import Decimal from 'decimal.js';
3
3
  import { BoxedExpression } from '../public';
4
4
  export declare const MACHINE_PRECISION_BITS = 53;
@@ -1,2 +1,2 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare function isPrime(n: number): boolean | undefined;
@@ -1,4 +1,4 @@
1
- /* 0.12.4 */
1
+ /* 0.12.6 */
2
2
  export declare function isRational(x: any | null): x is Rational;
3
3
  export declare function isMachineRational(x: any | null): x is [number, number];
4
4
  export declare function isBigRational(x: any | null): x is [bigint, bigint];