@cortex-js/compute-engine 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{compute-engine.js → compute-engine.cjs} +24718 -24251
- package/dist/compute-engine.esm.js +24718 -24251
- package/dist/compute-engine.min.cjs +129 -0
- package/dist/compute-engine.min.esm.js +55 -68
- package/dist/math-json.cjs +413 -0
- package/dist/math-json.esm.js +287 -7
- package/dist/math-json.min.cjs +6 -0
- package/dist/math-json.min.esm.js +287 -7
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/fuzzy-string-match.d.ts +2 -0
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/interruptible.d.ts +2 -2
- package/dist/types/common/json5.d.ts +3 -0
- package/dist/types/common/one-of.d.ts +2 -1
- package/dist/types/common/signals.d.ts +1 -2
- package/dist/types/common/type/boxed-type.d.ts +14 -0
- package/dist/types/common/type/parse.d.ts +1 -1
- package/dist/types/common/type/primitive.d.ts +2 -1
- package/dist/types/common/type/serialize.d.ts +1 -1
- package/dist/types/common/type/subtype.d.ts +1 -1
- package/dist/types/common/type/types.d.ts +121 -136
- package/dist/types/common/type/utils.d.ts +3 -7
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +17 -18
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +5 -4
- package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +27 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +5 -5
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +20 -14
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +14 -13
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +8 -10
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +4 -5
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +6 -5
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +11 -11
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +7 -10
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +2 -1
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -3
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +3 -2
- package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/product.d.ts +5 -5
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -2
- package/dist/types/compute-engine/boxed-expression/terms.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +2 -9
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +13 -4
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +9 -10
- package/dist/types/compute-engine/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compile.d.ts +2 -4
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/{boxed-expression/public.d.ts → global-types.d.ts} +887 -849
- package/dist/types/compute-engine/{compute-engine.d.ts → index.d.ts} +29 -19
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/{public.d.ts → types.d.ts} +13 -6
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -2
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +3 -2
- package/dist/types/compute-engine/library/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/invisible-operator.d.ts +2 -2
- package/dist/types/compute-engine/library/library.d.ts +3 -3
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +3 -5
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +3 -4
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +3 -5
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +3 -4
- package/dist/types/compute-engine/numeric-value/{public.d.ts → types.d.ts} +9 -5
- package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
- package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +2 -7
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -5
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +4 -4
- package/dist/types/compute-engine/numerics/statistics.d.ts +2 -2
- package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
- package/dist/types/compute-engine/numerics/types.d.ts +30 -0
- package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/{boxed-expression → tensor}/tensor-fields.d.ts +19 -18
- package/dist/types/compute-engine/tensor/tensors.d.ts +9 -12
- package/dist/types/compute-engine/types.d.ts +11 -0
- package/dist/types/compute-engine.d.ts +3 -5
- package/dist/types/math-json/identifiers.d.ts +1 -1
- package/dist/types/math-json/types.d.ts +9 -7
- package/dist/types/math-json/utils.d.ts +3 -3
- package/dist/types/math-json.d.ts +3 -3
- package/package.json +9 -9
- package/dist/compute-engine.min.js +0 -142
- package/dist/math-json.js +0 -133
- package/dist/math-json.min.js +0 -4
- package/dist/types/common/buffer.d.ts +0 -9
- package/dist/types/common/styled-text.d.ts +0 -28
- package/dist/types/common/suggest.d.ts +0 -1
- package/dist/types/common/syntax-highlighter.d.ts +0 -40
- package/dist/types/common/terminal.d.ts +0 -19
- package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +0 -12
- package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +0 -16
- package/dist/types/compute-engine/debug.d.ts +0 -3
- package/dist/types/compute-engine/numerics/bignum.d.ts +0 -12
- package/dist/types/compute-engine/private.d.ts +0 -29
- package/dist/types/compute-engine/public.d.ts +0 -42
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/** MathJSON 0.29.0 */
|
|
2
|
+
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';
|
|
3
|
+
var MathJson = (() => {
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/math-json.ts
|
|
23
|
+
var math_json_exports = {};
|
|
24
|
+
__export(math_json_exports, {
|
|
25
|
+
dictionaryFromExpression: () => dictionaryFromExpression,
|
|
26
|
+
isFunctionObject: () => isFunctionObject,
|
|
27
|
+
isStringObject: () => isStringObject,
|
|
28
|
+
isSymbolObject: () => isSymbolObject,
|
|
29
|
+
mapArgs: () => mapArgs,
|
|
30
|
+
operand: () => operand,
|
|
31
|
+
operator: () => operator,
|
|
32
|
+
stringValue: () => stringValue,
|
|
33
|
+
symbol: () => symbol,
|
|
34
|
+
version: () => version
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// src/common/json5.ts
|
|
38
|
+
var JSON5 = class {
|
|
39
|
+
static parse(input) {
|
|
40
|
+
const parser = new JSON5Parser(input);
|
|
41
|
+
const value = parser.parseValue();
|
|
42
|
+
parser.skipWhitespace();
|
|
43
|
+
if (!parser.isAtEnd()) {
|
|
44
|
+
throw parser.error(
|
|
45
|
+
`Unexpected token '${parser.currentChar()}' after parsing complete value`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var JSON5Parser = class {
|
|
52
|
+
constructor(input) {
|
|
53
|
+
this.index = 0;
|
|
54
|
+
this.text = input;
|
|
55
|
+
}
|
|
56
|
+
parseValue() {
|
|
57
|
+
this.skipWhitespace();
|
|
58
|
+
if (this.isAtEnd()) {
|
|
59
|
+
throw this.error("Unexpected end of input");
|
|
60
|
+
}
|
|
61
|
+
const ch = this.currentChar();
|
|
62
|
+
if (ch === "{") return this.parseObject();
|
|
63
|
+
if (ch === "[") return this.parseArray();
|
|
64
|
+
if (ch === '"' || ch === "'") return this.parseString();
|
|
65
|
+
if (ch === "-" || ch === "+" || ch >= "0" && ch <= "9" || ch === ".")
|
|
66
|
+
return this.parseNumber();
|
|
67
|
+
return this.parseIdentifier();
|
|
68
|
+
}
|
|
69
|
+
parseObject() {
|
|
70
|
+
const obj = {};
|
|
71
|
+
this.expectChar("{");
|
|
72
|
+
this.skipWhitespace();
|
|
73
|
+
if (this.currentChar() === "}") {
|
|
74
|
+
this.index++;
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
while (true) {
|
|
78
|
+
this.skipWhitespace();
|
|
79
|
+
let key;
|
|
80
|
+
const ch = this.currentChar();
|
|
81
|
+
if (ch === '"' || ch === "'") {
|
|
82
|
+
key = this.parseString();
|
|
83
|
+
} else {
|
|
84
|
+
key = this.parseIdentifier();
|
|
85
|
+
}
|
|
86
|
+
this.skipWhitespace();
|
|
87
|
+
this.expectChar(":");
|
|
88
|
+
this.skipWhitespace();
|
|
89
|
+
const value = this.parseValue();
|
|
90
|
+
obj[key] = value;
|
|
91
|
+
this.skipWhitespace();
|
|
92
|
+
if (this.currentChar() === ",") {
|
|
93
|
+
this.index++;
|
|
94
|
+
this.skipWhitespace();
|
|
95
|
+
if (this.currentChar() === "}") {
|
|
96
|
+
this.index++;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
} else if (this.currentChar() === "}") {
|
|
100
|
+
this.index++;
|
|
101
|
+
break;
|
|
102
|
+
} else {
|
|
103
|
+
throw this.error(
|
|
104
|
+
`Expected ',' or '}' in object but found '${this.currentChar()}'`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return obj;
|
|
109
|
+
}
|
|
110
|
+
parseArray() {
|
|
111
|
+
const arr = [];
|
|
112
|
+
this.expectChar("[");
|
|
113
|
+
this.skipWhitespace();
|
|
114
|
+
if (this.currentChar() === "]") {
|
|
115
|
+
this.index++;
|
|
116
|
+
return arr;
|
|
117
|
+
}
|
|
118
|
+
while (true) {
|
|
119
|
+
this.skipWhitespace();
|
|
120
|
+
arr.push(this.parseValue());
|
|
121
|
+
this.skipWhitespace();
|
|
122
|
+
if (this.currentChar() === ",") {
|
|
123
|
+
this.index++;
|
|
124
|
+
this.skipWhitespace();
|
|
125
|
+
if (this.currentChar() === "]") {
|
|
126
|
+
this.index++;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
} else if (this.currentChar() === "]") {
|
|
130
|
+
this.index++;
|
|
131
|
+
break;
|
|
132
|
+
} else {
|
|
133
|
+
throw this.error(
|
|
134
|
+
`Expected ',' or ']' in array but found '${this.currentChar()}'`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return arr;
|
|
139
|
+
}
|
|
140
|
+
parseString() {
|
|
141
|
+
const quote = this.currentChar();
|
|
142
|
+
if (quote !== '"' && quote !== "'") {
|
|
143
|
+
throw this.error(`String should start with a quote, got '${quote}'`);
|
|
144
|
+
}
|
|
145
|
+
this.index++;
|
|
146
|
+
let result = "";
|
|
147
|
+
while (!this.isAtEnd()) {
|
|
148
|
+
const ch = this.currentChar();
|
|
149
|
+
if (ch === quote) {
|
|
150
|
+
this.index++;
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
if (ch === "\\") {
|
|
154
|
+
this.index++;
|
|
155
|
+
if (this.isAtEnd()) {
|
|
156
|
+
throw this.error("Unterminated escape sequence in string");
|
|
157
|
+
}
|
|
158
|
+
const esc = this.currentChar();
|
|
159
|
+
switch (esc) {
|
|
160
|
+
case "b":
|
|
161
|
+
result += "\b";
|
|
162
|
+
break;
|
|
163
|
+
case "f":
|
|
164
|
+
result += "\f";
|
|
165
|
+
break;
|
|
166
|
+
case "n":
|
|
167
|
+
result += "\n";
|
|
168
|
+
break;
|
|
169
|
+
case "r":
|
|
170
|
+
result += "\r";
|
|
171
|
+
break;
|
|
172
|
+
case "t":
|
|
173
|
+
result += " ";
|
|
174
|
+
break;
|
|
175
|
+
case "v":
|
|
176
|
+
result += "\v";
|
|
177
|
+
break;
|
|
178
|
+
case "\\":
|
|
179
|
+
result += "\\";
|
|
180
|
+
break;
|
|
181
|
+
case "'":
|
|
182
|
+
result += "'";
|
|
183
|
+
break;
|
|
184
|
+
case '"':
|
|
185
|
+
result += '"';
|
|
186
|
+
break;
|
|
187
|
+
case "0":
|
|
188
|
+
result += "\0";
|
|
189
|
+
break;
|
|
190
|
+
case "u": {
|
|
191
|
+
this.index++;
|
|
192
|
+
const hex = this.text.substr(this.index, 4);
|
|
193
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex)) {
|
|
194
|
+
throw this.error(`Invalid Unicode escape sequence: \\u${hex}`);
|
|
195
|
+
}
|
|
196
|
+
result += String.fromCharCode(parseInt(hex, 16));
|
|
197
|
+
this.index += 3;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
default:
|
|
201
|
+
result += esc;
|
|
202
|
+
}
|
|
203
|
+
this.index++;
|
|
204
|
+
} else {
|
|
205
|
+
result += ch;
|
|
206
|
+
this.index++;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
throw this.error("Unterminated string literal");
|
|
210
|
+
}
|
|
211
|
+
parseNumber() {
|
|
212
|
+
const start = this.index;
|
|
213
|
+
if (this.text.startsWith("-Infinity", this.index)) {
|
|
214
|
+
this.index += "-Infinity".length;
|
|
215
|
+
return -Infinity;
|
|
216
|
+
}
|
|
217
|
+
if (this.text.startsWith("+Infinity", this.index)) {
|
|
218
|
+
this.index += "+Infinity".length;
|
|
219
|
+
return Infinity;
|
|
220
|
+
}
|
|
221
|
+
if (this.text.startsWith("Infinity", this.index)) {
|
|
222
|
+
this.index += "Infinity".length;
|
|
223
|
+
return Infinity;
|
|
224
|
+
}
|
|
225
|
+
while (!this.isAtEnd() && /[0-9+\-_.eE]/.test(this.currentChar())) {
|
|
226
|
+
this.index++;
|
|
227
|
+
}
|
|
228
|
+
const token = this.text.slice(start, this.index);
|
|
229
|
+
const normalized = token.replace(/_/g, "");
|
|
230
|
+
const num = Number(normalized);
|
|
231
|
+
if (isNaN(num)) {
|
|
232
|
+
throw this.error(`Invalid number: ${token}`);
|
|
233
|
+
}
|
|
234
|
+
return num;
|
|
235
|
+
}
|
|
236
|
+
parseIdentifier() {
|
|
237
|
+
const start = this.index;
|
|
238
|
+
const firstChar = this.currentChar();
|
|
239
|
+
if (!/[a-zA-Z$_]/.test(firstChar)) {
|
|
240
|
+
throw this.error(`Unexpected token '${firstChar}'`);
|
|
241
|
+
}
|
|
242
|
+
this.index++;
|
|
243
|
+
while (!this.isAtEnd()) {
|
|
244
|
+
const ch = this.currentChar();
|
|
245
|
+
if (!/[a-zA-Z0-9$_]/.test(ch)) break;
|
|
246
|
+
this.index++;
|
|
247
|
+
}
|
|
248
|
+
const token = this.text.slice(start, this.index);
|
|
249
|
+
if (token === "true") return true;
|
|
250
|
+
if (token === "false") return false;
|
|
251
|
+
if (token === "null") return null;
|
|
252
|
+
if (token === "Infinity") return Infinity;
|
|
253
|
+
if (token === "NaN") return NaN;
|
|
254
|
+
return token;
|
|
255
|
+
}
|
|
256
|
+
skipWhitespace() {
|
|
257
|
+
while (!this.isAtEnd()) {
|
|
258
|
+
const ch = this.currentChar();
|
|
259
|
+
if (/\s/.test(ch)) {
|
|
260
|
+
this.index++;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (ch === "/") {
|
|
264
|
+
const next = this.peekChar(1);
|
|
265
|
+
if (next === "/") {
|
|
266
|
+
this.index += 2;
|
|
267
|
+
while (!this.isAtEnd() && this.currentChar() !== "\n") {
|
|
268
|
+
this.index++;
|
|
269
|
+
}
|
|
270
|
+
continue;
|
|
271
|
+
} else if (next === "*") {
|
|
272
|
+
this.index += 2;
|
|
273
|
+
while (!this.isAtEnd() && !(this.currentChar() === "*" && this.peekChar(1) === "/")) {
|
|
274
|
+
this.index++;
|
|
275
|
+
}
|
|
276
|
+
if (this.isAtEnd()) {
|
|
277
|
+
throw this.error("Unterminated multi-line comment");
|
|
278
|
+
}
|
|
279
|
+
this.index += 2;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
expectChar(expected) {
|
|
287
|
+
if (this.currentChar() !== expected) {
|
|
288
|
+
throw this.error(
|
|
289
|
+
`Expected '${expected}' but found '${this.currentChar()}'`
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
this.index++;
|
|
293
|
+
}
|
|
294
|
+
currentChar() {
|
|
295
|
+
return this.text[this.index];
|
|
296
|
+
}
|
|
297
|
+
peekChar(offset) {
|
|
298
|
+
return this.text[this.index + offset];
|
|
299
|
+
}
|
|
300
|
+
isAtEnd() {
|
|
301
|
+
return this.index >= this.text.length;
|
|
302
|
+
}
|
|
303
|
+
error(message) {
|
|
304
|
+
return new Error(`${message} at position ${this.index}`);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// src/math-json/utils.ts
|
|
309
|
+
function isSymbolObject(expr) {
|
|
310
|
+
return expr !== null && typeof expr === "object" && "sym" in expr;
|
|
311
|
+
}
|
|
312
|
+
function isStringObject(expr) {
|
|
313
|
+
return expr !== null && typeof expr === "object" && "str" in expr;
|
|
314
|
+
}
|
|
315
|
+
function isFunctionObject(expr) {
|
|
316
|
+
return expr !== null && typeof expr === "object" && "fn" in expr;
|
|
317
|
+
}
|
|
318
|
+
function stringValue(expr) {
|
|
319
|
+
if (expr === null || expr === void 0) return null;
|
|
320
|
+
if (typeof expr === "object" && "str" in expr) return expr.str;
|
|
321
|
+
if (typeof expr !== "string") return null;
|
|
322
|
+
if (expr.length < 2) return null;
|
|
323
|
+
if (expr.at(0) !== "'" || expr.at(-1) !== "'") return null;
|
|
324
|
+
return expr.substring(1, expr.length - 1);
|
|
325
|
+
}
|
|
326
|
+
function operator(expr) {
|
|
327
|
+
if (Array.isArray(expr)) return expr[0];
|
|
328
|
+
if (expr === null || expr === void 0) return "";
|
|
329
|
+
if (isFunctionObject(expr)) return expr.fn[0];
|
|
330
|
+
return "";
|
|
331
|
+
}
|
|
332
|
+
function operands(expr) {
|
|
333
|
+
if (Array.isArray(expr)) return expr.slice(1);
|
|
334
|
+
if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
|
|
335
|
+
return [];
|
|
336
|
+
}
|
|
337
|
+
function operand(expr, n) {
|
|
338
|
+
if (Array.isArray(expr)) return expr[n] ?? null;
|
|
339
|
+
if (expr === null || !isFunctionObject(expr)) return null;
|
|
340
|
+
return expr.fn[n] ?? null;
|
|
341
|
+
}
|
|
342
|
+
function nops(expr) {
|
|
343
|
+
if (expr === null || expr === void 0) return 0;
|
|
344
|
+
if (Array.isArray(expr)) return Math.max(0, expr.length - 1);
|
|
345
|
+
if (isFunctionObject(expr)) return Math.max(0, expr.fn.length - 1);
|
|
346
|
+
return 0;
|
|
347
|
+
}
|
|
348
|
+
function symbol(expr) {
|
|
349
|
+
if (typeof expr === "string") {
|
|
350
|
+
if (/^[+-]?[0-9\.]/.test(expr)) return null;
|
|
351
|
+
if (expr.length >= 2 && expr[0] === "'" && expr[expr.length - 1] === "'")
|
|
352
|
+
return null;
|
|
353
|
+
return expr;
|
|
354
|
+
}
|
|
355
|
+
if (expr === null || expr === void 0) return null;
|
|
356
|
+
const s = isSymbolObject(expr) ? expr.sym : expr;
|
|
357
|
+
if (typeof s !== "string") return null;
|
|
358
|
+
return s;
|
|
359
|
+
}
|
|
360
|
+
function keyValuePair(expr) {
|
|
361
|
+
const h = operator(expr);
|
|
362
|
+
if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
|
|
363
|
+
const [k, v] = operands(expr);
|
|
364
|
+
const key = stringValue(k);
|
|
365
|
+
if (!key) return null;
|
|
366
|
+
return [key, v ?? "Nothing"];
|
|
367
|
+
}
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
function dictionaryFromExpression(expr) {
|
|
371
|
+
if (expr === null) return null;
|
|
372
|
+
if (typeof expr === "object" && !("sym" in expr) && !("num" in expr) && !("str" in expr) && !("fn" in expr)) {
|
|
373
|
+
return expr;
|
|
374
|
+
}
|
|
375
|
+
if (typeof expr === "string" && expr[0] === "{" && expr[expr.length - 1] === "}") {
|
|
376
|
+
try {
|
|
377
|
+
return JSON5.parse(expr);
|
|
378
|
+
} catch {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const kv = keyValuePair(expr);
|
|
383
|
+
if (kv) return { [kv[0]]: kv[1] };
|
|
384
|
+
if (operator(expr) === "Dictionary") {
|
|
385
|
+
const result = {};
|
|
386
|
+
const ops = operands(expr);
|
|
387
|
+
for (let i = 1; i < nops(expr); i++) {
|
|
388
|
+
const kv2 = keyValuePair(ops[i]);
|
|
389
|
+
if (kv2) result[kv2[0]] = kv2[1];
|
|
390
|
+
}
|
|
391
|
+
return result;
|
|
392
|
+
}
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
function mapArgs(expr, fn) {
|
|
396
|
+
let args = null;
|
|
397
|
+
if (Array.isArray(expr)) args = expr;
|
|
398
|
+
if (isFunctionObject(expr)) args = expr.fn;
|
|
399
|
+
if (args === null) return [];
|
|
400
|
+
let i = 1;
|
|
401
|
+
const result = [];
|
|
402
|
+
while (i < args.length) {
|
|
403
|
+
result.push(fn(args[i]));
|
|
404
|
+
i += 1;
|
|
405
|
+
}
|
|
406
|
+
return result;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/math-json.ts
|
|
410
|
+
var version = "{{SDK_VERSION}}";
|
|
411
|
+
return __toCommonJS(math_json_exports);
|
|
412
|
+
})();
|
|
413
|
+
Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
|