@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,19 +1,26 @@
1
- /* 0.4.2 */
2
- import type { Dictionary, CompiledDictionary, ComputeEngine, Numeric } from '../public';
3
- export declare function getDefaultDictionaries<T extends number = number>(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary<T>>[];
4
- export declare const DICTIONARY: {
5
- [category in DictionaryCategory]?: Dictionary<Numeric>;
1
+ /* 0.4.3 */
2
+ import { IComputeEngine, Dictionary } from '../public';
3
+ export declare function getDefaultDictionaries(categories?: DictionaryCategory[] | 'all'): Readonly<Dictionary>[];
4
+ export declare const DICTIONARIES: {
5
+ [category in DictionaryCategory]?: Readonly<Dictionary> | Readonly<Dictionary>[];
6
6
  };
7
7
  /**
8
- * Return a compiled and validated version of the dictionary.
8
+ * Set the dictionary of the current context (`engine.context`) to `dicts`
9
+ *
10
+ * `dicts` can be an array of dictionaries, in order to deal with circular
11
+ * dependencies: it is possible to partition a dictionary into multiple
12
+ * sub-dictionary, to control the order in which they are processe and
13
+ * avoid having expressions in the definition of an entry reference a symbol
14
+ * or function name that has not yet been added to the dictionary.
9
15
  *
10
16
  * Specifically:
11
- * - Expressions (for values, evaluate, domain, isElementOf, etc..) are compiled
12
- * when possible, put in canonical form otherwise
17
+ * - Expressions (for values, evaluate, domain, isElementOf, etc..) are boxed
13
18
  * - The domain of entries is inferred and validated:
14
19
  * - check that domains are in canonical form
15
- * - check that domains are consistent with declarations (for example that
16
- * the signature of predicate have a "MaybeBoolean" codomain)
20
+ * - check that domains are consistent with declarations
17
21
  *
18
22
  */
19
- export declare function compileDictionary<T extends number = Numeric>(dict: Dictionary<T>, engine: ComputeEngine<T>): CompiledDictionary<T>;
23
+ export declare function setCurrentContextDictionary(engine: IComputeEngine, dicts: Dictionary | Dictionary[] | undefined): void;
24
+ /**
25
+ * For debugging: a textual representation of the inheritance chain of sets.
26
+ */
@@ -1,2 +1,2 @@
1
- /* 0.4.2 */
1
+ /* 0.4.3 */
2
2
  export declare const LOGIC_DICTIONARY: Dictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const POLYNOMIALS_DICTIONARY: Dictionary[];
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const RELOP_DICTIONARY: Dictionary;
@@ -1,2 +1,2 @@
1
- /* 0.4.2 */
1
+ /* 0.4.3 */
2
2
  export declare const SETS_DICTIONARY: Dictionary;
@@ -1,2 +1,2 @@
1
- /* 0.4.2 */
2
- export declare const TRIGONOMETRY_DICTIONARY: Dictionary;
1
+ /* 0.4.3 */
2
+ export declare const TRIGONOMETRY_DICTIONARY: Dictionary[];
@@ -0,0 +1,30 @@
1
+ /* 0.4.3 */
2
+ import { Decimal } from 'decimal.js';
3
+ import { BoxedExpression } from './public';
4
+ /** Quickly determine the numeric domain of a number or constant
5
+ * For the symbols, this is a hard-coded optimization that doesn't rely on the
6
+ * dictionaries. The regular path is in `internalDomain()`
7
+ */
8
+ export declare function inferNumericDomain(value: number | Decimal | Complex | [numer: number, denom: number]): string;
9
+ /**
10
+ * Simple description of a numeric domain as a base domain, a min and
11
+ * max value, possibly open ends, and some excluded values.
12
+ */
13
+ export declare type NumericDomainInfo = {
14
+ domain?: string;
15
+ min?: number;
16
+ max?: number;
17
+ open?: 'left' | 'right' | 'both';
18
+ /** Values from _excludedValues_ are considered not in this domain */
19
+ excludedValues?: number[];
20
+ /** If defined, the values in this domain must follow the relation
21
+ * _period_ * _n_ + _phase_ when _n_ is in _domain_.
22
+ */
23
+ multiple?: [period: number, domain: BoxedExpression, phase: number];
24
+ };
25
+ /**
26
+ * Return an efficient data structure describing a numeric domain,
27
+ * an `Interval` or `Range`
28
+ * @todo could also check for `Multiple`
29
+ */
30
+ export declare function inferNumericDomainInfo(expr: BoxedExpression): NumericDomainInfo | null;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const DEFINITIONS_ALGEBRA: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const DEFINITIONS_ARITHMETIC: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const DEFINITIONS_CALCULUS: LatexDictionary;
@@ -0,0 +1,4 @@
1
+ /* 0.4.3 */
2
+ import { LatexDictionary, Serializer } from '../public';
3
+ export declare function serializeLatex(serializer: Serializer, expr: Expression | null): string;
4
+ export declare const DEFINITIONS_CORE: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const DEFINITIONS_INEQUALITIES: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const DEFINITIONS_LOGIC: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const DEFINITIONS_OTHERS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const DEFINITIONS_SETS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const DEFINITIONS_SYMBOLS: LatexDictionary;
@@ -0,0 +1,2 @@
1
+ /* 0.4.3 */
2
+ export declare const DEFINITIONS_TRIGONOMETRY: LatexDictionary;
@@ -0,0 +1,57 @@
1
+ /* 0.4.3 */
2
+ import { WarningSignal } from '../../../common/signals';
3
+ export declare type CommonEntry = {
4
+ name?: string;
5
+ serialize: SerializeHandler | LatexString;
6
+ };
7
+ export declare type SymbolEntry = CommonEntry & {
8
+ kind: 'symbol';
9
+ precedence: number;
10
+ arguments: 'group' | 'implicit' | '';
11
+ optionalLatexArg: number;
12
+ requiredLatexArg: number;
13
+ parse: SymbolParseHandler;
14
+ };
15
+ export declare type MatchfixEntry = CommonEntry & {
16
+ kind: 'matchfix';
17
+ openDelimiter: Delimiter | LatexToken[];
18
+ closeDelimiter: Delimiter | LatexToken[];
19
+ parse: MatchfixParseHandler;
20
+ };
21
+ export declare type InfixEntry = CommonEntry & {
22
+ kind: 'infix';
23
+ associativity: 'right' | 'left' | 'non' | 'both';
24
+ precedence: number;
25
+ parse: InfixParseHandler;
26
+ };
27
+ export declare type PrefixEntry = CommonEntry & {
28
+ kind: 'prefix';
29
+ precedence: number;
30
+ parse: PrefixParseHandler;
31
+ };
32
+ export declare type PostfixEntry = CommonEntry & {
33
+ kind: 'postfix';
34
+ precedence: number;
35
+ parse: PostfixParseHandler;
36
+ };
37
+ export declare type EnvironmentEntry = CommonEntry & {
38
+ kind: 'environment';
39
+ optionalLatexArg: number;
40
+ requiredLatexArg: number;
41
+ parse: EnvironmentParseHandler;
42
+ };
43
+ export declare type IndexedLatexDictionaryEntry = SymbolEntry | MatchfixEntry | InfixEntry | PrefixEntry | PostfixEntry | EnvironmentEntry;
44
+ export declare type IndexedLatexDictionary = {
45
+ lookahead: number;
46
+ name: Map<string, IndexedLatexDictionaryEntry>;
47
+ symbol: (Map<LatexString, SymbolEntry[]> | null)[];
48
+ prefix: (Map<LatexString, PrefixEntry[]> | null)[];
49
+ infix: (Map<LatexString, InfixEntry[]> | null)[];
50
+ postfix: (Map<LatexString, PostfixEntry[]> | null)[];
51
+ matchfix: MatchfixEntry[];
52
+ environment: Map<string, EnvironmentEntry>;
53
+ };
54
+ export declare function indexLatexDictionary(dic: readonly LatexDictionaryEntry[], onError: (sig: WarningSignal) => void): IndexedLatexDictionary;
55
+ export declare const DEFAULT_LATEX_DICTIONARY: {
56
+ [category in DictionaryCategory]?: LatexDictionary;
57
+ };
@@ -0,0 +1,23 @@
1
+ /* 0.4.3 */
2
+ import { Serializer } from './serializer';
3
+ import { Expression } from '../../math-json/math-json-format';
4
+ import { WarningSignalHandler } from '../../common/signals';
5
+ import { IComputeEngine } from '../public';
6
+ export declare const DEFAULT_SERIALIZE_LATEX_OPTIONS: Required<SerializeLatexOptions>;
7
+ export declare class LatexSyntax {
8
+ onError: WarningSignalHandler;
9
+ options: Required<NumberFormattingOptions> & Required<ParseLatexOptions> & Required<SerializeLatexOptions>;
10
+ readonly computeEngine: IComputeEngine;
11
+ private dictionary;
12
+ private _serializer?;
13
+ constructor(options: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions> & {
14
+ computeEngine: IComputeEngine;
15
+ dictionary?: readonly LatexDictionaryEntry[];
16
+ onError?: WarningSignalHandler;
17
+ });
18
+ updateOptions(opt: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions> & Partial<SerializeLatexOptions>): void;
19
+ static getDictionary(domain?: DictionaryCategory | 'all'): Readonly<LatexDictionary>;
20
+ parse(latex: LatexString): Expression;
21
+ serialize(expr: Expression): LatexString;
22
+ get serializer(): Serializer;
23
+ }
@@ -0,0 +1,198 @@
1
+ /* 0.4.3 */
2
+ import { ParseLatexOptions, LatexToken, NumberFormattingOptions, Delimiter, Terminator, Parser } from './public';
3
+ import { IndexedLatexDictionary, InfixEntry, PostfixEntry, PrefixEntry, SymbolEntry } from './dictionary/definitions';
4
+ import { WarningSignalHandler } from '../../common/signals';
5
+ import { IComputeEngine } from '../public';
6
+ export declare const DEFAULT_LATEX_NUMBER_OPTIONS: Required<NumberFormattingOptions>;
7
+ export declare const DEFAULT_PARSE_LATEX_OPTIONS: Required<ParseLatexOptions>;
8
+ export declare class _Parser implements Parser {
9
+ readonly onError: WarningSignalHandler;
10
+ readonly options: Required<NumberFormattingOptions> & Required<ParseLatexOptions>;
11
+ readonly engine: IComputeEngine;
12
+ readonly _dictionary: IndexedLatexDictionary;
13
+ index: number;
14
+ _lastPeek: string;
15
+ _peekCounter: number;
16
+ readonly _tokens: LatexToken[];
17
+ constructor(tokens: LatexToken[], options: Required<NumberFormattingOptions> & Required<ParseLatexOptions>, dictionary: IndexedLatexDictionary, computeEngine: IComputeEngine, onError: WarningSignalHandler);
18
+ updateOptions(opt: Partial<NumberFormattingOptions> & Partial<ParseLatexOptions>): void;
19
+ clone(start: number, end: number): Parser;
20
+ get atEnd(): boolean;
21
+ get peek(): LatexToken;
22
+ /**
23
+ * Return true if
24
+ * - at end of the token stream
25
+ * - the upcoming tokens match `t.tokens`
26
+ * - the `t.condition` function returns true
27
+ * Note: the `minPrec` condition is not checked. It should be checked separately.
28
+ */
29
+ atTerminator(t?: Terminator): boolean;
30
+ latex(start: number, end?: number): string;
31
+ latexAhead(n: number): string;
32
+ latexBefore(): string;
33
+ latexAfter(): string;
34
+ /**
35
+ * Return at most `lookahead` strings made from the tokens
36
+ * ahead.
37
+ *
38
+ * The index in the returned array correspond to the number of tokens.
39
+ * Note that since a token can be longer than one char ('\\pi', but also
40
+ * some astral plane unicode characters), the length of the string
41
+ * does not match that index. However, knowing the index is important
42
+ * to know by how many tokens to advance.
43
+ *
44
+ */
45
+ lookAhead(): string[];
46
+ /** Return all the definitions that potentially match the tokens ahead */
47
+ peekDefinitions(kind: 'symbol'): [SymbolEntry, number][] | null;
48
+ peekDefinitions(kind: 'postfix'): [PostfixEntry, number][] | null;
49
+ peekDefinitions(kind: 'postfix'): [PostfixEntry, number][] | null;
50
+ peekDefinitions(kind: 'operator'): [InfixEntry | PrefixEntry | PostfixEntry, number][] | null;
51
+ peekDefinitions(kind: 'infix'): [InfixEntry, number][] | null;
52
+ peekDefinitions(kind: 'prefix'): [PrefixEntry, number][] | null;
53
+ next(): LatexToken;
54
+ skipSpace(): boolean;
55
+ matchChar(): string | null;
56
+ matchColor(_background?: boolean): string | null;
57
+ matchLatexDimension(): string | null;
58
+ match(token: LatexToken): boolean;
59
+ matchAll(tokens: LatexToken | LatexToken[]): boolean;
60
+ matchAny(tokens: LatexToken[]): LatexToken;
61
+ matchWhile(tokens: LatexToken[]): LatexToken[];
62
+ matchSign(): string;
63
+ matchDecimalDigits(): string;
64
+ matchSignedInteger(): string;
65
+ matchExponent(): string;
66
+ matchNumber(): string;
67
+ /**
68
+ * A Latex number can be a decimal, hex or octal number.
69
+ * It is used in some Latex commands, such as `\char`
70
+ *
71
+ * From TeX:8695 (scan_int):
72
+ * > An integer number can be preceded by any number of spaces and `+' or
73
+ * > `-' signs. Then comes either a decimal constant (i.e., radix 10), an
74
+ * > octal constant (i.e., radix 8, preceded by '), a hexadecimal constant
75
+ * > (radix 16, preceded by "), an alphabetic constant (preceded by `), or
76
+ * > an internal variable.
77
+ */
78
+ matchLatexNumber(isInteger?: boolean): null | number;
79
+ matchPrefixOperator(until?: Terminator): Expression | null;
80
+ matchInfixOperator(lhs: Expression, until?: Terminator): Expression | null;
81
+ /**
82
+ * 'group' : will look for an argument inside a pair of `()`
83
+ * 'implicit': either an expression inside a pair of `()`, or just a primary
84
+ * (i.e. we interpret `\cos x + 1` as `\cos(x) + 1`)
85
+ */
86
+ matchArguments(kind: undefined | '' | 'group' | 'implicit'): Expression[] | null;
87
+ /** If matches the normalized open delimiter, returns the
88
+ * expected closing delimiter.
89
+ *
90
+ * For example, if `delimiter` is `(`, it would match `\left\lparen` and
91
+ * return `['\right', '\rparen']`, which can be matched with `matchAll()`
92
+ *
93
+ * If you need to match several tokens, use `matchAll()`
94
+ */
95
+ matchOpenDelimiter(openDelim: Delimiter, closeDelim: Delimiter): LatexToken[] | null;
96
+ matchMiddleDelimiter(delimiter: '|' | ':' | LatexToken): boolean;
97
+ /**
98
+ * An enclosure is an opening matchfix operator, an expression, optionally
99
+ * followed multiple times by a separator and another expression,
100
+ * and finally a closing matching operator.
101
+ */
102
+ matchEnclosure(): Expression | null;
103
+ /**
104
+ * A symbol can be:
105
+ * - a constant: `\pi`
106
+ * - a variable: `x`
107
+ * - a function with explicit arguments `f(x)`
108
+ * - a function with implicit arguments: `\cos x`
109
+ * - a command: `\frac{2}{3}`
110
+ */
111
+ matchSymbol(): Expression | null;
112
+ matchOptionalLatexArgument(): Expression | null;
113
+ /**
114
+ * Match a required LaTeX argument:
115
+ * - either enclosed in `{}`
116
+ * - or a single token.
117
+ *
118
+ * Return null if an argument was not found
119
+ * Return 'Nothing' if an empty argument `{}` was found
120
+ */
121
+ matchRequiredLatexArgument(): Expression | null;
122
+ /**
123
+ * Match a sequence superfix/subfix operator, e.g. `^{*}`
124
+ *
125
+ * Superfix and subfix need special handling:
126
+ *
127
+ * - they act mostly like an infix operator, but they are commutative, i.e.
128
+ * `x_a^b` should be parsed identically to `x^b_a`.
129
+ *
130
+ * - furthermore, in LaTeX, consecutive `^` or `_` are treated as concatenated,
131
+ * that is `x^a^b` parses the same as `x^{ab}`.
132
+ *
133
+ */
134
+ matchSupsub(lhs: Expression | null): Expression | null;
135
+ matchPostfix(lhs: Expression | null): Expression | null;
136
+ matchString(until: {
137
+ tokens: LatexToken[];
138
+ } & Partial<Terminator>): string;
139
+ matchEnvironmentName(command: '\\begin' | '\\end', envName: string): boolean;
140
+ /**
141
+ * Match an expression in a tabular format,
142
+ * where row are separated by `\\` and columns by `&`
143
+ *
144
+ * Return rows of sparse columns as a list: empty rows are indicated with NOTHING,
145
+ * and empty cells are also indicated with NOTHING.
146
+ */
147
+ matchTabular(endName: string): null | Expression;
148
+ matchEnvironment(): Expression | null;
149
+ /**
150
+ * Apply an invisible operator between two expressions.
151
+ *
152
+ * If the `lhs` is an literal integer and the `rhs` is a literal rational
153
+ * -> 'invisible plus'
154
+ *
155
+ * That is '2 3/4' -> ['Add', 2, ['Rational', 3, 4]]
156
+ *
157
+ * If `lhs` is a number and `rhs` is a number but not a literal -> 'invisible multiply'.
158
+ * - 2x
159
+ * - 2(x+1)
160
+ * - x(x+1)
161
+ * - f(x)g(y)
162
+ * - 2 sin(x)
163
+ * - 2 f(x)
164
+ * - x f(x)
165
+ * - (x-1)(x+1)
166
+ * - (x+1)2 -> no
167
+ * - x2 -> no
168
+ * => lhs is a number, rhs is a number, but not a literal
169
+ */
170
+ applyInvisibleOperator(terminator: Terminator, rawLhs: Expression | null): Expression | null;
171
+ matchUnknownLatexCommand(): Expression | null;
172
+ /**
173
+ * <primary> :=
174
+ * (<number> | <symbol> | <environment> | <matchfix-expr>) <subsup>* <postfix-operator>*
175
+ *
176
+ * <symbol> ::= (<symbol-id> | (<latex-command><latex-arguments>)) <arguments>
177
+ *
178
+ * <matchfix-expr> :=
179
+ * <matchfix-op-open> <expression> [<matchfix-op-separator> <expression>] <matchfix-op-close>
180
+ *
181
+ */
182
+ matchPrimary(): Expression | null;
183
+ /**
184
+ * Parse an expression:
185
+ *
186
+ * <expression> ::=
187
+ * | <primary>
188
+ * | <prefix-op> <primary>
189
+ * | <primary> <infix-op> <expression>
190
+ *
191
+ * Stop when an operator of precedence less than `minPrec` is encountered
192
+ */
193
+ matchExpression(until?: Partial<Terminator>): Expression | null;
194
+ /**
195
+ * Add latex or other requested metadata to the expression
196
+ */
197
+ decorate(expr: Expression | null, start: number): Expression | null;
198
+ }