affinirum 1.5.2 → 1.5.4
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/README.md +12 -2
- package/dst/Affinirum.d.ts +22 -22
- package/dst/Affinirum.js +88 -80
- package/dst/CallFrame.d.ts +11 -0
- package/dst/CallFrame.js +35 -0
- package/dst/LexicalScope.d.ts +15 -0
- package/dst/LexicalScope.js +31 -0
- package/dst/Node.d.ts +5 -4
- package/dst/Node.js +5 -5
- package/dst/ParserState.d.ts +3 -3
- package/dst/ParserState.js +40 -40
- package/dst/ScriptSpan.d.ts +10 -0
- package/dst/{ParserFrame.js → ScriptSpan.js} +20 -31
- package/dst/Type.d.ts +2 -0
- package/dst/Type.js +2 -0
- package/dst/Variable.d.ts +0 -4
- package/dst/Variable.js +0 -7
- package/dst/cjs/Affinirum.d.ts +88 -0
- package/dst/cjs/Affinirum.js +88 -80
- package/dst/cjs/Atom.d.ts +7 -0
- package/dst/cjs/CallFrame.d.ts +11 -0
- package/dst/cjs/CallFrame.js +39 -0
- package/dst/cjs/Constant.d.ts +13 -0
- package/dst/cjs/Constants.d.ts +2 -0
- package/dst/cjs/Functions.d.ts +2 -0
- package/dst/cjs/Jump.d.ts +1 -0
- package/dst/cjs/JumpException.d.ts +9 -0
- package/dst/cjs/Keywords.d.ts +1 -0
- package/dst/cjs/LexicalScope.d.ts +15 -0
- package/dst/cjs/LexicalScope.js +35 -0
- package/dst/cjs/Node.d.ts +14 -0
- package/dst/cjs/Node.js +5 -5
- package/dst/cjs/ParserState.d.ts +60 -0
- package/dst/cjs/ParserState.js +40 -40
- package/dst/cjs/ScriptSpan.d.ts +10 -0
- package/dst/cjs/{ParserFrame.js → ScriptSpan.js} +22 -33
- package/dst/cjs/Type.d.ts +71 -0
- package/dst/cjs/Type.js +2 -0
- package/dst/cjs/Value.d.ts +5 -0
- package/dst/cjs/Variable.d.ts +9 -0
- package/dst/cjs/Variable.js +0 -7
- package/dst/cjs/atom/ArrayAtom.d.ts +16 -0
- package/dst/cjs/atom/FunctionAtom.d.ts +22 -0
- package/dst/cjs/atom/ObjectAtom.d.ts +14 -0
- package/dst/cjs/atom/PrimitiveAtom.d.ts +12 -0
- package/dst/cjs/index.d.ts +3 -0
- package/dst/cjs/native/Aggregable.d.ts +4 -0
- package/dst/cjs/native/Array.d.ts +16 -0
- package/dst/cjs/native/Boolean.d.ts +6 -0
- package/dst/cjs/native/Buffer.d.ts +13 -0
- package/dst/cjs/native/Buffer.js +1 -1
- package/dst/cjs/native/Enumerable.d.ts +4 -0
- package/dst/cjs/native/Float.d.ts +5 -0
- package/dst/cjs/native/Integer.d.ts +7 -0
- package/dst/cjs/native/Iterable.d.ts +5 -0
- package/dst/cjs/native/Number.d.ts +26 -0
- package/dst/cjs/native/Number.js +25 -12
- package/dst/cjs/native/Object.d.ts +5 -0
- package/dst/cjs/native/String.d.ts +28 -0
- package/dst/cjs/native/String.js +97 -48
- package/dst/cjs/native/Timestamp.d.ts +22 -0
- package/dst/cjs/native/Unknown.d.ts +14 -0
- package/dst/cjs/native/Unknown.js +10 -1
- package/dst/cjs/native/notation/AN.d.ts +4 -0
- package/dst/cjs/native/notation/AN.js +2 -2
- package/dst/cjs/native/notation/IP.d.ts +1 -0
- package/dst/cjs/native/notation/JSON.d.ts +3 -0
- package/dst/cjs/node/ArrayNode.d.ts +14 -0
- package/dst/cjs/node/ArrayNode.js +4 -11
- package/dst/cjs/node/BlockNode.d.ts +15 -0
- package/dst/cjs/node/BlockNode.js +10 -6
- package/dst/cjs/node/CallNode.d.ts +15 -0
- package/dst/cjs/node/CallNode.js +15 -28
- package/dst/cjs/node/CastNode.d.ts +16 -0
- package/dst/cjs/node/CastNode.js +4 -4
- package/dst/cjs/node/ConstantNode.d.ts +17 -0
- package/dst/cjs/node/ConstantNode.js +7 -5
- package/dst/cjs/node/JumpNode.d.ts +16 -0
- package/dst/cjs/node/JumpNode.js +10 -6
- package/dst/cjs/node/LoopNode.d.ts +14 -0
- package/dst/cjs/node/LoopNode.js +5 -5
- package/dst/cjs/node/ObjectNode.d.ts +14 -0
- package/dst/cjs/node/ObjectNode.js +6 -12
- package/dst/cjs/node/SwitchNode.d.ts +15 -0
- package/dst/cjs/node/SwitchNode.js +8 -7
- package/dst/cjs/node/VariableNode.d.ts +15 -0
- package/dst/cjs/node/VariableNode.js +5 -5
- package/dst/cjs/node/VariadicNode.d.ts +4 -0
- package/dst/cjs/node/VariadicNode.js +10 -0
- package/dst/native/Buffer.js +1 -1
- package/dst/native/Number.js +25 -12
- package/dst/native/String.js +97 -48
- package/dst/native/Unknown.js +10 -1
- package/dst/native/notation/AN.js +2 -2
- package/dst/node/ArrayNode.d.ts +4 -3
- package/dst/node/ArrayNode.js +4 -11
- package/dst/node/BlockNode.d.ts +6 -3
- package/dst/node/BlockNode.js +10 -6
- package/dst/node/CallNode.d.ts +4 -3
- package/dst/node/CallNode.js +15 -28
- package/dst/node/CastNode.d.ts +4 -3
- package/dst/node/CastNode.js +4 -4
- package/dst/node/ConstantNode.d.ts +5 -3
- package/dst/node/ConstantNode.js +7 -5
- package/dst/node/JumpNode.d.ts +5 -3
- package/dst/node/JumpNode.js +10 -6
- package/dst/node/LoopNode.d.ts +4 -3
- package/dst/node/LoopNode.js +5 -5
- package/dst/node/ObjectNode.d.ts +4 -3
- package/dst/node/ObjectNode.js +6 -12
- package/dst/node/SwitchNode.d.ts +4 -3
- package/dst/node/SwitchNode.js +8 -7
- package/dst/node/VariableNode.d.ts +4 -3
- package/dst/node/VariableNode.js +5 -5
- package/dst/node/VariadicNode.d.ts +4 -0
- package/dst/node/VariadicNode.js +6 -0
- package/package.json +10 -9
- package/dst/ParserFrame.d.ts +0 -13
- package/dst/Scope.d.ts +0 -16
- package/dst/Scope.js +0 -49
- package/dst/cjs/Scope.js +0 -53
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Constant } from "../Constant.js";
|
|
2
|
+
export type FloatEncoding = "f32" | "f32le" | "f64" | "f64le";
|
|
3
|
+
export declare const encodeFloat: (value: number, encoding?: FloatEncoding) => ArrayBuffer;
|
|
4
|
+
export declare const funcFloat: Constant;
|
|
5
|
+
export declare const constFloat: any;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Constant } from "../Constant.js";
|
|
2
|
+
export type IntegerEncoding = "i8" | "i16" | "i16le" | "i32" | "i32le" | "i64" | "i64le" | "n8" | "n16" | "n16le" | "n32" | "n32le";
|
|
3
|
+
export declare const boundInteger: (value: bigint) => bigint;
|
|
4
|
+
export declare const createInteger: (value?: number) => bigint | undefined;
|
|
5
|
+
export declare const encodeInteger: (value: bigint, encoding?: IntegerEncoding) => ArrayBuffer;
|
|
6
|
+
export declare const funcInteger: Constant;
|
|
7
|
+
export declare const constInteger: any;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Constant } from "../Constant.js";
|
|
2
|
+
export declare const isSignSymbol: (c: string) => c is "+" | "-";
|
|
3
|
+
export declare const isNumericSymbol: (c: string) => boolean;
|
|
4
|
+
export interface NumberFormatting {
|
|
5
|
+
min_integer_digits?: number;
|
|
6
|
+
min_fraction_digits?: number;
|
|
7
|
+
max_fraction_digits?: number;
|
|
8
|
+
min_significant_digits?: number;
|
|
9
|
+
max_significant_digits?: number;
|
|
10
|
+
notation?: "standard" | "scientific";
|
|
11
|
+
}
|
|
12
|
+
export declare const formatLiteralNumber: (value: bigint | number) => string;
|
|
13
|
+
export declare const parseLiteralNumber: (value: string, offset?: number) => readonly [number | bigint, number];
|
|
14
|
+
export declare const formatNumber: (value: bigint | number, formatting?: string) => string;
|
|
15
|
+
export declare const funcGreaterThan: Constant;
|
|
16
|
+
export declare const funcLessThan: Constant;
|
|
17
|
+
export declare const funcGreaterOrEqual: Constant;
|
|
18
|
+
export declare const funcLessOrEqual: Constant;
|
|
19
|
+
export declare const funcSubtract: Constant;
|
|
20
|
+
export declare const funcMultiply: Constant;
|
|
21
|
+
export declare const funcDivide: Constant;
|
|
22
|
+
export declare const funcRemainder: Constant;
|
|
23
|
+
export declare const funcModulo: Constant;
|
|
24
|
+
export declare const funcPower: Constant;
|
|
25
|
+
export declare const funcRoot: Constant;
|
|
26
|
+
export declare const funcNegate: Constant;
|
package/dst/cjs/native/Number.js
CHANGED
|
@@ -9,9 +9,10 @@ exports.isSignSymbol = isSignSymbol;
|
|
|
9
9
|
const isNumericSymbol = (c) => c >= "0" && c <= "9";
|
|
10
10
|
exports.isNumericSymbol = isNumericSymbol;
|
|
11
11
|
const formatLiteralNumber = (value) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const str = value.toString();
|
|
13
|
+
return typeof value === "number" && Number.isInteger(value) && !str.includes("e")
|
|
14
|
+
? `${str}.0`
|
|
15
|
+
: str;
|
|
15
16
|
};
|
|
16
17
|
exports.formatLiteralNumber = formatLiteralNumber;
|
|
17
18
|
const parseLiteralNumber = (value, offset = 0) => {
|
|
@@ -68,7 +69,7 @@ const formatNumber = (value, formatting) => {
|
|
|
68
69
|
};
|
|
69
70
|
exports.formatNumber = formatNumber;
|
|
70
71
|
const typeComparator = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Number, Type_js_1.Type.Number]);
|
|
71
|
-
const typeOperator = Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float, Type_js_1.Type.Integer]), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Integer, Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer, Type_js_1.Type.Integer]));
|
|
72
|
+
const typeOperator = Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float, Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float, Type_js_1.Type.Integer]), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Integer, Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer, Type_js_1.Type.Integer]));
|
|
72
73
|
exports.funcGreaterThan = new Constant_js_1.Constant((value1, value2) => value1 > value2, typeComparator);
|
|
73
74
|
exports.funcLessThan = new Constant_js_1.Constant((value1, value2) => value1 < value2, typeComparator);
|
|
74
75
|
exports.funcGreaterOrEqual = new Constant_js_1.Constant((value1, value2) => value1 >= value2, typeComparator);
|
|
@@ -92,23 +93,28 @@ exports.funcPower = new Constant_js_1.Constant((value, exponent) => typeof value
|
|
|
92
93
|
? (0, Integer_js_1.boundInteger)(value ** BigInt(exponent))
|
|
93
94
|
: Number(value) ** Number(exponent), typeOperator);
|
|
94
95
|
exports.funcRoot = new Constant_js_1.Constant((value, exponent) => {
|
|
96
|
+
if (exponent <= 0) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
95
99
|
if (typeof value === "bigint" && typeof exponent === "bigint") {
|
|
96
100
|
const v = (0, Integer_js_1.boundInteger)(value);
|
|
97
101
|
const e = (0, Integer_js_1.boundInteger)(exponent);
|
|
98
|
-
|
|
102
|
+
const negative = v < 0n;
|
|
103
|
+
if (negative && e % 2n === 0n) {
|
|
99
104
|
return undefined;
|
|
100
105
|
}
|
|
101
|
-
|
|
106
|
+
const magnitude = negative ? -v : v;
|
|
107
|
+
if (magnitude <= 1n || e === 1n) {
|
|
102
108
|
return v;
|
|
103
109
|
}
|
|
104
|
-
let low = 0n, high =
|
|
110
|
+
let low = 0n, high = magnitude, result = 0n;
|
|
105
111
|
while (low <= high) {
|
|
106
112
|
const mid = low + high >> 1n;
|
|
107
113
|
const midPow = mid ** e;
|
|
108
|
-
if (midPow ===
|
|
109
|
-
return mid;
|
|
114
|
+
if (midPow === magnitude) {
|
|
115
|
+
return negative ? -mid : mid;
|
|
110
116
|
}
|
|
111
|
-
else if (midPow <
|
|
117
|
+
else if (midPow < magnitude) {
|
|
112
118
|
result = mid;
|
|
113
119
|
low = mid + 1n;
|
|
114
120
|
}
|
|
@@ -116,8 +122,15 @@ exports.funcRoot = new Constant_js_1.Constant((value, exponent) => {
|
|
|
116
122
|
high = mid - 1n;
|
|
117
123
|
}
|
|
118
124
|
}
|
|
119
|
-
return result;
|
|
125
|
+
return negative ? -result : result;
|
|
120
126
|
}
|
|
121
|
-
|
|
127
|
+
const v = Number(value);
|
|
128
|
+
const e = Number(exponent);
|
|
129
|
+
const odd = typeof exponent === "bigint"
|
|
130
|
+
? exponent % 2n !== 0n
|
|
131
|
+
: Number.isInteger(exponent) && exponent % 2 !== 0;
|
|
132
|
+
return (v < 0 || Object.is(v, -0)) && odd
|
|
133
|
+
? -Math.pow(-v, 1 / e)
|
|
134
|
+
: Math.pow(v, 1 / e);
|
|
122
135
|
}, typeOperator);
|
|
123
136
|
exports.funcNegate = new Constant_js_1.Constant((value) => value == null ? undefined : typeof value === "number" ? -value : (0, Integer_js_1.boundInteger)(-value), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer])));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Constant } from "../Constant.js";
|
|
2
|
+
export type StringEncoding = "utf8" | "sbcs" | "ucs2" | "ucs2le";
|
|
3
|
+
export declare const isAlphanumericSymbol: (c: string) => boolean;
|
|
4
|
+
export declare const isTokenStartSymbol: (c: string) => boolean;
|
|
5
|
+
export declare const isTokenSymbol: (c: string) => boolean;
|
|
6
|
+
export declare const isHexadecimalSymbol: (c: string) => boolean;
|
|
7
|
+
export declare const formatLiteralString: (value: string) => string;
|
|
8
|
+
export declare const parseLiteralString: (value: string, offset?: number) => readonly [string, number];
|
|
9
|
+
export declare const replaceWith: (value?: string, replacement?: string, ...search: string[]) => string | undefined;
|
|
10
|
+
export declare const equateStrings: (value1?: string, value2?: string, ignoreCaseSpaceEtc?: boolean) => boolean;
|
|
11
|
+
export declare const containsString: (value?: string, search?: string, startPos?: number, ignoreCaseSpaceEtc?: boolean) => boolean;
|
|
12
|
+
export declare const startsWithString: (value?: string, search?: string, startPos?: number, ignoreCaseSpaceEtc?: boolean) => boolean;
|
|
13
|
+
export declare const endsWithString: (value?: string, search?: string, endPos?: number, ignoreCaseSpaceEtc?: boolean) => boolean;
|
|
14
|
+
export declare const encodeString: (value: string, encoding?: StringEncoding) => ArrayBuffer;
|
|
15
|
+
export declare const funcLike: Constant;
|
|
16
|
+
export declare const funcUnlike: Constant;
|
|
17
|
+
export declare const funcStartsWith: Constant;
|
|
18
|
+
export declare const funcEndsWith: Constant;
|
|
19
|
+
export declare const funcChar: Constant;
|
|
20
|
+
export declare const funcCharCode: Constant;
|
|
21
|
+
export declare const funcTrim: Constant;
|
|
22
|
+
export declare const funcTrimStart: Constant;
|
|
23
|
+
export declare const funcTrimEnd: Constant;
|
|
24
|
+
export declare const funcLowerCase: Constant;
|
|
25
|
+
export declare const funcUpperCase: Constant;
|
|
26
|
+
export declare const funcSplit: Constant;
|
|
27
|
+
export declare const funcReplaceWith: Constant;
|
|
28
|
+
export declare const constString: any;
|
package/dst/cjs/native/String.js
CHANGED
|
@@ -85,25 +85,49 @@ const equateStrings = (value1, value2, ignoreCaseSpaceEtc) => {
|
|
|
85
85
|
if (value1 == null || value2 == null) {
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
|
+
if (value1 === value2) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
88
91
|
if (!ignoreCaseSpaceEtc) {
|
|
89
|
-
return
|
|
92
|
+
return false;
|
|
90
93
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
++i1;
|
|
94
|
+
for (let i1 = 0, i2 = 0; i1 < value1.length || i2 < value2.length;) {
|
|
95
|
+
let code1 = 0, code2 = 0;
|
|
96
|
+
while (i1 < value1.length && !code1) {
|
|
97
|
+
code1 = alphanumericCode(value1, i1++);
|
|
96
98
|
}
|
|
97
|
-
while (
|
|
98
|
-
++
|
|
99
|
+
while (i2 < value2.length && !code2) {
|
|
100
|
+
code2 = alphanumericCode(value2, i2++);
|
|
99
101
|
}
|
|
100
|
-
if (
|
|
102
|
+
if (code1 !== code2) {
|
|
101
103
|
return false;
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
return true;
|
|
105
107
|
};
|
|
106
108
|
exports.equateStrings = equateStrings;
|
|
109
|
+
const alphanumericCode = (value, index) => {
|
|
110
|
+
let code = value.charCodeAt(index);
|
|
111
|
+
if (code > 0x7f) {
|
|
112
|
+
// Preserve Unicode lowercase mappings to ASCII, such as İ and K.
|
|
113
|
+
code = value.charAt(index).toLowerCase().charCodeAt(0);
|
|
114
|
+
}
|
|
115
|
+
code |= 0x20;
|
|
116
|
+
return code >= 0x61 && code <= 0x7a || code >= 0x30 && code <= 0x39 ? code : 0;
|
|
117
|
+
};
|
|
118
|
+
const createSearchPrefixes = (pattern) => {
|
|
119
|
+
const prefixes = new Uint32Array(pattern.length);
|
|
120
|
+
for (let i = 1, matched = 0; i < pattern.length; ++i) {
|
|
121
|
+
while (matched > 0 && pattern[i] !== pattern[matched]) {
|
|
122
|
+
matched = prefixes[matched - 1];
|
|
123
|
+
}
|
|
124
|
+
if (pattern[i] === pattern[matched]) {
|
|
125
|
+
++matched;
|
|
126
|
+
}
|
|
127
|
+
prefixes[i] = matched;
|
|
128
|
+
}
|
|
129
|
+
return prefixes;
|
|
130
|
+
};
|
|
107
131
|
const containsString = (value, search, startPos, ignoreCaseSpaceEtc) => {
|
|
108
132
|
if (value == null) {
|
|
109
133
|
return false;
|
|
@@ -114,33 +138,62 @@ const containsString = (value, search, startPos, ignoreCaseSpaceEtc) => {
|
|
|
114
138
|
if (!ignoreCaseSpaceEtc) {
|
|
115
139
|
return value.includes(search, startPos);
|
|
116
140
|
}
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
141
|
+
const pattern = [];
|
|
142
|
+
for (let i = 0; i < search.length; ++i) {
|
|
143
|
+
const code = alphanumericCode(search, i);
|
|
144
|
+
if (code) {
|
|
145
|
+
pattern.push(code);
|
|
146
|
+
}
|
|
121
147
|
}
|
|
122
|
-
if (
|
|
148
|
+
if (pattern.length === 0) {
|
|
123
149
|
return true;
|
|
124
150
|
}
|
|
125
151
|
const pos = startPos == null ? 0 : startPos < 0 ? value.length + startPos : startPos;
|
|
126
|
-
|
|
152
|
+
const start = Math.max(0, Math.trunc(pos) || 0);
|
|
153
|
+
if (pattern.length > value.length - start) {
|
|
127
154
|
return false;
|
|
128
155
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
156
|
+
// Build KMP fallback lengths only when a partial match first fails.
|
|
157
|
+
let prefixes;
|
|
158
|
+
const first = pattern[0];
|
|
159
|
+
for (let i = start, matched = 0; i < value.length; ++i) {
|
|
160
|
+
if (matched === 0) {
|
|
161
|
+
while (i < value.length) {
|
|
162
|
+
const code = value.charCodeAt(i) | 0x20;
|
|
163
|
+
if (code === first || code > 0x7f && alphanumericCode(value, i) === first) {
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
++i;
|
|
167
|
+
}
|
|
168
|
+
if (i === value.length) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
if (pattern.length === 1) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
matched = 1;
|
|
175
|
+
continue;
|
|
132
176
|
}
|
|
133
|
-
|
|
134
|
-
|
|
177
|
+
let code = value.charCodeAt(i) | 0x20;
|
|
178
|
+
if (code > 0x7f) {
|
|
179
|
+
code = alphanumericCode(value, i);
|
|
135
180
|
}
|
|
136
|
-
|
|
137
|
-
++
|
|
181
|
+
if (code === pattern[matched]) {
|
|
182
|
+
if (++matched === pattern.length) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
138
185
|
}
|
|
139
|
-
if (
|
|
140
|
-
|
|
186
|
+
else if (matched > 0 && (code >= 0x61 && code <= 0x7a || code >= 0x30 && code <= 0x39)) {
|
|
187
|
+
prefixes ??= createSearchPrefixes(pattern);
|
|
188
|
+
do {
|
|
189
|
+
matched = prefixes[matched - 1];
|
|
190
|
+
} while (matched > 0 && code !== pattern[matched]);
|
|
191
|
+
if (code === pattern[matched]) {
|
|
192
|
+
++matched;
|
|
193
|
+
}
|
|
141
194
|
}
|
|
142
195
|
}
|
|
143
|
-
return
|
|
196
|
+
return false;
|
|
144
197
|
};
|
|
145
198
|
exports.containsString = containsString;
|
|
146
199
|
const startsWithString = (value, search, startPos, ignoreCaseSpaceEtc) => {
|
|
@@ -153,20 +206,18 @@ const startsWithString = (value, search, startPos, ignoreCaseSpaceEtc) => {
|
|
|
153
206
|
if (!ignoreCaseSpaceEtc) {
|
|
154
207
|
return value.startsWith(search, startPos);
|
|
155
208
|
}
|
|
156
|
-
const valueStr = value.toLowerCase();
|
|
157
|
-
const searchStr = search.toLowerCase();
|
|
158
|
-
if (valueStr.length < searchStr.length) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
209
|
const pos = startPos == null ? 0 : startPos < 0 ? value.length + startPos : startPos;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
210
|
+
let valueIndex = Math.max(0, Math.trunc(pos) || 0);
|
|
211
|
+
for (let i = 0; i < search.length; ++i) {
|
|
212
|
+
const searchCode = alphanumericCode(search, i);
|
|
213
|
+
if (!searchCode) {
|
|
214
|
+
continue;
|
|
165
215
|
}
|
|
166
|
-
|
|
167
|
-
|
|
216
|
+
let valueCode = 0;
|
|
217
|
+
while (valueIndex < value.length && !valueCode) {
|
|
218
|
+
valueCode = alphanumericCode(value, valueIndex++);
|
|
168
219
|
}
|
|
169
|
-
if (
|
|
220
|
+
if (valueCode !== searchCode) {
|
|
170
221
|
return false;
|
|
171
222
|
}
|
|
172
223
|
}
|
|
@@ -183,20 +234,18 @@ const endsWithString = (value, search, endPos, ignoreCaseSpaceEtc) => {
|
|
|
183
234
|
if (!ignoreCaseSpaceEtc) {
|
|
184
235
|
return value.endsWith(search, endPos);
|
|
185
236
|
}
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
for (let i1 = pos - 1, i2 = searchStr.length - 1; i1 > -1 && i2 > -1; --i1, --i2) {
|
|
193
|
-
while (!(0, exports.isAlphanumericSymbol)(valueStr[i1]) && i1 > -1) {
|
|
194
|
-
--i1;
|
|
237
|
+
const pos = endPos == null ? value.length : endPos < 0 ? value.length + endPos : endPos;
|
|
238
|
+
let valueIndex = Math.min(value.length, Math.max(0, Math.trunc(pos) || 0)) - 1;
|
|
239
|
+
for (let i = search.length - 1; i >= 0; --i) {
|
|
240
|
+
const searchCode = alphanumericCode(search, i);
|
|
241
|
+
if (!searchCode) {
|
|
242
|
+
continue;
|
|
195
243
|
}
|
|
196
|
-
|
|
197
|
-
|
|
244
|
+
let valueCode = 0;
|
|
245
|
+
while (valueIndex >= 0 && !valueCode) {
|
|
246
|
+
valueCode = alphanumericCode(value, valueIndex--);
|
|
198
247
|
}
|
|
199
|
-
if (
|
|
248
|
+
if (valueCode !== searchCode) {
|
|
200
249
|
return false;
|
|
201
250
|
}
|
|
202
251
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Constant } from "../Constant.js";
|
|
2
|
+
export type TimestampEncoding = "i32" | "i32le" | "i64" | "i64le";
|
|
3
|
+
export declare const formatLiteralTimestamp: (value: Date) => string;
|
|
4
|
+
export declare const parseLiteralTimestamp: (value: string, offset?: number) => readonly [Date, number];
|
|
5
|
+
export declare const encodeTimestamp: (value: Date, encoding?: TimestampEncoding) => ArrayBuffer;
|
|
6
|
+
export declare const decodeTimestamp: (value?: ArrayBuffer, encoding?: TimestampEncoding, byteOffset?: number) => Date | undefined;
|
|
7
|
+
export declare const formatTimestamp: (value: Date, template?: string) => string;
|
|
8
|
+
export declare const funcYear: Constant;
|
|
9
|
+
export declare const funcMonth: Constant;
|
|
10
|
+
export declare const funcMonthIndex: Constant;
|
|
11
|
+
export declare const funcWeekdayIndex: Constant;
|
|
12
|
+
export declare const funcDay: Constant;
|
|
13
|
+
export declare const funcHour: Constant;
|
|
14
|
+
export declare const funcMinute: Constant;
|
|
15
|
+
export declare const funcSecond: Constant;
|
|
16
|
+
export declare const funcMillisecond: Constant;
|
|
17
|
+
export declare const funcEpochTime: Constant;
|
|
18
|
+
export declare const funcDaysSince: Constant;
|
|
19
|
+
export declare const funcHoursSince: Constant;
|
|
20
|
+
export declare const funcMinutesSince: Constant;
|
|
21
|
+
export declare const funcSecondsSince: Constant;
|
|
22
|
+
export declare const constTimestamp: any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Constant } from "../Constant.js";
|
|
2
|
+
import { Value } from "../Value.js";
|
|
3
|
+
import { FloatEncoding } from "./Float.js";
|
|
4
|
+
import { IntegerEncoding } from "./Integer.js";
|
|
5
|
+
import { StringEncoding } from "./String.js";
|
|
6
|
+
import { TimestampEncoding } from "./Timestamp.js";
|
|
7
|
+
export declare const equate: (value1: Value, value2: Value) => boolean;
|
|
8
|
+
export declare const encode: (value: Value, encoding?: FloatEncoding | IntegerEncoding | TimestampEncoding | StringEncoding) => ArrayBuffer;
|
|
9
|
+
export declare const format: (value: Value, formatting?: string) => string;
|
|
10
|
+
export declare const funcCoalesce: Constant;
|
|
11
|
+
export declare const funcEqual: Constant;
|
|
12
|
+
export declare const funcNotEqual: Constant;
|
|
13
|
+
export declare const funcEncode: Constant;
|
|
14
|
+
export declare const funcFormat: Constant;
|
|
@@ -15,7 +15,7 @@ const equate = (value1, value2) => {
|
|
|
15
15
|
}
|
|
16
16
|
if (typeof value1 !== typeof value2) {
|
|
17
17
|
if (typeof value1 === "number" && typeof value2 === "bigint") {
|
|
18
|
-
return value1 ===
|
|
18
|
+
return Number.isInteger(value1) && BigInt(value1) === value2;
|
|
19
19
|
}
|
|
20
20
|
if (typeof value1 === "bigint" && typeof value2 === "number") {
|
|
21
21
|
return Number.isInteger(value2) && value1 === BigInt(value2);
|
|
@@ -31,9 +31,15 @@ const equate = (value1, value2) => {
|
|
|
31
31
|
if (value1 instanceof Date && value2 instanceof Date) {
|
|
32
32
|
return value1.getTime() === value2.getTime();
|
|
33
33
|
}
|
|
34
|
+
if (value1 instanceof Date || value2 instanceof Date) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
34
37
|
if (value1 instanceof ArrayBuffer && value2 instanceof ArrayBuffer) {
|
|
35
38
|
return (0, Buffer_js_1.equateBuffers)(value1, value2);
|
|
36
39
|
}
|
|
40
|
+
if (value1 instanceof ArrayBuffer || value2 instanceof ArrayBuffer) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
37
43
|
if (Array.isArray(value1) && Array.isArray(value2)) {
|
|
38
44
|
if (value1.length === value2.length) {
|
|
39
45
|
for (let i = 0; i < value1.length; ++i) {
|
|
@@ -45,6 +51,9 @@ const equate = (value1, value2) => {
|
|
|
45
51
|
}
|
|
46
52
|
return false;
|
|
47
53
|
}
|
|
54
|
+
if (Array.isArray(value1) || Array.isArray(value2)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
48
57
|
const props = new Set([...Object.getOwnPropertyNames(value1), ...Object.getOwnPropertyNames(value2)]);
|
|
49
58
|
for (const prop of props) {
|
|
50
59
|
if (!(0, exports.equate)(value1[prop], value2[prop])) {
|
|
@@ -13,7 +13,7 @@ const Timestamp_js_1 = require("../Timestamp.js");
|
|
|
13
13
|
const typeAN = Type_js_1.Type.union(Type_js_1.Type.Void, Type_js_1.Type.Boolean, Type_js_1.Type.Timestamp, Type_js_1.Type.Float, Type_js_1.Type.Integer, Type_js_1.Type.Buffer, Type_js_1.Type.String, Type_js_1.Type.Array, Type_js_1.Type.Object);
|
|
14
14
|
const formatAN = (value, whitespace) => {
|
|
15
15
|
if (value == null) {
|
|
16
|
-
return "";
|
|
16
|
+
return "null";
|
|
17
17
|
}
|
|
18
18
|
if (typeof value === "boolean") {
|
|
19
19
|
return value ? "true" : "false";
|
|
@@ -32,7 +32,7 @@ const formatAN = (value, whitespace) => {
|
|
|
32
32
|
}
|
|
33
33
|
if (Array.isArray(value)) {
|
|
34
34
|
const [prefix, suffix] = whitespace ? ["\n" + whitespace, "\n"] : ["", ""];
|
|
35
|
-
const lines =
|
|
35
|
+
const lines = Array.from(value, (i) => `${prefix}${(0, exports.formatAN)(i, whitespace)?.split("\n").join(prefix) ?? ""}`);
|
|
36
36
|
return lines.length ? `[${lines.join(",")}${suffix}]` : "[]";
|
|
37
37
|
}
|
|
38
38
|
if (typeof value === "object") {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const constIP: any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Node } from "../Node.js";
|
|
2
|
+
import { ScriptSpan } from "../ScriptSpan.js";
|
|
3
|
+
import { Value } from "../Value.js";
|
|
4
|
+
import { Type } from "../Type.js";
|
|
5
|
+
import { CallFrame } from "../CallFrame.js";
|
|
6
|
+
export declare class ArrayNode extends Node {
|
|
7
|
+
protected _subnodes: Node[];
|
|
8
|
+
protected _type: Type;
|
|
9
|
+
constructor(span: ScriptSpan, _subnodes: Node[]);
|
|
10
|
+
get type(): Type;
|
|
11
|
+
compile(type: Type): Node;
|
|
12
|
+
evaluate(frame: CallFrame): Value;
|
|
13
|
+
toString(ident?: number): string;
|
|
14
|
+
}
|
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ArrayNode = void 0;
|
|
4
4
|
const Node_js_1 = require("../Node.js");
|
|
5
|
-
const Constant_js_1 = require("../Constant.js");
|
|
6
|
-
const ConstantNode_js_1 = require("./ConstantNode.js");
|
|
7
5
|
const Type_js_1 = require("../Type.js");
|
|
8
6
|
class ArrayNode extends Node_js_1.Node {
|
|
9
7
|
_subnodes;
|
|
10
8
|
_type;
|
|
11
|
-
constructor(
|
|
12
|
-
super(
|
|
9
|
+
constructor(span, _subnodes) {
|
|
10
|
+
super(span);
|
|
13
11
|
this._subnodes = _subnodes;
|
|
14
12
|
this._type = Type_js_1.Type.arrayType(_subnodes.map((i) => i.type));
|
|
15
13
|
}
|
|
@@ -17,23 +15,18 @@ class ArrayNode extends Node_js_1.Node {
|
|
|
17
15
|
return this._type;
|
|
18
16
|
}
|
|
19
17
|
compile(type) {
|
|
20
|
-
let constant = true;
|
|
21
18
|
for (let i = 0; i < this._subnodes.length; ++i) {
|
|
22
19
|
const valType = type.arrayAtomValType(i);
|
|
23
20
|
this._subnodes[i] = this._subnodes[i].compile(valType);
|
|
24
|
-
constant &&= this._subnodes[i].constant;
|
|
25
21
|
}
|
|
26
22
|
this._type = Type_js_1.Type.arrayType(this._subnodes.map((node) => node.type));
|
|
27
23
|
this._type = this.reduceType(type);
|
|
28
|
-
if (constant) {
|
|
29
|
-
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
|
|
30
|
-
}
|
|
31
24
|
return this;
|
|
32
25
|
}
|
|
33
|
-
evaluate() {
|
|
26
|
+
evaluate(frame) {
|
|
34
27
|
const result = [];
|
|
35
28
|
for (const subnode of this._subnodes) {
|
|
36
|
-
result.push(subnode.evaluate());
|
|
29
|
+
result.push(subnode.evaluate(frame));
|
|
37
30
|
}
|
|
38
31
|
return result;
|
|
39
32
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Node } from "../Node.js";
|
|
2
|
+
import { ScriptSpan } from "../ScriptSpan.js";
|
|
3
|
+
import { Value } from "../Value.js";
|
|
4
|
+
import { Type } from "../Type.js";
|
|
5
|
+
import { CallFrame } from "../CallFrame.js";
|
|
6
|
+
import { Variable } from "../Variable.js";
|
|
7
|
+
export declare class BlockNode extends Node {
|
|
8
|
+
protected _subnodes: Node[];
|
|
9
|
+
protected readonly _variables: Variable[];
|
|
10
|
+
constructor(span: ScriptSpan, _subnodes: Node[], _variables?: Variable[]);
|
|
11
|
+
get type(): Type;
|
|
12
|
+
compile(type: Type): Node;
|
|
13
|
+
evaluate(frame: CallFrame): Value;
|
|
14
|
+
toString(ident?: number): string;
|
|
15
|
+
}
|
|
@@ -5,11 +5,14 @@ const Node_js_1 = require("../Node.js");
|
|
|
5
5
|
const Constant_js_1 = require("../Constant.js");
|
|
6
6
|
const ConstantNode_js_1 = require("./ConstantNode.js");
|
|
7
7
|
const Type_js_1 = require("../Type.js");
|
|
8
|
+
const CallFrame_js_1 = require("../CallFrame.js");
|
|
8
9
|
class BlockNode extends Node_js_1.Node {
|
|
9
10
|
_subnodes;
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
_variables;
|
|
12
|
+
constructor(span, _subnodes, _variables = []) {
|
|
13
|
+
super(span);
|
|
12
14
|
this._subnodes = _subnodes;
|
|
15
|
+
this._variables = _variables;
|
|
13
16
|
}
|
|
14
17
|
get type() {
|
|
15
18
|
return this._subnodes.length ? this._subnodes[this._subnodes.length - 1].type : Type_js_1.Type.Void;
|
|
@@ -25,17 +28,18 @@ class BlockNode extends Node_js_1.Node {
|
|
|
25
28
|
constant &&= this._subnodes[i].constant;
|
|
26
29
|
}
|
|
27
30
|
if (constant) {
|
|
28
|
-
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(), this.type));
|
|
31
|
+
return new ConstantNode_js_1.ConstantNode(this, new Constant_js_1.Constant(this.evaluate(new CallFrame_js_1.CallFrame()), this.type));
|
|
29
32
|
}
|
|
30
|
-
if (this._subnodes.length === 1) {
|
|
33
|
+
if (this._subnodes.length === 1 && this._variables.length === 0) {
|
|
31
34
|
return this._subnodes[0];
|
|
32
35
|
}
|
|
33
36
|
return this;
|
|
34
37
|
}
|
|
35
|
-
evaluate() {
|
|
38
|
+
evaluate(frame) {
|
|
39
|
+
const subframe = this._variables.length ? frame.subframe(this._variables) : frame;
|
|
36
40
|
let result = undefined;
|
|
37
41
|
for (const subnode of this._subnodes) {
|
|
38
|
-
result = subnode.evaluate();
|
|
42
|
+
result = subnode.evaluate(subframe);
|
|
39
43
|
}
|
|
40
44
|
return result;
|
|
41
45
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Node } from "../Node.js";
|
|
2
|
+
import { ScriptSpan } from "../ScriptSpan.js";
|
|
3
|
+
import { Value } from "../Value.js";
|
|
4
|
+
import { Type } from "../Type.js";
|
|
5
|
+
import { CallFrame } from "../CallFrame.js";
|
|
6
|
+
export declare class CallNode extends Node {
|
|
7
|
+
protected _fnode: Node;
|
|
8
|
+
protected _subnodes: Node[];
|
|
9
|
+
protected _type: Type;
|
|
10
|
+
constructor(span: ScriptSpan, _fnode: Node, _subnodes: Node[]);
|
|
11
|
+
get type(): Type;
|
|
12
|
+
compile(type: Type): Node;
|
|
13
|
+
evaluate(frame: CallFrame): Value;
|
|
14
|
+
toString(ident?: number): string;
|
|
15
|
+
}
|