@mojir/lits 2.1.2 → 2.1.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.
- package/dist/cli/cli.js +174 -37
- package/dist/cli/src/builtin/interface.d.ts +1 -0
- package/dist/cli/src/constants/constants.d.ts +1 -1
- package/dist/cli/src/evaluator/ContextStack.d.ts +3 -2
- package/dist/cli/src/evaluator/functionExecutors.d.ts +1 -1
- package/dist/cli/src/parser/types.d.ts +6 -1
- package/dist/cli/src/tokenizer/token.d.ts +2 -2
- package/dist/index.esm.js +173 -36
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +173 -36
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +173 -36
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/builtin/interface.d.ts +1 -0
- package/dist/src/constants/constants.d.ts +1 -1
- package/dist/src/evaluator/ContextStack.d.ts +3 -2
- package/dist/src/evaluator/functionExecutors.d.ts +1 -1
- package/dist/src/parser/types.d.ts +6 -1
- package/dist/src/tokenizer/token.d.ts +2 -2
- package/dist/testFramework.esm.js +173 -36
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +173 -36
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
|
@@ -28,6 +28,7 @@ export interface EvaluateHelpers {
|
|
|
28
28
|
}
|
|
29
29
|
export interface BuiltinSpecialExpression<T, N extends SpecialExpressionNode> {
|
|
30
30
|
evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => T;
|
|
31
|
+
evaluateAsNormalExpression?: NormalExpressionEvaluator<T>;
|
|
31
32
|
paramCount: Count;
|
|
32
33
|
getUndefinedSymbols: (node: N, contextStack: ContextStack, params: {
|
|
33
34
|
getUndefinedSymbols: GetUndefinedSymbols;
|
|
@@ -13,7 +13,7 @@ export declare const NodeTypes: {
|
|
|
13
13
|
export type NodeType = typeof NodeTypes[keyof typeof NodeTypes];
|
|
14
14
|
export declare function getNodeTypeName(type: NodeType): keyof typeof NodeTypes;
|
|
15
15
|
export declare function isNodeType(type: unknown): type is NodeType;
|
|
16
|
-
declare const functionTypes: readonly ["UserDefined", "Partial", "Comp", "Constantly", "Juxt", "Complement", "EveryPred", "SomePred", "Fnull", "Builtin", "NativeJsFunction"];
|
|
16
|
+
declare const functionTypes: readonly ["UserDefined", "Partial", "Comp", "Constantly", "Juxt", "Complement", "EveryPred", "SomePred", "Fnull", "Builtin", "SpecialBuiltin", "NativeJsFunction"];
|
|
17
17
|
export type FunctionType = typeof functionTypes[number];
|
|
18
18
|
export declare function isFunctionType(type: unknown): type is FunctionType;
|
|
19
19
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Any } from '../interface';
|
|
2
2
|
import type { ContextParams, LazyValue } from '../Lits/Lits';
|
|
3
3
|
import type { NativeJsFunction, SymbolNode, UserDefinedSymbolNode } from '../parser/types';
|
|
4
|
+
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
4
5
|
import type { Context, LookUpResult } from './interface';
|
|
5
6
|
export type ContextStack = ContextStackImpl;
|
|
6
7
|
export declare class ContextStackImpl {
|
|
@@ -17,8 +18,8 @@ export declare class ContextStackImpl {
|
|
|
17
18
|
});
|
|
18
19
|
create(context: Context): ContextStack;
|
|
19
20
|
new(context: Context): ContextStack;
|
|
20
|
-
exportValues(values: Record<string, Any
|
|
21
|
-
addValues(values: Record<string, Any
|
|
21
|
+
exportValues(values: Record<string, Any>, sourceCodeInfo: SourceCodeInfo | undefined): void;
|
|
22
|
+
addValues(values: Record<string, Any>, sourceCodeInfo: SourceCodeInfo | undefined): void;
|
|
22
23
|
getValue(name: string): unknown;
|
|
23
24
|
lookUp(node: UserDefinedSymbolNode): LookUpResult;
|
|
24
25
|
evaluateSymbol(node: SymbolNode): Any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Any, Arr } from '../interface';
|
|
2
|
-
import {
|
|
2
|
+
import type { LitsFunctionType } from '../parser/types';
|
|
3
3
|
import type { SourceCodeInfo } from '../tokenizer/token';
|
|
4
4
|
import type { ContextStack } from './ContextStack';
|
|
5
5
|
import type { EvaluateNode, ExecuteFunction } from './interface';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsFunction } from '../Lits/Lits';
|
|
2
2
|
import type { SpecialExpressionType } from '../builtin';
|
|
3
|
+
import type { specialExpressionTypes } from '../builtin/specialExpressionTypes';
|
|
3
4
|
import type { FunctionType, NodeType, NodeTypes } from '../constants/constants';
|
|
4
5
|
import type { Context } from '../evaluator/interface';
|
|
5
6
|
import type { Any, Arr } from '../interface';
|
|
@@ -69,7 +70,11 @@ export interface NormalBuiltinFunction extends GenericLitsFunction {
|
|
|
69
70
|
functionType: 'Builtin';
|
|
70
71
|
normalBuitinSymbolType: number;
|
|
71
72
|
}
|
|
72
|
-
export
|
|
73
|
+
export interface SpecialBuiltinFunction extends GenericLitsFunction {
|
|
74
|
+
functionType: 'SpecialBuiltin';
|
|
75
|
+
specialBuiltinSymbolType: typeof specialExpressionTypes['&&'] | typeof specialExpressionTypes['||'] | typeof specialExpressionTypes['array'] | typeof specialExpressionTypes['object'] | typeof specialExpressionTypes['defined?'] | typeof specialExpressionTypes['recur'] | typeof specialExpressionTypes['throw'] | typeof specialExpressionTypes['??'];
|
|
76
|
+
}
|
|
77
|
+
export type LitsFunction = NativeJsFunction | UserDefinedFunction | NormalBuiltinFunction | SpecialBuiltinFunction | PartialFunction | CompFunction | ConstantlyFunction | JuxtFunction | ComplementFunction | EveryPredFunction | SomePredFunction | FNullFunction;
|
|
73
78
|
export type LitsFunctionType = LitsFunction['functionType'];
|
|
74
79
|
export type DebugData = {
|
|
75
80
|
token: Token;
|
|
@@ -24,11 +24,11 @@ export type WhitespaceToken = GenericToken<'Whitespace'>;
|
|
|
24
24
|
export type Token = LBraceToken | LBracketToken | LParenToken | RBraceToken | RBracketToken | RParenToken | BasePrefixedNumberToken | MultiLineCommentToken | NumberToken | OperatorToken | RegexpShorthandToken | ReservedSymbolToken | SingleLineCommentToken | StringToken | SymbolToken | WhitespaceToken;
|
|
25
25
|
export type TokenDescriptor<T extends Token> = [length: number, token?: T];
|
|
26
26
|
export interface SourceCodeInfo {
|
|
27
|
-
position
|
|
27
|
+
position: {
|
|
28
28
|
line: number;
|
|
29
29
|
column: number;
|
|
30
30
|
};
|
|
31
|
-
code
|
|
31
|
+
code: string;
|
|
32
32
|
filePath?: string;
|
|
33
33
|
}
|
|
34
34
|
export declare function isSymbolToken<T extends string>(token: Token, symbolName?: T): token is SymbolToken<T>;
|
|
@@ -96,9 +96,15 @@ function getCodeMarker(sourceCodeInfo) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function getLitsErrorMessage(message, sourceCodeInfo) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
if (!sourceCodeInfo) {
|
|
100
|
+
return message;
|
|
101
|
+
}
|
|
102
|
+
var location = "".concat(sourceCodeInfo.position.line, ":").concat(sourceCodeInfo.position.column);
|
|
103
|
+
var filePathLine = sourceCodeInfo.filePath
|
|
104
|
+
? "\n".concat(sourceCodeInfo.filePath, ":").concat(location)
|
|
105
|
+
: "\nLocation ".concat(location);
|
|
106
|
+
var codeLine = "\n".concat(sourceCodeInfo.code);
|
|
107
|
+
var codeMarker = "\n".concat(getCodeMarker(sourceCodeInfo));
|
|
102
108
|
return "".concat(message).concat(filePathLine).concat(codeLine).concat(codeMarker);
|
|
103
109
|
}
|
|
104
110
|
var RecurSignal = /** @class */ (function (_super) {
|
|
@@ -233,6 +239,7 @@ var functionTypes = [
|
|
|
233
239
|
'SomePred',
|
|
234
240
|
'Fnull',
|
|
235
241
|
'Builtin',
|
|
242
|
+
'SpecialBuiltin',
|
|
236
243
|
'NativeJsFunction',
|
|
237
244
|
];
|
|
238
245
|
var functionTypeSet = new Set(functionTypes);
|
|
@@ -404,7 +411,7 @@ function findUnresolvedSymbolsInNode(node, contextStack, builtin, evaluateNode)
|
|
|
404
411
|
return findUnresolvedSymbolsInNode(node[1], contextStack, builtin, evaluateNode);
|
|
405
412
|
/* v8 ignore next 2 */
|
|
406
413
|
default:
|
|
407
|
-
throw new
|
|
414
|
+
throw new LitsError("Unhandled node type: ".concat(nodeType), node[2]);
|
|
408
415
|
}
|
|
409
416
|
}
|
|
410
417
|
|
|
@@ -3769,6 +3776,26 @@ var andSpecialExpression = {
|
|
|
3769
3776
|
}
|
|
3770
3777
|
return value;
|
|
3771
3778
|
},
|
|
3779
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
3780
|
+
var e_2, _a;
|
|
3781
|
+
var value = true;
|
|
3782
|
+
try {
|
|
3783
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
3784
|
+
var param = params_1_1.value;
|
|
3785
|
+
value = asAny(param, sourceCodeInfo);
|
|
3786
|
+
if (!value)
|
|
3787
|
+
break;
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3790
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3791
|
+
finally {
|
|
3792
|
+
try {
|
|
3793
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
3794
|
+
}
|
|
3795
|
+
finally { if (e_2) throw e_2.error; }
|
|
3796
|
+
}
|
|
3797
|
+
return value;
|
|
3798
|
+
},
|
|
3772
3799
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
3773
3800
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
3774
3801
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4013,7 +4040,7 @@ var defSpecialExpression = {
|
|
|
4013
4040
|
var value = bindingNode[1][1];
|
|
4014
4041
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4015
4042
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4016
|
-
contextStack.exportValues(values);
|
|
4043
|
+
contextStack.exportValues(values, target[2]);
|
|
4017
4044
|
return null;
|
|
4018
4045
|
},
|
|
4019
4046
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4025,7 +4052,7 @@ var defSpecialExpression = {
|
|
|
4025
4052
|
walkDefaults(target, function (defaultNode) {
|
|
4026
4053
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4027
4054
|
});
|
|
4028
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
4055
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4029
4056
|
return bindingResult;
|
|
4030
4057
|
},
|
|
4031
4058
|
};
|
|
@@ -4143,14 +4170,14 @@ var functionSpecialExpression = {
|
|
|
4143
4170
|
_b.name = functionSymbol[1],
|
|
4144
4171
|
_b.evaluatedfunction = evaluatedFunction,
|
|
4145
4172
|
_b);
|
|
4146
|
-
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4173
|
+
contextStack.addValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4147
4174
|
return null;
|
|
4148
4175
|
},
|
|
4149
4176
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4150
4177
|
var _b, _c;
|
|
4151
4178
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4152
4179
|
var functionName = node[1][1][1];
|
|
4153
|
-
contextStack.addValues((_b = {}, _b[functionName] = true, _b));
|
|
4180
|
+
contextStack.addValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4154
4181
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4155
4182
|
return getFunctionUnresolvedSymbols(node[1][2], contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4156
4183
|
},
|
|
@@ -4171,7 +4198,7 @@ var defnSpecialExpression = {
|
|
|
4171
4198
|
_b.name = functionSymbol[1],
|
|
4172
4199
|
_b.evaluatedfunction = evaluatedFunctionOverloades,
|
|
4173
4200
|
_b);
|
|
4174
|
-
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c));
|
|
4201
|
+
contextStack.exportValues((_c = {}, _c[functionSymbol[1]] = litsFunction, _c), functionSymbol[2]);
|
|
4175
4202
|
return null;
|
|
4176
4203
|
},
|
|
4177
4204
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4179,7 +4206,7 @@ var defnSpecialExpression = {
|
|
|
4179
4206
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4180
4207
|
var functionName = node[1][1][1];
|
|
4181
4208
|
var fn = node[1][2];
|
|
4182
|
-
contextStack.exportValues((_b = {}, _b[functionName] = true, _b));
|
|
4209
|
+
contextStack.exportValues((_b = {}, _b[functionName] = true, _b), node[1][1][2]);
|
|
4183
4210
|
var newContext = (_c = {}, _c[functionName] = { value: true }, _c);
|
|
4184
4211
|
return getFunctionUnresolvedSymbols(fn, contextStack, getUndefinedSymbols, builtin, evaluateNode, newContext);
|
|
4185
4212
|
},
|
|
@@ -4291,7 +4318,7 @@ var letSpecialExpression = {
|
|
|
4291
4318
|
var value = bindingNode[1][1];
|
|
4292
4319
|
var bindingValue = evaluateNode(value, contextStack);
|
|
4293
4320
|
var values = evalueateBindingNodeValues(target, bindingValue, function (Node) { return evaluateNode(Node, contextStack); });
|
|
4294
|
-
contextStack.addValues(values);
|
|
4321
|
+
contextStack.addValues(values, target[2]);
|
|
4295
4322
|
return null;
|
|
4296
4323
|
},
|
|
4297
4324
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
@@ -4303,7 +4330,7 @@ var letSpecialExpression = {
|
|
|
4303
4330
|
walkDefaults(target, function (defaultNode) {
|
|
4304
4331
|
addToSet(bindingResult, getUndefinedSymbols([defaultNode], contextStack, builtin, evaluateNode));
|
|
4305
4332
|
});
|
|
4306
|
-
contextStack.addValues(getAllBindingTargetNames(target));
|
|
4333
|
+
contextStack.addValues(getAllBindingTargetNames(target), target[2]);
|
|
4307
4334
|
return bindingResult;
|
|
4308
4335
|
},
|
|
4309
4336
|
};
|
|
@@ -4574,6 +4601,26 @@ var orSpecialExpression = {
|
|
|
4574
4601
|
}
|
|
4575
4602
|
return value;
|
|
4576
4603
|
},
|
|
4604
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4605
|
+
var e_2, _a;
|
|
4606
|
+
var value = false;
|
|
4607
|
+
try {
|
|
4608
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4609
|
+
var param = params_1_1.value;
|
|
4610
|
+
value = asAny(param, sourceCodeInfo);
|
|
4611
|
+
if (value)
|
|
4612
|
+
break;
|
|
4613
|
+
}
|
|
4614
|
+
}
|
|
4615
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4616
|
+
finally {
|
|
4617
|
+
try {
|
|
4618
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4619
|
+
}
|
|
4620
|
+
finally { if (e_2) throw e_2.error; }
|
|
4621
|
+
}
|
|
4622
|
+
return value;
|
|
4623
|
+
},
|
|
4577
4624
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4578
4625
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4579
4626
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4592,6 +4639,11 @@ var qqSpecialExpression = {
|
|
|
4592
4639
|
var firstResult = evaluateNode(firstNode, contextStack);
|
|
4593
4640
|
return firstResult !== null && firstResult !== void 0 ? firstResult : (secondNode ? evaluateNode(secondNode, contextStack) : null);
|
|
4594
4641
|
},
|
|
4642
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4643
|
+
var firstParam = asAny(params[0], sourceCodeInfo);
|
|
4644
|
+
var secondParam = params[1] !== undefined ? asAny(params[1], sourceCodeInfo) : null;
|
|
4645
|
+
return firstParam !== null && firstParam !== void 0 ? firstParam : secondParam;
|
|
4646
|
+
},
|
|
4595
4647
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4596
4648
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4597
4649
|
return getUndefinedSymbols(node[1][1].filter(function (n) { return !!n; }), contextStack, builtin, evaluateNode);
|
|
@@ -4606,6 +4658,9 @@ var recurSpecialExpression = {
|
|
|
4606
4658
|
var evaluatedParams = params.map(function (paramNode) { return evaluateNode(paramNode, contextStack); });
|
|
4607
4659
|
throw new RecurSignal(evaluatedParams);
|
|
4608
4660
|
},
|
|
4661
|
+
evaluateAsNormalExpression: function (params) {
|
|
4662
|
+
throw new RecurSignal(params);
|
|
4663
|
+
},
|
|
4609
4664
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4610
4665
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4611
4666
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4621,6 +4676,12 @@ var throwSpecialExpression = {
|
|
|
4621
4676
|
});
|
|
4622
4677
|
throw new UserDefinedError(message, node[2]);
|
|
4623
4678
|
},
|
|
4679
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4680
|
+
var message = asString(params[0], sourceCodeInfo, {
|
|
4681
|
+
nonEmpty: true,
|
|
4682
|
+
});
|
|
4683
|
+
throw new UserDefinedError(message, undefined);
|
|
4684
|
+
},
|
|
4624
4685
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4625
4686
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4626
4687
|
return getUndefinedSymbols([node[1][1]], contextStack, builtin, evaluateNode);
|
|
@@ -4688,6 +4749,24 @@ var arraySpecialExpression = {
|
|
|
4688
4749
|
}
|
|
4689
4750
|
return result;
|
|
4690
4751
|
},
|
|
4752
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4753
|
+
var e_2, _a;
|
|
4754
|
+
var result = [];
|
|
4755
|
+
try {
|
|
4756
|
+
for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
|
|
4757
|
+
var param = params_1_1.value;
|
|
4758
|
+
result.push(asAny(param, sourceCodeInfo));
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
4762
|
+
finally {
|
|
4763
|
+
try {
|
|
4764
|
+
if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
|
|
4765
|
+
}
|
|
4766
|
+
finally { if (e_2) throw e_2.error; }
|
|
4767
|
+
}
|
|
4768
|
+
return result;
|
|
4769
|
+
},
|
|
4691
4770
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4692
4771
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4693
4772
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4719,6 +4798,16 @@ var objectSpecialExpression = {
|
|
|
4719
4798
|
}
|
|
4720
4799
|
return result;
|
|
4721
4800
|
},
|
|
4801
|
+
evaluateAsNormalExpression: function (params, sourceCodeInfo) {
|
|
4802
|
+
var result = {};
|
|
4803
|
+
for (var i = 0; i < params.length; i += 2) {
|
|
4804
|
+
var key = params[i];
|
|
4805
|
+
var value = params[i + 1];
|
|
4806
|
+
assertString(key, sourceCodeInfo);
|
|
4807
|
+
result[key] = value !== null && value !== void 0 ? value : null;
|
|
4808
|
+
}
|
|
4809
|
+
return result;
|
|
4810
|
+
},
|
|
4722
4811
|
getUndefinedSymbols: function (node, contextStack, _a) {
|
|
4723
4812
|
var getUndefinedSymbols = _a.getUndefinedSymbols, builtin = _a.builtin, evaluateNode = _a.evaluateNode;
|
|
4724
4813
|
return getUndefinedSymbols(node[1][1], contextStack, builtin, evaluateNode);
|
|
@@ -4962,6 +5051,16 @@ var functionExecutors = {
|
|
|
4962
5051
|
var normalExpression = asNonUndefined(allNormalExpressions[fn.normalBuitinSymbolType], sourceCodeInfo);
|
|
4963
5052
|
return normalExpression.evaluate(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
4964
5053
|
},
|
|
5054
|
+
SpecialBuiltin: function (fn, params, sourceCodeInfo, contextStack, _a) {
|
|
5055
|
+
var executeFunction = _a.executeFunction;
|
|
5056
|
+
var specialExpression = asNonUndefined(specialExpressions[fn.specialBuiltinSymbolType], sourceCodeInfo);
|
|
5057
|
+
if (specialExpression.evaluateAsNormalExpression) {
|
|
5058
|
+
return specialExpression.evaluateAsNormalExpression(params, sourceCodeInfo, contextStack, { executeFunction: executeFunction });
|
|
5059
|
+
}
|
|
5060
|
+
else {
|
|
5061
|
+
throw new LitsError("Special builtin function ".concat(fn.specialBuiltinSymbolType, " is not supported as normal expression."), sourceCodeInfo);
|
|
5062
|
+
}
|
|
5063
|
+
},
|
|
4965
5064
|
};
|
|
4966
5065
|
|
|
4967
5066
|
function evaluate(ast, contextStack) {
|
|
@@ -5017,7 +5116,21 @@ function evaluateReservedSymbol(node) {
|
|
|
5017
5116
|
function evaluateNormalExpression(node, contextStack) {
|
|
5018
5117
|
var sourceCodeInfo = node[2];
|
|
5019
5118
|
var paramNodes = node[1][1];
|
|
5020
|
-
var params =
|
|
5119
|
+
var params = [];
|
|
5120
|
+
paramNodes.forEach(function (paramNode) {
|
|
5121
|
+
if (isSpreadNode(paramNode)) {
|
|
5122
|
+
var spreadValue = evaluateNode(paramNode[1], contextStack);
|
|
5123
|
+
if (Array.isArray(spreadValue)) {
|
|
5124
|
+
params.push.apply(params, __spreadArray([], __read(spreadValue), false));
|
|
5125
|
+
}
|
|
5126
|
+
else {
|
|
5127
|
+
throw new LitsError("Spread operator requires an array, got ".concat(valueToString(paramNode)), paramNode[2]);
|
|
5128
|
+
}
|
|
5129
|
+
}
|
|
5130
|
+
else {
|
|
5131
|
+
params.push(evaluateNode(paramNode, contextStack));
|
|
5132
|
+
}
|
|
5133
|
+
});
|
|
5021
5134
|
if (isNormalExpressionNodeWithName(node)) {
|
|
5022
5135
|
var nameSymbol = node[1][0];
|
|
5023
5136
|
if (isNormalBuiltinSymbolNode(nameSymbol)) {
|
|
@@ -5119,19 +5232,19 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5119
5232
|
var contexts = [{}, context];
|
|
5120
5233
|
return new ContextStackImpl({ contexts: contexts });
|
|
5121
5234
|
};
|
|
5122
|
-
ContextStackImpl.prototype.exportValues = function (values) {
|
|
5235
|
+
ContextStackImpl.prototype.exportValues = function (values, sourceCodeInfo) {
|
|
5123
5236
|
var e_1, _a;
|
|
5124
5237
|
try {
|
|
5125
5238
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5126
5239
|
var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
|
|
5127
5240
|
if (this.globalContext[name_1]) {
|
|
5128
|
-
throw new
|
|
5241
|
+
throw new LitsError("Cannot redefine exported value \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5129
5242
|
}
|
|
5130
5243
|
if (specialExpressionKeys.includes(name_1)) {
|
|
5131
|
-
throw new
|
|
5244
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5132
5245
|
}
|
|
5133
5246
|
if (normalExpressionKeys.includes(name_1)) {
|
|
5134
|
-
throw new
|
|
5247
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_1, "\""), sourceCodeInfo);
|
|
5135
5248
|
}
|
|
5136
5249
|
this.globalContext[name_1] = { value: value };
|
|
5137
5250
|
}
|
|
@@ -5143,22 +5256,22 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5143
5256
|
}
|
|
5144
5257
|
finally { if (e_1) throw e_1.error; }
|
|
5145
5258
|
}
|
|
5146
|
-
this.addValues(values);
|
|
5259
|
+
this.addValues(values, sourceCodeInfo);
|
|
5147
5260
|
};
|
|
5148
|
-
ContextStackImpl.prototype.addValues = function (values) {
|
|
5261
|
+
ContextStackImpl.prototype.addValues = function (values, sourceCodeInfo) {
|
|
5149
5262
|
var e_2, _a;
|
|
5150
5263
|
var currentContext = this.contexts[0];
|
|
5151
5264
|
try {
|
|
5152
5265
|
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5153
5266
|
var _d = __read(_c.value, 2), name_2 = _d[0], value = _d[1];
|
|
5154
5267
|
if (currentContext[name_2]) {
|
|
5155
|
-
throw new
|
|
5268
|
+
throw new LitsError("Cannot redefine value \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5156
5269
|
}
|
|
5157
5270
|
if (specialExpressionKeys.includes(name_2)) {
|
|
5158
|
-
throw new
|
|
5271
|
+
throw new LitsError("Cannot shadow special expression \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5159
5272
|
}
|
|
5160
5273
|
if (normalExpressionKeys.includes(name_2)) {
|
|
5161
|
-
throw new
|
|
5274
|
+
throw new LitsError("Cannot shadow builtin function \"".concat(name_2, "\""), sourceCodeInfo);
|
|
5162
5275
|
}
|
|
5163
5276
|
currentContext[name_2] = { value: toAny(value) };
|
|
5164
5277
|
}
|
|
@@ -5238,18 +5351,36 @@ var ContextStackImpl = /** @class */ (function () {
|
|
|
5238
5351
|
return null;
|
|
5239
5352
|
};
|
|
5240
5353
|
ContextStackImpl.prototype.evaluateSymbol = function (node) {
|
|
5241
|
-
var _a;
|
|
5354
|
+
var _a, _b;
|
|
5242
5355
|
if (isSpecialBuiltinSymbolNode(node)) {
|
|
5243
|
-
|
|
5356
|
+
var functionType = node[1];
|
|
5357
|
+
switch (functionType) {
|
|
5358
|
+
case specialExpressionTypes['&&']:
|
|
5359
|
+
case specialExpressionTypes['||']:
|
|
5360
|
+
case specialExpressionTypes.array:
|
|
5361
|
+
case specialExpressionTypes.object:
|
|
5362
|
+
case specialExpressionTypes['defined?']:
|
|
5363
|
+
case specialExpressionTypes.recur:
|
|
5364
|
+
case specialExpressionTypes.throw:
|
|
5365
|
+
case specialExpressionTypes['??']:
|
|
5366
|
+
return _a = {},
|
|
5367
|
+
_a[FUNCTION_SYMBOL] = true,
|
|
5368
|
+
_a.functionType = 'SpecialBuiltin',
|
|
5369
|
+
_a.specialBuiltinSymbolType = functionType,
|
|
5370
|
+
_a.sourceCodeInfo = node[2],
|
|
5371
|
+
_a;
|
|
5372
|
+
default:
|
|
5373
|
+
throw new LitsError("Unknown special builtin symbol type: ".concat(functionType), node[2]);
|
|
5374
|
+
}
|
|
5244
5375
|
}
|
|
5245
5376
|
if (isNormalBuiltinSymbolNode(node)) {
|
|
5246
5377
|
var type = node[1];
|
|
5247
|
-
return
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5378
|
+
return _b = {},
|
|
5379
|
+
_b[FUNCTION_SYMBOL] = true,
|
|
5380
|
+
_b.functionType = 'Builtin',
|
|
5381
|
+
_b.normalBuitinSymbolType = type,
|
|
5382
|
+
_b.sourceCodeInfo = node[2],
|
|
5383
|
+
_b;
|
|
5253
5384
|
}
|
|
5254
5385
|
var lookUpResult = this.lookUp(node);
|
|
5255
5386
|
if (isContextEntry(lookUpResult))
|
|
@@ -5921,7 +6052,7 @@ function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
|
5921
6052
|
}
|
|
5922
6053
|
return node;
|
|
5923
6054
|
}
|
|
5924
|
-
function getPrecedence(operatorSign) {
|
|
6055
|
+
function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
5925
6056
|
switch (operatorSign) {
|
|
5926
6057
|
case '**': // exponentiation
|
|
5927
6058
|
return exponentiationPrecedence;
|
|
@@ -5960,7 +6091,7 @@ function getPrecedence(operatorSign) {
|
|
|
5960
6091
|
// leave room for binaryFunctionalOperatorPrecedence = 1
|
|
5961
6092
|
/* v8 ignore next 2 */
|
|
5962
6093
|
default:
|
|
5963
|
-
throw new
|
|
6094
|
+
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
5964
6095
|
}
|
|
5965
6096
|
}
|
|
5966
6097
|
function createNamedNormalExpressionNode(symbolNode, params, sourceCodeInfo) {
|
|
@@ -6093,7 +6224,7 @@ var Parser = /** @class */ (function () {
|
|
|
6093
6224
|
while (!this.isAtExpressionEnd()) {
|
|
6094
6225
|
if (isA_BinaryOperatorToken(operator)) {
|
|
6095
6226
|
var name_1 = operator[1];
|
|
6096
|
-
var newPrecedece = getPrecedence(name_1);
|
|
6227
|
+
var newPrecedece = getPrecedence(name_1, operator[2]);
|
|
6097
6228
|
if (newPrecedece <= precedence
|
|
6098
6229
|
// ** (exponentiation) is right associative
|
|
6099
6230
|
&& !(newPrecedece === exponentiationPrecedence && precedence === exponentiationPrecedence)) {
|
|
@@ -6173,7 +6304,7 @@ var Parser = /** @class */ (function () {
|
|
|
6173
6304
|
this.advance();
|
|
6174
6305
|
var expression = this.parseExpression();
|
|
6175
6306
|
if (!isRParenToken(this.peek())) {
|
|
6176
|
-
throw new
|
|
6307
|
+
throw new LitsError('Expected closing parenthesis', this.peek()[2]);
|
|
6177
6308
|
}
|
|
6178
6309
|
this.advance();
|
|
6179
6310
|
return expression;
|
|
@@ -6295,7 +6426,13 @@ var Parser = /** @class */ (function () {
|
|
|
6295
6426
|
this.advance();
|
|
6296
6427
|
var params = [];
|
|
6297
6428
|
while (!this.isAtEnd() && !isRParenToken(this.peek())) {
|
|
6298
|
-
|
|
6429
|
+
if (isOperatorToken(this.peek(), '...')) {
|
|
6430
|
+
this.advance();
|
|
6431
|
+
params.push(withSourceCodeInfo([NodeTypes.Spread, this.parseExpression()], this.peek()[2]));
|
|
6432
|
+
}
|
|
6433
|
+
else {
|
|
6434
|
+
params.push(this.parseExpression());
|
|
6435
|
+
}
|
|
6299
6436
|
var nextToken = this.peek();
|
|
6300
6437
|
if (!isOperatorToken(nextToken, ',') && !isRParenToken(nextToken)) {
|
|
6301
6438
|
throw new LitsError('Expected comma or closing parenthesis', this.peek()[2]);
|
|
@@ -6351,7 +6488,7 @@ var Parser = /** @class */ (function () {
|
|
|
6351
6488
|
throw new LitsError("".concat(type, " is not allowed"), symbol[2]);
|
|
6352
6489
|
/* v8 ignore next 2 */
|
|
6353
6490
|
default:
|
|
6354
|
-
throw new
|
|
6491
|
+
throw new LitsError("Unknown special expression: ".concat(type), symbol[2]);
|
|
6355
6492
|
}
|
|
6356
6493
|
}
|
|
6357
6494
|
else if (isNormalBuiltinSymbolNode(symbol) || isNormalBuiltinSymbolNode(symbol)) {
|