@jplorg/jpl 1.5.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/main.js +3474 -0
- package/dist/types/applyDefaults.d.ts +2 -0
- package/dist/types/builtins/funcContains.d.ts +3 -0
- package/dist/types/builtins/funcEndsWith.d.ts +3 -0
- package/dist/types/builtins/funcError.d.ts +3 -0
- package/dist/types/builtins/funcFromJSON.d.ts +3 -0
- package/dist/types/builtins/funcHas.d.ts +3 -0
- package/dist/types/builtins/funcIn.d.ts +3 -0
- package/dist/types/builtins/funcKeys.d.ts +3 -0
- package/dist/types/builtins/funcLength.d.ts +3 -0
- package/dist/types/builtins/funcNow.d.ts +3 -0
- package/dist/types/builtins/funcStartsWith.d.ts +3 -0
- package/dist/types/builtins/funcToJSON.d.ts +3 -0
- package/dist/types/builtins/funcToLowerCase.d.ts +3 -0
- package/dist/types/builtins/funcToNumber.d.ts +3 -0
- package/dist/types/builtins/funcToString.d.ts +3 -0
- package/dist/types/builtins/funcToUpperCase.d.ts +3 -0
- package/dist/types/builtins/funcTrim.d.ts +3 -0
- package/dist/types/builtins/funcTrimEnd.d.ts +3 -0
- package/dist/types/builtins/funcTrimStart.d.ts +3 -0
- package/dist/types/builtins/funcType.d.ts +3 -0
- package/dist/types/builtins/funcVoid.d.ts +3 -0
- package/dist/types/builtins/index.d.ts +2 -0
- package/dist/types/builtins/internals.d.ts +1 -0
- package/dist/types/builtins/math.d.ts +17 -0
- package/dist/types/createSingleton.d.ts +1 -0
- package/dist/types/interpreter/index.d.ts +21 -0
- package/dist/types/interpreter/parse.d.ts +194 -0
- package/{src/interpreter/parseFunction.js → dist/types/interpreter/parseFunction.d.ts} +2 -10
- package/dist/types/interpreter/system.d.ts +3 -0
- package/dist/types/interpreter/util.d.ts +89 -0
- package/dist/types/library/apply.d.ts +32 -0
- package/dist/types/library/definition.d.ts +79 -0
- package/dist/types/library/errors/adaptErrors.d.ts +6 -0
- package/dist/types/library/errors/enclosure.d.ts +6 -0
- package/dist/types/library/errors/error.d.ts +6 -0
- package/dist/types/library/errors/execution.d.ts +12 -0
- package/dist/types/library/errors/fatal.d.ts +4 -0
- package/dist/types/library/errors/runtime.d.ts +46 -0
- package/dist/types/library/errors/syntax.d.ts +7 -0
- package/{src/library/functions.js → dist/types/library/functions.d.ts} +9 -30
- package/dist/types/library/index.d.ts +18 -0
- package/dist/types/library/mux.d.ts +19 -0
- package/{src/library/ops/op.js → dist/types/library/ops/op.d.ts} +25 -49
- package/{src/library/ops/opa.js → dist/types/library/ops/opa.d.ts} +4 -7
- package/{src/library/ops/opc.js → dist/types/library/ops/opc.d.ts} +6 -11
- package/{src/library/ops/opm.js → dist/types/library/ops/opm.d.ts} +5 -9
- package/{src/library/ops/opu.js → dist/types/library/ops/opu.d.ts} +8 -15
- package/dist/types/library/runtimeScope.d.ts +23 -0
- package/dist/types/library/runtimeSignal.d.ts +25 -0
- package/dist/types/library/types.d.ts +97 -0
- package/dist/types/main.d.ts +19 -0
- package/dist/types/program/handler.d.ts +12 -0
- package/dist/types/program/index.d.ts +40 -0
- package/dist/types/program/ops/index.d.ts +5 -0
- package/dist/types/program/ops/opAccess/index.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaField.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaFunction.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaIter.d.ts +11 -0
- package/dist/types/program/ops/opAccess/opaSlice.d.ts +11 -0
- package/dist/types/program/ops/opAnd.d.ts +11 -0
- package/dist/types/program/ops/opArrayConstructor.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/index.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opaAssignField.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opaAssignIter.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opaAssignSlice.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuAddition.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuDivision.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuMultiplication.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuNullCoalescence.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuRemainder.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuSet.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuSubtraction.d.ts +11 -0
- package/dist/types/program/ops/opAssignment/opuUpdate.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/index.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmAddition.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmDivision.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmMultiplication.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmRemainder.d.ts +11 -0
- package/dist/types/program/ops/opCalculation/opmSubtraction.d.ts +11 -0
- package/dist/types/program/ops/opComparison/index.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcEqual.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcGreater.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcGreaterEqual.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcLess.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcLessEqual.d.ts +11 -0
- package/dist/types/program/ops/opComparison/opcUnequal.d.ts +11 -0
- package/dist/types/program/ops/opConstant.d.ts +11 -0
- package/dist/types/program/ops/opConstantFalse.d.ts +11 -0
- package/dist/types/program/ops/opConstantNull.d.ts +11 -0
- package/dist/types/program/ops/opConstantTrue.d.ts +11 -0
- package/dist/types/program/ops/opFunctionDefinition.d.ts +11 -0
- package/dist/types/program/ops/opIf.d.ts +11 -0
- package/dist/types/program/ops/opInterpolatedString.d.ts +11 -0
- package/dist/types/program/ops/opNegation.d.ts +11 -0
- package/dist/types/program/ops/opNot.d.ts +11 -0
- package/dist/types/program/ops/opNullCoalescence.d.ts +11 -0
- package/dist/types/program/ops/opNumber.d.ts +11 -0
- package/dist/types/program/ops/opObjectConstructor.d.ts +11 -0
- package/dist/types/program/ops/opOr.d.ts +11 -0
- package/dist/types/program/ops/opOutputConcat.d.ts +11 -0
- package/dist/types/program/ops/opString.d.ts +11 -0
- package/dist/types/program/ops/opTry.d.ts +11 -0
- package/dist/types/program/ops/opVariable.d.ts +11 -0
- package/dist/types/program/ops/opVariableDefinition.d.ts +11 -0
- package/dist/types/program/ops/opVoid.d.ts +11 -0
- package/dist/types/program/ops/utils.d.ts +5 -0
- package/dist/types/program/params.d.ts +68 -0
- package/dist/types/runtime/index.d.ts +83 -0
- package/package.json +66 -49
- package/{repl.js → repl.ts} +85 -39
- package/lib/applyDefaults.js +0 -34
- package/lib/builtins/funcContains.js +0 -25
- package/lib/builtins/funcEndsWith.js +0 -21
- package/lib/builtins/funcError.js +0 -11
- package/lib/builtins/funcFromJSON.js +0 -26
- package/lib/builtins/funcHas.js +0 -24
- package/lib/builtins/funcIn.js +0 -24
- package/lib/builtins/funcKeys.js +0 -20
- package/lib/builtins/funcLength.js +0 -24
- package/lib/builtins/funcNow.js +0 -10
- package/lib/builtins/funcStartsWith.js +0 -21
- package/lib/builtins/funcToJSON.js +0 -10
- package/lib/builtins/funcToLowerCase.js +0 -17
- package/lib/builtins/funcToNumber.js +0 -26
- package/lib/builtins/funcToString.js +0 -10
- package/lib/builtins/funcToUpperCase.js +0 -17
- package/lib/builtins/funcTrim.js +0 -17
- package/lib/builtins/funcTrimEnd.js +0 -17
- package/lib/builtins/funcTrimStart.js +0 -17
- package/lib/builtins/funcType.js +0 -10
- package/lib/builtins/funcVoid.js +0 -10
- package/lib/builtins/index.js +0 -205
- package/lib/builtins/internals.js +0 -8
- package/lib/builtins/math.js +0 -40
- package/lib/builtins/native.js +0 -180
- package/lib/createSingleton.js +0 -14
- package/lib/index.js +0 -79
- package/lib/interpreter/index.js +0 -56
- package/lib/interpreter/parse.js +0 -2377
- package/lib/interpreter/parseFunction.js +0 -24
- package/lib/interpreter/system.js +0 -10
- package/lib/interpreter/util.js +0 -349
- package/lib/library/apply.js +0 -142
- package/lib/library/definition.js +0 -9
- package/lib/library/errors/adaptErrors.js +0 -34
- package/lib/library/errors/enclosure.js +0 -16
- package/lib/library/errors/error.js +0 -18
- package/lib/library/errors/execution.js +0 -20
- package/lib/library/errors/fatal.js +0 -15
- package/lib/library/errors/runtime.js +0 -78
- package/lib/library/errors/syntax.js +0 -17
- package/lib/library/functions.js +0 -82
- package/lib/library/index.js +0 -335
- package/lib/library/mux.js +0 -106
- package/lib/library/ops/index.js +0 -60
- package/lib/library/ops/op.js +0 -180
- package/lib/library/ops/opa.js +0 -41
- package/lib/library/ops/opc.js +0 -59
- package/lib/library/ops/opm.js +0 -50
- package/lib/library/ops/opu.js +0 -77
- package/lib/library/runtimeScope.js +0 -38
- package/lib/library/runtimeSignal.js +0 -72
- package/lib/library/types.js +0 -304
- package/lib/program/index.js +0 -101
- package/lib/program/ops/index.js +0 -61
- package/lib/program/ops/opAccess/index.js +0 -55
- package/lib/program/ops/opAccess/opaField.js +0 -50
- package/lib/program/ops/opAccess/opaFunction.js +0 -50
- package/lib/program/ops/opAccess/opaIter.js +0 -31
- package/lib/program/ops/opAccess/opaSlice.js +0 -44
- package/lib/program/ops/opAnd.js +0 -30
- package/lib/program/ops/opArrayConstructor.js +0 -20
- package/lib/program/ops/opAssignment/index.js +0 -90
- package/lib/program/ops/opAssignment/opaAssignField.js +0 -125
- package/lib/program/ops/opAssignment/opaAssignIter.js +0 -69
- package/lib/program/ops/opAssignment/opaAssignSlice.js +0 -99
- package/lib/program/ops/opAssignment/opuAddition.js +0 -31
- package/lib/program/ops/opAssignment/opuDivision.js +0 -31
- package/lib/program/ops/opAssignment/opuMultiplication.js +0 -31
- package/lib/program/ops/opAssignment/opuNullCoalescence.js +0 -25
- package/lib/program/ops/opAssignment/opuRemainder.js +0 -31
- package/lib/program/ops/opAssignment/opuSet.js +0 -19
- package/lib/program/ops/opAssignment/opuSubtraction.js +0 -31
- package/lib/program/ops/opAssignment/opuUpdate.js +0 -19
- package/lib/program/ops/opCalculation/index.js +0 -57
- package/lib/program/ops/opCalculation/opmAddition.js +0 -49
- package/lib/program/ops/opCalculation/opmDivision.js +0 -42
- package/lib/program/ops/opCalculation/opmMultiplication.js +0 -40
- package/lib/program/ops/opCalculation/opmRemainder.js +0 -34
- package/lib/program/ops/opCalculation/opmSubtraction.js +0 -53
- package/lib/program/ops/opComparison/index.js +0 -59
- package/lib/program/ops/opComparison/opcEqual.js +0 -19
- package/lib/program/ops/opComparison/opcGreater.js +0 -19
- package/lib/program/ops/opComparison/opcGreaterEqual.js +0 -19
- package/lib/program/ops/opComparison/opcLess.js +0 -19
- package/lib/program/ops/opComparison/opcLessEqual.js +0 -19
- package/lib/program/ops/opComparison/opcUnequal.js +0 -19
- package/lib/program/ops/opConstant.js +0 -18
- package/lib/program/ops/opConstantFalse.js +0 -16
- package/lib/program/ops/opConstantNull.js +0 -16
- package/lib/program/ops/opConstantTrue.js +0 -16
- package/lib/program/ops/opFunctionDefinition.js +0 -21
- package/lib/program/ops/opIf.js +0 -38
- package/lib/program/ops/opInterpolatedString.js +0 -24
- package/lib/program/ops/opNegation.js +0 -25
- package/lib/program/ops/opNot.js +0 -16
- package/lib/program/ops/opNullCoalescence.js +0 -34
- package/lib/program/ops/opNumber.js +0 -18
- package/lib/program/ops/opObjectConstructor.js +0 -37
- package/lib/program/ops/opOr.js +0 -30
- package/lib/program/ops/opOutputConcat.js +0 -19
- package/lib/program/ops/opString.js +0 -18
- package/lib/program/ops/opTry.js +0 -37
- package/lib/program/ops/opVariable.js +0 -20
- package/lib/program/ops/opVariableDefinition.js +0 -24
- package/lib/program/ops/opVoid.js +0 -16
- package/lib/program/ops/utils.js +0 -35
- package/lib/runtime/index.js +0 -258
- package/src/applyDefaults.js +0 -35
- package/src/builtins/funcContains.js +0 -27
- package/src/builtins/funcEndsWith.js +0 -21
- package/src/builtins/funcError.js +0 -7
- package/src/builtins/funcFromJSON.js +0 -24
- package/src/builtins/funcHas.js +0 -25
- package/src/builtins/funcIn.js +0 -25
- package/src/builtins/funcKeys.js +0 -20
- package/src/builtins/funcLength.js +0 -26
- package/src/builtins/funcNow.js +0 -5
- package/src/builtins/funcStartsWith.js +0 -21
- package/src/builtins/funcToJSON.js +0 -5
- package/src/builtins/funcToLowerCase.js +0 -20
- package/src/builtins/funcToNumber.js +0 -25
- package/src/builtins/funcToString.js +0 -5
- package/src/builtins/funcToUpperCase.js +0 -20
- package/src/builtins/funcTrim.js +0 -16
- package/src/builtins/funcTrimEnd.js +0 -16
- package/src/builtins/funcTrimStart.js +0 -16
- package/src/builtins/funcType.js +0 -5
- package/src/builtins/funcVoid.js +0 -5
- package/src/builtins/index.js +0 -193
- package/src/builtins/internals.js +0 -9
- package/src/builtins/math.js +0 -44
- package/src/createSingleton.js +0 -9
- package/src/index.js +0 -44
- package/src/interpreter/index.js +0 -48
- package/src/interpreter/parse.js +0 -1473
- package/src/interpreter/system.js +0 -5
- package/src/interpreter/util.js +0 -237
- package/src/library/apply.js +0 -135
- package/src/library/definition.js +0 -3
- package/src/library/errors/adaptErrors.js +0 -28
- package/src/library/errors/enclosure.js +0 -11
- package/src/library/errors/error.js +0 -14
- package/src/library/errors/execution.js +0 -15
- package/src/library/errors/fatal.js +0 -10
- package/src/library/errors/runtime.js +0 -71
- package/src/library/errors/syntax.js +0 -12
- package/src/library/index.js +0 -41
- package/src/library/mux.js +0 -98
- package/src/library/runtimeScope.js +0 -35
- package/src/library/runtimeSignal.js +0 -67
- package/src/library/types.js +0 -299
- package/src/program/index.js +0 -114
- package/src/program/ops/index.js +0 -82
- package/src/program/ops/opAccess/index.js +0 -55
- package/src/program/ops/opAccess/opaField.js +0 -58
- package/src/program/ops/opAccess/opaFunction.js +0 -52
- package/src/program/ops/opAccess/opaIter.js +0 -31
- package/src/program/ops/opAccess/opaSlice.js +0 -58
- package/src/program/ops/opAnd.js +0 -32
- package/src/program/ops/opArrayConstructor.js +0 -16
- package/src/program/ops/opAssignment/index.js +0 -102
- package/src/program/ops/opAssignment/opaAssignField.js +0 -156
- package/src/program/ops/opAssignment/opaAssignIter.js +0 -74
- package/src/program/ops/opAssignment/opaAssignSlice.js +0 -157
- package/src/program/ops/opAssignment/opuAddition.js +0 -29
- package/src/program/ops/opAssignment/opuDivision.js +0 -29
- package/src/program/ops/opAssignment/opuMultiplication.js +0 -29
- package/src/program/ops/opAssignment/opuNullCoalescence.js +0 -26
- package/src/program/ops/opAssignment/opuRemainder.js +0 -29
- package/src/program/ops/opAssignment/opuSet.js +0 -15
- package/src/program/ops/opAssignment/opuSubtraction.js +0 -29
- package/src/program/ops/opAssignment/opuUpdate.js +0 -15
- package/src/program/ops/opCalculation/index.js +0 -64
- package/src/program/ops/opCalculation/opmAddition.js +0 -63
- package/src/program/ops/opCalculation/opmDivision.js +0 -47
- package/src/program/ops/opCalculation/opmMultiplication.js +0 -52
- package/src/program/ops/opCalculation/opmRemainder.js +0 -49
- package/src/program/ops/opCalculation/opmSubtraction.js +0 -72
- package/src/program/ops/opComparison/index.js +0 -67
- package/src/program/ops/opComparison/opcEqual.js +0 -17
- package/src/program/ops/opComparison/opcGreater.js +0 -17
- package/src/program/ops/opComparison/opcGreaterEqual.js +0 -17
- package/src/program/ops/opComparison/opcLess.js +0 -17
- package/src/program/ops/opComparison/opcLessEqual.js +0 -17
- package/src/program/ops/opComparison/opcUnequal.js +0 -17
- package/src/program/ops/opConstant.js +0 -13
- package/src/program/ops/opConstantFalse.js +0 -11
- package/src/program/ops/opConstantNull.js +0 -11
- package/src/program/ops/opConstantTrue.js +0 -11
- package/src/program/ops/opFunctionDefinition.js +0 -17
- package/src/program/ops/opIf.js +0 -44
- package/src/program/ops/opInterpolatedString.js +0 -27
- package/src/program/ops/opNegation.js +0 -26
- package/src/program/ops/opNot.js +0 -11
- package/src/program/ops/opNullCoalescence.js +0 -36
- package/src/program/ops/opNumber.js +0 -13
- package/src/program/ops/opObjectConstructor.js +0 -40
- package/src/program/ops/opOr.js +0 -32
- package/src/program/ops/opOutputConcat.js +0 -17
- package/src/program/ops/opString.js +0 -13
- package/src/program/ops/opTry.js +0 -38
- package/src/program/ops/opVariable.js +0 -17
- package/src/program/ops/opVariableDefinition.js +0 -18
- package/src/program/ops/opVoid.js +0 -11
- package/src/program/ops/utils.js +0 -19
- package/src/runtime/index.js +0 -309
- /package/{src/builtins/native.js → dist/types/builtins/native.d.ts} +0 -0
- /package/{src/library/ops/index.js → dist/types/library/ops/index.d.ts} +0 -0
package/lib/builtins/index.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _createSingleton = _interopRequireDefault(require("../createSingleton"));
|
|
8
|
-
var _system = _interopRequireDefault(require("../interpreter/system"));
|
|
9
|
-
var _library = require("../library");
|
|
10
|
-
var internals = _interopRequireWildcard(require("./internals"));
|
|
11
|
-
var native = _interopRequireWildcard(require("./native"));
|
|
12
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
const builtins = `
|
|
15
|
-
# There are additional builtins that are implemented directly in the corresponding languages.
|
|
16
|
-
# Also the functions in the "internals" namespace are not exposed to the public and are only to be used by the builtins below.
|
|
17
|
-
|
|
18
|
-
func map(f): ([.[] | f()])
|
|
19
|
-
| func mapValues(f): (.[] |= f())
|
|
20
|
-
| func select(f): (if f() then . else void() end)
|
|
21
|
-
| func reduce(f, s): (
|
|
22
|
-
l = length()
|
|
23
|
-
| func i(i, n, c): (if n < l then i(i, n + 1, f->(.[n], c, n)) else c end)
|
|
24
|
-
| i(i, 0, s)
|
|
25
|
-
)
|
|
26
|
-
| func while(cond, f): (
|
|
27
|
-
func i(i): (if cond() then ., i->(f(), i) else void() end)
|
|
28
|
-
| i(i)
|
|
29
|
-
)
|
|
30
|
-
| func until(cond, f): (
|
|
31
|
-
func i(i): (if cond() then . else i->(f(), i) end)
|
|
32
|
-
| i(i)
|
|
33
|
-
)
|
|
34
|
-
| func range(from, to, step): (
|
|
35
|
-
t = type->(from) | if t != "number" then error->("cannot use \\(t) as a number") end
|
|
36
|
-
| t = type->(to) | if t != "number" then error->("cannot use \\(t) as a number") end
|
|
37
|
-
| s = (step | if . != 0 and . != null then abs() else 1 end)
|
|
38
|
-
| while->(
|
|
39
|
-
from,
|
|
40
|
-
if from <= to then func (): (. < to) else func (): (. > to) end,
|
|
41
|
-
if from <= to then func (): (. + s) else func (): (. - s) end
|
|
42
|
-
)
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
# type selectors:
|
|
47
|
-
| func isArray(): (type() == "array")
|
|
48
|
-
| func arrays(): (select(isArray))
|
|
49
|
-
| func isObject(): (type() == "object")
|
|
50
|
-
| func objects(): (select(isObject))
|
|
51
|
-
| func isIterable(): (contains->(["array", "object"], type()))
|
|
52
|
-
| func iterables(): (select(isIterable))
|
|
53
|
-
| func isScalar(): (not contains->(["array", "object"], type()))
|
|
54
|
-
| func scalars(): (select(isScalar))
|
|
55
|
-
| func isBoolean(): (type() == "boolean")
|
|
56
|
-
| func booleans(): (select(isBoolean))
|
|
57
|
-
| func isNumber(): (type() == "number")
|
|
58
|
-
| func numbers(): (select(isNumber))
|
|
59
|
-
| func isString(): (type() == "string")
|
|
60
|
-
| func strings(): (select(isString))
|
|
61
|
-
| func isNull(): (type() == "null")
|
|
62
|
-
| func nulls(): (select(isNull))
|
|
63
|
-
| func isFunction(): (type() == "function")
|
|
64
|
-
| func functions(): (select(isFunction))
|
|
65
|
-
| func isNullLike(): (contains->(["null", "function"], type()))
|
|
66
|
-
| func nullLikes(): (select(isNullLike))
|
|
67
|
-
| func isValue(): (not contains->(["null", "function"], type()))
|
|
68
|
-
| func values(): (select(isValue))
|
|
69
|
-
| func hasContent(): (isValue() and not contains->([[], {}, ""], .))
|
|
70
|
-
| func contents(): (select(hasContent))
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
| func toEntries(): (o = . | keys() | map(func (): ({ key: ., value: o[.] })))
|
|
74
|
-
| func fromEntries(): (
|
|
75
|
-
reduce(
|
|
76
|
-
func (s): (s + { (.key ?? .Key ?? .name ?? .Name): if has("value") then .value else .Value end }),
|
|
77
|
-
{}
|
|
78
|
-
)
|
|
79
|
-
)
|
|
80
|
-
| func withEntries(f): (toEntries() | map(f) | fromEntries())
|
|
81
|
-
|
|
82
|
-
| func add(): (reduce(func (sum): (sum + .)))
|
|
83
|
-
| func join(sep): (
|
|
84
|
-
reduce(
|
|
85
|
-
func (sum): (
|
|
86
|
-
if sum == null then "" else sum + sep end
|
|
87
|
-
+ (. | toString())
|
|
88
|
-
)
|
|
89
|
-
) ?? ""
|
|
90
|
-
)
|
|
91
|
-
| func sortBy(f): ([.[] | [[f()], .]] | internals.sortEntries() | [.[][1]])
|
|
92
|
-
| func sort(): (sortBy(func (): (.)))
|
|
93
|
-
| func groupBy(f): (
|
|
94
|
-
key = 0 | value = 1
|
|
95
|
-
| [.[] | [[f()], [.]]] | internals.sortEntries()
|
|
96
|
-
| if . == []
|
|
97
|
-
then .
|
|
98
|
-
else
|
|
99
|
-
reduce->(
|
|
100
|
-
.[1:],
|
|
101
|
-
func (sum): (if sum[-1][key] == .[key] then (sum)[-1][value] += .[value] else sum + [.] end),
|
|
102
|
-
.[:1]
|
|
103
|
-
)
|
|
104
|
-
| [.[][value]]
|
|
105
|
-
end
|
|
106
|
-
)
|
|
107
|
-
| func group(): (groupBy(func (): (.)))
|
|
108
|
-
| func uniqueBy(f): (groupBy(f) | map(func (): (.[0])))
|
|
109
|
-
| func unique(): (group() | map(func (): (.[0])))
|
|
110
|
-
| func recurseBy(f, cond): (
|
|
111
|
-
c = cond ?? func (): (. != null)
|
|
112
|
-
| func r(r): (., (f() | select(c) | r(r)))
|
|
113
|
-
| r(r)
|
|
114
|
-
)
|
|
115
|
-
| func recurse(cond): (recurseBy(func (): ((arrays(), objects()) | .[]), cond))
|
|
116
|
-
| func reverse(): ([.[length() - 1 - range(0, length())]])
|
|
117
|
-
| func minBy(f): (
|
|
118
|
-
key = 0 | value = 1
|
|
119
|
-
| [.[] | [[f()], .]]
|
|
120
|
-
| reduce->(.[1:], func (sum): (if .[key] < sum[key] then . else sum end), .[0])
|
|
121
|
-
| .[value]
|
|
122
|
-
)
|
|
123
|
-
| func min(): (reduce->(.[1:], func (sum): (if . < sum then . else sum end), .[0]))
|
|
124
|
-
| func maxBy(f): (
|
|
125
|
-
key = 0 | value = 1
|
|
126
|
-
| [.[] | [[f()], .]]
|
|
127
|
-
| reduce->(.[1:], func (sum): (if .[key] > sum[key] then . else sum end), .[0])
|
|
128
|
-
| .[value]
|
|
129
|
-
)
|
|
130
|
-
| func max(): (reduce->(.[1:], func (sum): (if . > sum then . else sum end), .[0]))
|
|
131
|
-
| func first(f): ([f()][0])
|
|
132
|
-
| func nth(which, f): (
|
|
133
|
-
[f()]
|
|
134
|
-
| .[if which | type() == "number" then which else length() | which() end]
|
|
135
|
-
)
|
|
136
|
-
| func last(f): ([f()][-1])
|
|
137
|
-
| func isEmpty(f): (first(func (): ((f() | false), true)))
|
|
138
|
-
| func allBy(f, cond): (isEmpty(func (): (f() | cond() and void())))
|
|
139
|
-
| func all(cond): (allBy(func (): (.[]), cond))
|
|
140
|
-
| func anyBy(f, cond): (not isEmpty(func (): (f() | cond() or void())))
|
|
141
|
-
| func any(cond): (anyBy(func (): (.[]), cond))
|
|
142
|
-
|
|
143
|
-
| func getPath(path): (
|
|
144
|
-
fields = (path | if type() == 'string' then . / '.' end)
|
|
145
|
-
| reduce->(fields, func (sum): sum[if type->(sum) == 'array' then toNumber() else toString() end], .)
|
|
146
|
-
)
|
|
147
|
-
| func updatePath(path, update): (
|
|
148
|
-
fields = (path | if type() == 'string' then (. / '.')[] |= (v = . | try toNumber() catch v) end)
|
|
149
|
-
| reduce->(
|
|
150
|
-
reverse->(fields),
|
|
151
|
-
func (sum): (
|
|
152
|
-
field = .
|
|
153
|
-
| func (): (
|
|
154
|
-
if type() == 'array'
|
|
155
|
-
then (
|
|
156
|
-
input = .
|
|
157
|
-
| try toNumber->(field) catch toString->(field)
|
|
158
|
-
| if type() == 'number'
|
|
159
|
-
then input[.] |= sum()
|
|
160
|
-
else {}[.] |= sum()
|
|
161
|
-
end
|
|
162
|
-
) elif type() == 'object'
|
|
163
|
-
then (
|
|
164
|
-
.[toString->(field)] |= sum()
|
|
165
|
-
) elif type->(field) == 'number'
|
|
166
|
-
then (
|
|
167
|
-
[][field] |= sum()
|
|
168
|
-
) else (
|
|
169
|
-
{}[toString->(field)] |= sum()
|
|
170
|
-
)
|
|
171
|
-
end
|
|
172
|
-
)
|
|
173
|
-
),
|
|
174
|
-
update
|
|
175
|
-
)->(.)
|
|
176
|
-
)
|
|
177
|
-
| func setPath(path, value): (
|
|
178
|
-
updatePath(path, func (): value)
|
|
179
|
-
)
|
|
180
|
-
`;
|
|
181
|
-
const getBuiltins = (0, _createSingleton.default)(async () => {
|
|
182
|
-
await undefined;
|
|
183
|
-
let result = {
|
|
184
|
-
...native
|
|
185
|
-
};
|
|
186
|
-
const program = await _system.default.parse(builtins, {
|
|
187
|
-
runtime: {
|
|
188
|
-
vars: {
|
|
189
|
-
internals,
|
|
190
|
-
...native
|
|
191
|
-
},
|
|
192
|
-
adjustResult: (value, scope) => {
|
|
193
|
-
const {
|
|
194
|
-
internals: _,
|
|
195
|
-
...vars
|
|
196
|
-
} = scope.vars;
|
|
197
|
-
result = (0, _library.applyObject)(result, Object.entries(vars));
|
|
198
|
-
return [];
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
await program.run([null]);
|
|
203
|
-
return result;
|
|
204
|
-
});
|
|
205
|
-
var _default = exports.default = getBuiltins;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.sortEntries = void 0;
|
|
7
|
-
var _library = require("../library");
|
|
8
|
-
const sortEntries = exports.sortEntries = (0, _library.nativeFunction)(async (runtime, input) => [await runtime.alterValue(input, value => [...value].sort((a, b) => runtime.compareArrays(runtime.unwrapValue(a)[0], runtime.unwrapValue(b)[0])))]);
|
package/lib/builtins/math.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.trunc = exports.tan = exports.sqrt = exports.sin = exports.round = exports.pow = exports.log10 = exports.log = exports.floor = exports.exp = exports.cos = exports.ceil = exports.atan = exports.asin = exports.acos = exports.abs = void 0;
|
|
7
|
-
var _library = require("../library");
|
|
8
|
-
function unwrapNumber(runtime, v) {
|
|
9
|
-
const t = runtime.type(v);
|
|
10
|
-
const u = runtime.unwrapValue(v);
|
|
11
|
-
if (t !== 'number') {
|
|
12
|
-
throw new _library.JPLTypeError('%s (%*<100v) cannot be used for mathematical operations', t, u);
|
|
13
|
-
}
|
|
14
|
-
return u;
|
|
15
|
-
}
|
|
16
|
-
function funcMath(alter) {
|
|
17
|
-
return async function builtin(runtime, signal, next, input, ...args) {
|
|
18
|
-
const t = runtime.type(input);
|
|
19
|
-
if (t !== 'number') {
|
|
20
|
-
throw new _library.JPLTypeError('%s (%*<100v) cannot be used for mathematical operations', t, runtime.unwrapValue(input));
|
|
21
|
-
}
|
|
22
|
-
return next(await runtime.alterValue(input, value => alter(runtime, value, ...args)));
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const pow = exports.pow = funcMath((runtime, value, arg0) => value ** unwrapNumber(runtime, arg0 ?? null));
|
|
26
|
-
const sqrt = exports.sqrt = funcMath((runtime, value) => Math.sqrt(value));
|
|
27
|
-
const exp = exports.exp = funcMath((runtime, value) => Math.exp(value));
|
|
28
|
-
const log = exports.log = funcMath((runtime, value) => Math.log(value));
|
|
29
|
-
const log10 = exports.log10 = funcMath((runtime, value) => Math.log10(value));
|
|
30
|
-
const sin = exports.sin = funcMath((runtime, value) => Math.sin(value));
|
|
31
|
-
const cos = exports.cos = funcMath((runtime, value) => Math.cos(value));
|
|
32
|
-
const tan = exports.tan = funcMath((runtime, value) => Math.tan(value));
|
|
33
|
-
const asin = exports.asin = funcMath((runtime, value) => Math.asin(value));
|
|
34
|
-
const acos = exports.acos = funcMath((runtime, value) => Math.acos(value));
|
|
35
|
-
const atan = exports.atan = funcMath((runtime, value) => Math.atan(value));
|
|
36
|
-
const ceil = exports.ceil = funcMath((runtime, value) => Math.ceil(value));
|
|
37
|
-
const floor = exports.floor = funcMath((runtime, value) => Math.floor(value));
|
|
38
|
-
const round = exports.round = funcMath((runtime, value) => Math.round(value));
|
|
39
|
-
const trunc = exports.trunc = funcMath((runtime, value) => Math.trunc(value));
|
|
40
|
-
const abs = exports.abs = funcMath((runtime, value) => Math.abs(value));
|
package/lib/builtins/native.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
contains: true,
|
|
8
|
-
endsWith: true,
|
|
9
|
-
error: true,
|
|
10
|
-
fromJSON: true,
|
|
11
|
-
has: true,
|
|
12
|
-
"in": true,
|
|
13
|
-
keys: true,
|
|
14
|
-
length: true,
|
|
15
|
-
now: true,
|
|
16
|
-
startsWith: true,
|
|
17
|
-
toJSON: true,
|
|
18
|
-
toLowerCase: true,
|
|
19
|
-
toNumber: true,
|
|
20
|
-
toString: true,
|
|
21
|
-
toUpperCase: true,
|
|
22
|
-
trim: true,
|
|
23
|
-
trimEnd: true,
|
|
24
|
-
trimStart: true,
|
|
25
|
-
type: true,
|
|
26
|
-
"void": true
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "contains", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function () {
|
|
31
|
-
return _funcContains.default;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
Object.defineProperty(exports, "endsWith", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
get: function () {
|
|
37
|
-
return _funcEndsWith.default;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
Object.defineProperty(exports, "error", {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
get: function () {
|
|
43
|
-
return _funcError.default;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
Object.defineProperty(exports, "fromJSON", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
get: function () {
|
|
49
|
-
return _funcFromJSON.default;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(exports, "has", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
get: function () {
|
|
55
|
-
return _funcHas.default;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(exports, "in", {
|
|
59
|
-
enumerable: true,
|
|
60
|
-
get: function () {
|
|
61
|
-
return _funcIn.default;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(exports, "keys", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function () {
|
|
67
|
-
return _funcKeys.default;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
Object.defineProperty(exports, "length", {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
get: function () {
|
|
73
|
-
return _funcLength.default;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
Object.defineProperty(exports, "now", {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
get: function () {
|
|
79
|
-
return _funcNow.default;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
Object.defineProperty(exports, "startsWith", {
|
|
83
|
-
enumerable: true,
|
|
84
|
-
get: function () {
|
|
85
|
-
return _funcStartsWith.default;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
Object.defineProperty(exports, "toJSON", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
get: function () {
|
|
91
|
-
return _funcToJSON.default;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
Object.defineProperty(exports, "toLowerCase", {
|
|
95
|
-
enumerable: true,
|
|
96
|
-
get: function () {
|
|
97
|
-
return _funcToLowerCase.default;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
Object.defineProperty(exports, "toNumber", {
|
|
101
|
-
enumerable: true,
|
|
102
|
-
get: function () {
|
|
103
|
-
return _funcToNumber.default;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
Object.defineProperty(exports, "toString", {
|
|
107
|
-
enumerable: true,
|
|
108
|
-
get: function () {
|
|
109
|
-
return _funcToString.default;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
Object.defineProperty(exports, "toUpperCase", {
|
|
113
|
-
enumerable: true,
|
|
114
|
-
get: function () {
|
|
115
|
-
return _funcToUpperCase.default;
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
Object.defineProperty(exports, "trim", {
|
|
119
|
-
enumerable: true,
|
|
120
|
-
get: function () {
|
|
121
|
-
return _funcTrim.default;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
Object.defineProperty(exports, "trimEnd", {
|
|
125
|
-
enumerable: true,
|
|
126
|
-
get: function () {
|
|
127
|
-
return _funcTrimEnd.default;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
Object.defineProperty(exports, "trimStart", {
|
|
131
|
-
enumerable: true,
|
|
132
|
-
get: function () {
|
|
133
|
-
return _funcTrimStart.default;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
Object.defineProperty(exports, "type", {
|
|
137
|
-
enumerable: true,
|
|
138
|
-
get: function () {
|
|
139
|
-
return _funcType.default;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
Object.defineProperty(exports, "void", {
|
|
143
|
-
enumerable: true,
|
|
144
|
-
get: function () {
|
|
145
|
-
return _funcVoid.default;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
var _funcContains = _interopRequireDefault(require("./funcContains"));
|
|
149
|
-
var _funcEndsWith = _interopRequireDefault(require("./funcEndsWith"));
|
|
150
|
-
var _funcError = _interopRequireDefault(require("./funcError"));
|
|
151
|
-
var _funcFromJSON = _interopRequireDefault(require("./funcFromJSON"));
|
|
152
|
-
var _funcHas = _interopRequireDefault(require("./funcHas"));
|
|
153
|
-
var _funcIn = _interopRequireDefault(require("./funcIn"));
|
|
154
|
-
var _funcKeys = _interopRequireDefault(require("./funcKeys"));
|
|
155
|
-
var _funcLength = _interopRequireDefault(require("./funcLength"));
|
|
156
|
-
var _funcNow = _interopRequireDefault(require("./funcNow"));
|
|
157
|
-
var _funcStartsWith = _interopRequireDefault(require("./funcStartsWith"));
|
|
158
|
-
var _funcToJSON = _interopRequireDefault(require("./funcToJSON"));
|
|
159
|
-
var _funcToLowerCase = _interopRequireDefault(require("./funcToLowerCase"));
|
|
160
|
-
var _funcToNumber = _interopRequireDefault(require("./funcToNumber"));
|
|
161
|
-
var _funcToString = _interopRequireDefault(require("./funcToString"));
|
|
162
|
-
var _funcToUpperCase = _interopRequireDefault(require("./funcToUpperCase"));
|
|
163
|
-
var _funcTrim = _interopRequireDefault(require("./funcTrim"));
|
|
164
|
-
var _funcTrimEnd = _interopRequireDefault(require("./funcTrimEnd"));
|
|
165
|
-
var _funcTrimStart = _interopRequireDefault(require("./funcTrimStart"));
|
|
166
|
-
var _funcType = _interopRequireDefault(require("./funcType"));
|
|
167
|
-
var _funcVoid = _interopRequireDefault(require("./funcVoid"));
|
|
168
|
-
var _math = require("./math");
|
|
169
|
-
Object.keys(_math).forEach(function (key) {
|
|
170
|
-
if (key === "default" || key === "__esModule") return;
|
|
171
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
172
|
-
if (key in exports && exports[key] === _math[key]) return;
|
|
173
|
-
Object.defineProperty(exports, key, {
|
|
174
|
-
enumerable: true,
|
|
175
|
-
get: function () {
|
|
176
|
-
return _math[key];
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
package/lib/createSingleton.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
function createSingleton(generatorFn) {
|
|
8
|
-
let result;
|
|
9
|
-
return () => {
|
|
10
|
-
if (result == null) result = generatorFn();
|
|
11
|
-
return result;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
var _default = exports.default = createSingleton;
|
package/lib/index.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
getOptions: true,
|
|
8
|
-
parse: true,
|
|
9
|
-
run: true,
|
|
10
|
-
getBuiltins: true,
|
|
11
|
-
parseFunction: true
|
|
12
|
-
};
|
|
13
|
-
exports.default = void 0;
|
|
14
|
-
Object.defineProperty(exports, "getBuiltins", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return _builtins.default;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
exports.parse = exports.getOptions = void 0;
|
|
21
|
-
Object.defineProperty(exports, "parseFunction", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _parseFunction.default;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
exports.run = void 0;
|
|
28
|
-
var _builtins = _interopRequireDefault(require("./builtins"));
|
|
29
|
-
var _createSingleton = _interopRequireDefault(require("./createSingleton"));
|
|
30
|
-
var _interpreter = _interopRequireWildcard(require("./interpreter"));
|
|
31
|
-
var _parseFunction = _interopRequireDefault(require("./interpreter/parseFunction"));
|
|
32
|
-
var library = _interopRequireWildcard(require("./library"));
|
|
33
|
-
Object.keys(library).forEach(function (key) {
|
|
34
|
-
if (key === "default" || key === "__esModule") return;
|
|
35
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
36
|
-
if (key in exports && exports[key] === library[key]) return;
|
|
37
|
-
Object.defineProperty(exports, key, {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () {
|
|
40
|
-
return library[key];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
var _program = require("./program");
|
|
45
|
-
var _runtime = require("./runtime");
|
|
46
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
47
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
48
|
-
const getGlobalOptions = exports.getOptions = (0, _createSingleton.default)(async () => ({
|
|
49
|
-
interpreter: {},
|
|
50
|
-
program: {},
|
|
51
|
-
runtime: {
|
|
52
|
-
vars: {
|
|
53
|
-
...(await (0, _builtins.default)())
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}));
|
|
57
|
-
const parse = async (source, options) => {
|
|
58
|
-
const globalOptions = await getGlobalOptions();
|
|
59
|
-
const interpreter = new _interpreter.default({
|
|
60
|
-
interpreter: (0, _interpreter.applyInterpreterDefaults)(options?.interpreter, globalOptions.interpreter),
|
|
61
|
-
program: (0, _program.applyProgramDefaults)(options?.program, globalOptions.program),
|
|
62
|
-
runtime: (0, _runtime.applyRuntimeDefaults)(options?.runtime, globalOptions.runtime)
|
|
63
|
-
});
|
|
64
|
-
return interpreter.parse(source);
|
|
65
|
-
};
|
|
66
|
-
exports.parse = parse;
|
|
67
|
-
const run = async (source, inputs, options) => {
|
|
68
|
-
const program = await parse(source, options);
|
|
69
|
-
return program.run(inputs);
|
|
70
|
-
};
|
|
71
|
-
exports.run = run;
|
|
72
|
-
var _default = exports.default = {
|
|
73
|
-
...library,
|
|
74
|
-
run,
|
|
75
|
-
parse,
|
|
76
|
-
parseFunction: _parseFunction.default,
|
|
77
|
-
getBuiltins: _builtins.default,
|
|
78
|
-
getOptions: getGlobalOptions
|
|
79
|
-
};
|
package/lib/interpreter/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.applyInterpreterDefaults = applyInterpreterDefaults;
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _applyDefaults = _interopRequireDefault(require("../applyDefaults"));
|
|
9
|
-
var _library = require("../library");
|
|
10
|
-
var _program = _interopRequireWildcard(require("../program"));
|
|
11
|
-
var _runtime = require("../runtime");
|
|
12
|
-
var _parse = require("./parse");
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
const defaultOptions = {};
|
|
16
|
-
function applyInterpreterDefaults(options = {}, defaults = {}) {
|
|
17
|
-
return (0, _applyDefaults.default)(options, defaults);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** JPL interpreter */
|
|
21
|
-
class JPLInterpreter {
|
|
22
|
-
constructor(options) {
|
|
23
|
-
this._options = applyInterpreterDefaults(options?.interpreter, defaultOptions);
|
|
24
|
-
this._programOptions = options?.program;
|
|
25
|
-
this._runtimeOptions = options?.runtime;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Return the interpreter's options */
|
|
29
|
-
get options() {
|
|
30
|
-
return this._options;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Parse the specified source program string into a reusable JPLProgram instance */
|
|
34
|
-
parse = async (source, options) => {
|
|
35
|
-
const instructions = await this.parseInstructions(source);
|
|
36
|
-
const programDefinition = {
|
|
37
|
-
version: _library.DEFINITION_VERSION,
|
|
38
|
-
instructions
|
|
39
|
-
};
|
|
40
|
-
return new _program.default(programDefinition, {
|
|
41
|
-
program: (0, _program.applyProgramDefaults)(options?.program, this._programOptions),
|
|
42
|
-
runtime: (0, _runtime.applyRuntimeDefaults)(options?.runtime, this._runtimeOptions)
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/** Parse the specified source program string */
|
|
47
|
-
parseInstructions = async source => {
|
|
48
|
-
const {
|
|
49
|
-
ops: instructions
|
|
50
|
-
} = await (0, _parse.parseEntrypoint)(source, 0, {
|
|
51
|
-
interpreter: this
|
|
52
|
-
});
|
|
53
|
-
return instructions;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
var _default = exports.default = JPLInterpreter;
|