affinirum 1.5.4 → 2.0.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.
Files changed (243) hide show
  1. package/.cache/arrow-preview-vWvB5K/affinirum-arrow-functions.patch +155 -0
  2. package/.cache/function-syntax-tests.log +20 -0
  3. package/README.md +925 -355
  4. package/dst/Affinirum.d.ts +29 -19
  5. package/dst/Affinirum.js +399 -334
  6. package/dst/CallFrame.d.ts +12 -3
  7. package/dst/CallFrame.js +49 -10
  8. package/dst/Constant.d.ts +1 -3
  9. package/dst/Constant.js +3 -8
  10. package/dst/LexicalScope.d.ts +11 -9
  11. package/dst/LexicalScope.js +10 -6
  12. package/dst/ParserSpan.d.ts +11 -0
  13. package/dst/{ScriptSpan.js → ParserSpan.js} +8 -5
  14. package/dst/ParserState.d.ts +28 -49
  15. package/dst/ParserState.js +256 -489
  16. package/dst/Type.d.ts +34 -17
  17. package/dst/Type.js +211 -115
  18. package/dst/TypeParser.d.ts +9 -0
  19. package/dst/TypeParser.js +127 -0
  20. package/dst/Value.d.ts +1 -1
  21. package/dst/Value.js +21 -10
  22. package/dst/Variable.d.ts +16 -5
  23. package/dst/Variable.js +32 -7
  24. package/dst/atom/ArrayAtom.d.ts +10 -10
  25. package/dst/atom/ArrayAtom.js +62 -55
  26. package/dst/atom/Atom.d.ts +7 -0
  27. package/dst/atom/FunctionAtom.d.ts +13 -15
  28. package/dst/atom/FunctionAtom.js +53 -104
  29. package/dst/atom/FunctionSignature.d.ts +23 -0
  30. package/dst/atom/FunctionSignature.js +124 -0
  31. package/dst/atom/ObjectAtom.d.ts +11 -9
  32. package/dst/atom/ObjectAtom.js +73 -33
  33. package/dst/atom/PrimitiveAtom.d.ts +6 -7
  34. package/dst/atom/PrimitiveAtom.js +7 -10
  35. package/dst/cjs/Affinirum.d.ts +29 -19
  36. package/dst/cjs/Affinirum.js +398 -333
  37. package/dst/cjs/CallFrame.d.ts +12 -3
  38. package/dst/cjs/CallFrame.js +49 -10
  39. package/dst/cjs/Constant.d.ts +1 -3
  40. package/dst/cjs/Constant.js +3 -8
  41. package/dst/cjs/LexicalScope.d.ts +11 -9
  42. package/dst/cjs/LexicalScope.js +10 -6
  43. package/dst/cjs/ParserSpan.d.ts +11 -0
  44. package/dst/cjs/{ScriptSpan.js → ParserSpan.js} +10 -7
  45. package/dst/cjs/ParserState.d.ts +28 -49
  46. package/dst/cjs/ParserState.js +255 -488
  47. package/dst/cjs/Type.d.ts +34 -17
  48. package/dst/cjs/Type.js +211 -115
  49. package/dst/cjs/TypeParser.d.ts +9 -0
  50. package/dst/cjs/TypeParser.js +131 -0
  51. package/dst/cjs/Value.d.ts +1 -1
  52. package/dst/cjs/Value.js +21 -10
  53. package/dst/cjs/Variable.d.ts +16 -5
  54. package/dst/cjs/Variable.js +36 -9
  55. package/dst/cjs/atom/ArrayAtom.d.ts +10 -10
  56. package/dst/cjs/atom/ArrayAtom.js +62 -55
  57. package/dst/cjs/atom/Atom.d.ts +7 -0
  58. package/dst/cjs/atom/FunctionAtom.d.ts +13 -15
  59. package/dst/cjs/atom/FunctionAtom.js +54 -105
  60. package/dst/cjs/atom/FunctionSignature.d.ts +23 -0
  61. package/dst/cjs/atom/FunctionSignature.js +128 -0
  62. package/dst/cjs/atom/ObjectAtom.d.ts +11 -9
  63. package/dst/cjs/atom/ObjectAtom.js +73 -33
  64. package/dst/cjs/atom/PrimitiveAtom.d.ts +6 -7
  65. package/dst/cjs/atom/PrimitiveAtom.js +7 -10
  66. package/dst/cjs/dictionary/Constants.d.ts +2 -0
  67. package/dst/cjs/dictionary/Constants.js +27 -0
  68. package/dst/cjs/dictionary/Functions.d.ts +2 -0
  69. package/dst/cjs/{Functions.js → dictionary/Functions.js} +27 -25
  70. package/dst/cjs/native/Aggregable.js +10 -2
  71. package/dst/cjs/native/Array.d.ts +2 -3
  72. package/dst/cjs/native/Array.js +38 -39
  73. package/dst/cjs/native/Boolean.d.ts +1 -1
  74. package/dst/cjs/native/Boolean.js +13 -10
  75. package/dst/cjs/native/Buffer.d.ts +5 -5
  76. package/dst/cjs/native/Buffer.js +70 -46
  77. package/dst/cjs/native/Composite.d.ts +5 -0
  78. package/dst/cjs/native/Composite.js +35 -0
  79. package/dst/cjs/native/Enumerable.js +20 -8
  80. package/dst/cjs/native/Float.d.ts +3 -1
  81. package/dst/cjs/native/Float.js +51 -12
  82. package/dst/cjs/native/Integer.d.ts +4 -2
  83. package/dst/cjs/native/Integer.js +60 -25
  84. package/dst/cjs/native/Iterable.d.ts +0 -2
  85. package/dst/cjs/native/Iterable.js +9 -28
  86. package/dst/cjs/native/Number.d.ts +0 -2
  87. package/dst/cjs/native/Number.js +34 -48
  88. package/dst/cjs/native/Object.d.ts +1 -1
  89. package/dst/cjs/native/Object.js +5 -6
  90. package/dst/cjs/native/String.d.ts +7 -6
  91. package/dst/cjs/native/String.js +28 -27
  92. package/dst/cjs/native/Timestamp.d.ts +3 -3
  93. package/dst/cjs/native/Timestamp.js +34 -36
  94. package/dst/cjs/native/Unknown.d.ts +3 -3
  95. package/dst/cjs/native/Unknown.js +48 -17
  96. package/dst/cjs/native/notation/AN.d.ts +1 -1
  97. package/dst/cjs/native/notation/AN.js +37 -35
  98. package/dst/cjs/native/notation/IP.d.ts +1 -1
  99. package/dst/cjs/native/notation/IP.js +11 -12
  100. package/dst/cjs/native/notation/JSON.d.ts +1 -1
  101. package/dst/cjs/native/notation/JSON.js +7 -6
  102. package/dst/cjs/node/AccessNode.d.ts +24 -0
  103. package/dst/cjs/node/AccessNode.js +193 -0
  104. package/dst/cjs/node/ArrayNode.d.ts +7 -4
  105. package/dst/cjs/node/ArrayNode.js +26 -15
  106. package/dst/cjs/node/AssignableNode.d.ts +16 -0
  107. package/dst/cjs/node/AssignableNode.js +18 -0
  108. package/dst/cjs/node/AssignmentNode.d.ts +20 -0
  109. package/dst/cjs/node/AssignmentNode.js +66 -0
  110. package/dst/cjs/node/BlockNode.d.ts +5 -4
  111. package/dst/cjs/node/BlockNode.js +18 -11
  112. package/dst/cjs/node/CallNode.d.ts +7 -5
  113. package/dst/cjs/node/CallNode.js +40 -41
  114. package/dst/cjs/node/CastNode.d.ts +5 -6
  115. package/dst/cjs/node/CastNode.js +16 -17
  116. package/dst/cjs/node/ConstantNode.d.ts +4 -6
  117. package/dst/cjs/node/ConstantNode.js +9 -17
  118. package/dst/cjs/node/FinalNode.d.ts +19 -0
  119. package/dst/cjs/node/FinalNode.js +41 -0
  120. package/dst/cjs/node/FunctionNode.d.ts +17 -0
  121. package/dst/cjs/node/FunctionNode.js +51 -0
  122. package/dst/cjs/node/InvocationNode.d.ts +5 -0
  123. package/dst/cjs/node/InvocationNode.js +34 -0
  124. package/dst/cjs/node/JumpNode.d.ts +7 -9
  125. package/dst/cjs/node/JumpNode.js +12 -19
  126. package/dst/cjs/node/LoopNode.d.ts +7 -5
  127. package/dst/cjs/node/LoopNode.js +33 -22
  128. package/dst/cjs/node/MatchNode.d.ts +17 -0
  129. package/dst/cjs/node/MatchNode.js +65 -0
  130. package/dst/cjs/node/Node.d.ts +14 -0
  131. package/dst/cjs/{Node.js → node/Node.js} +17 -11
  132. package/dst/cjs/node/ObjectNode.d.ts +7 -4
  133. package/dst/cjs/node/ObjectNode.js +42 -11
  134. package/dst/cjs/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
  135. package/dst/cjs/node/TernaryNode.js +45 -0
  136. package/dst/cjs/node/VariableNode.d.ts +10 -6
  137. package/dst/cjs/node/VariableNode.js +50 -16
  138. package/dst/dictionary/Constants.d.ts +2 -0
  139. package/dst/dictionary/Constants.js +24 -0
  140. package/dst/dictionary/Functions.d.ts +2 -0
  141. package/dst/{Functions.js → dictionary/Functions.js} +26 -24
  142. package/dst/native/Aggregable.js +11 -3
  143. package/dst/native/Array.d.ts +2 -3
  144. package/dst/native/Array.js +37 -38
  145. package/dst/native/Boolean.d.ts +1 -1
  146. package/dst/native/Boolean.js +12 -9
  147. package/dst/native/Buffer.d.ts +5 -5
  148. package/dst/native/Buffer.js +66 -42
  149. package/dst/native/Composite.d.ts +5 -0
  150. package/dst/native/Composite.js +32 -0
  151. package/dst/native/Enumerable.js +20 -8
  152. package/dst/native/Float.d.ts +3 -1
  153. package/dst/native/Float.js +48 -11
  154. package/dst/native/Integer.d.ts +4 -2
  155. package/dst/native/Integer.js +56 -23
  156. package/dst/native/Iterable.d.ts +0 -2
  157. package/dst/native/Iterable.js +8 -27
  158. package/dst/native/Number.d.ts +0 -2
  159. package/dst/native/Number.js +34 -46
  160. package/dst/native/Object.d.ts +1 -1
  161. package/dst/native/Object.js +4 -5
  162. package/dst/native/String.d.ts +7 -6
  163. package/dst/native/String.js +24 -24
  164. package/dst/native/Timestamp.d.ts +3 -3
  165. package/dst/native/Timestamp.js +31 -33
  166. package/dst/native/Unknown.d.ts +3 -3
  167. package/dst/native/Unknown.js +49 -18
  168. package/dst/native/notation/AN.d.ts +1 -1
  169. package/dst/native/notation/AN.js +37 -35
  170. package/dst/native/notation/IP.d.ts +1 -1
  171. package/dst/native/notation/IP.js +10 -11
  172. package/dst/native/notation/JSON.d.ts +1 -1
  173. package/dst/native/notation/JSON.js +6 -5
  174. package/dst/node/AccessNode.d.ts +24 -0
  175. package/dst/node/AccessNode.js +189 -0
  176. package/dst/node/ArrayNode.d.ts +7 -4
  177. package/dst/node/ArrayNode.js +26 -15
  178. package/dst/node/AssignableNode.d.ts +16 -0
  179. package/dst/node/AssignableNode.js +14 -0
  180. package/dst/node/AssignmentNode.d.ts +20 -0
  181. package/dst/node/AssignmentNode.js +62 -0
  182. package/dst/node/BlockNode.d.ts +5 -4
  183. package/dst/node/BlockNode.js +18 -11
  184. package/dst/node/CallNode.d.ts +7 -5
  185. package/dst/node/CallNode.js +40 -41
  186. package/dst/node/CastNode.d.ts +5 -6
  187. package/dst/node/CastNode.js +16 -17
  188. package/dst/node/ConstantNode.d.ts +4 -6
  189. package/dst/node/ConstantNode.js +9 -17
  190. package/dst/node/FinalNode.d.ts +19 -0
  191. package/dst/node/FinalNode.js +37 -0
  192. package/dst/node/FunctionNode.d.ts +17 -0
  193. package/dst/node/FunctionNode.js +47 -0
  194. package/dst/node/InvocationNode.d.ts +5 -0
  195. package/dst/node/InvocationNode.js +30 -0
  196. package/dst/node/JumpNode.d.ts +7 -9
  197. package/dst/node/JumpNode.js +12 -19
  198. package/dst/node/LoopNode.d.ts +7 -5
  199. package/dst/node/LoopNode.js +33 -22
  200. package/dst/node/MatchNode.d.ts +17 -0
  201. package/dst/node/MatchNode.js +61 -0
  202. package/dst/node/Node.d.ts +14 -0
  203. package/dst/node/Node.js +28 -0
  204. package/dst/node/ObjectNode.d.ts +7 -4
  205. package/dst/node/ObjectNode.js +42 -11
  206. package/dst/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
  207. package/dst/node/TernaryNode.js +41 -0
  208. package/dst/node/VariableNode.d.ts +10 -6
  209. package/dst/node/VariableNode.js +50 -16
  210. package/package.json +4 -4
  211. package/dst/Atom.d.ts +0 -7
  212. package/dst/Constants.d.ts +0 -2
  213. package/dst/Constants.js +0 -24
  214. package/dst/Functions.d.ts +0 -2
  215. package/dst/Jump.d.ts +0 -1
  216. package/dst/Jump.js +0 -1
  217. package/dst/JumpException.d.ts +0 -9
  218. package/dst/JumpException.js +0 -14
  219. package/dst/Keywords.d.ts +0 -1
  220. package/dst/Keywords.js +0 -17
  221. package/dst/Node.d.ts +0 -14
  222. package/dst/Node.js +0 -22
  223. package/dst/ScriptSpan.d.ts +0 -10
  224. package/dst/cjs/Atom.d.ts +0 -7
  225. package/dst/cjs/Constants.d.ts +0 -2
  226. package/dst/cjs/Constants.js +0 -27
  227. package/dst/cjs/Functions.d.ts +0 -2
  228. package/dst/cjs/Jump.d.ts +0 -1
  229. package/dst/cjs/Jump.js +0 -2
  230. package/dst/cjs/JumpException.d.ts +0 -9
  231. package/dst/cjs/JumpException.js +0 -18
  232. package/dst/cjs/Keywords.d.ts +0 -1
  233. package/dst/cjs/Keywords.js +0 -20
  234. package/dst/cjs/Node.d.ts +0 -14
  235. package/dst/cjs/ScriptSpan.d.ts +0 -10
  236. package/dst/cjs/node/SwitchNode.js +0 -49
  237. package/dst/cjs/node/VariadicNode.d.ts +0 -4
  238. package/dst/cjs/node/VariadicNode.js +0 -10
  239. package/dst/node/SwitchNode.js +0 -45
  240. package/dst/node/VariadicNode.d.ts +0 -4
  241. package/dst/node/VariadicNode.js +0 -6
  242. /package/dst/{Atom.js → atom/Atom.js} +0 -0
  243. /package/dst/cjs/{Atom.js → atom/Atom.js} +0 -0
@@ -1,13 +1,12 @@
1
1
  import { Constant } from "../../Constant.js";
2
2
  import { ParserState } from "../../ParserState.js";
3
3
  import { Type } from "../../Type.js";
4
- import { funcAdd } from "../Aggregable.js";
5
- import { boundInteger } from "../Integer.js";
6
- import { formatLiteralNumber, funcSubtract } from "../Number.js";
4
+ import { formatLiteralFloat } from "../Float.js";
5
+ import { formatLiteralInteger, int64 } from "../Integer.js";
7
6
  import { formatLiteralBuffer } from "../Buffer.js";
8
7
  import { formatLiteralString } from "../String.js";
9
8
  import { formatLiteralTimestamp } from "../Timestamp.js";
10
- const typeAN = Type.union(Type.Void, Type.Boolean, Type.Timestamp, Type.Float, Type.Integer, Type.Buffer, Type.String, Type.Array, Type.Object);
9
+ const typeAN = Type.union(Type.Null, Type.Boolean, Type.Timestamp, Type.Float, Type.Integer, Type.Buffer, Type.String, Type.Array, Type.Object);
11
10
  export const formatAN = (value, whitespace) => {
12
11
  if (value == null) {
13
12
  return "null";
@@ -18,8 +17,11 @@ export const formatAN = (value, whitespace) => {
18
17
  if (value instanceof Date) {
19
18
  return formatLiteralTimestamp(value);
20
19
  }
21
- if (typeof value === "bigint" || typeof value === "number") {
22
- return formatLiteralNumber(value);
20
+ if (typeof value === "number") {
21
+ return formatLiteralFloat(value);
22
+ }
23
+ if (typeof value === "bigint") {
24
+ return formatLiteralInteger(value);
23
25
  }
24
26
  if (value instanceof ArrayBuffer) {
25
27
  return formatLiteralBuffer(value);
@@ -41,20 +43,20 @@ export const formatAN = (value, whitespace) => {
41
43
  };
42
44
  const parseArray = (state, firstValue) => {
43
45
  const arr = [firstValue];
44
- while (!state.isEmpty) {
45
- if (state.isBracketsClose) {
46
+ while (!state.isEnded) {
47
+ if (state.equals("]")) {
46
48
  state.next();
47
49
  return arr;
48
50
  }
49
- if (!state.isComma) {
51
+ if (!state.equals(",")) {
50
52
  state.throwError("missing array value separator");
51
53
  }
52
54
  state.next();
53
- if (state.isBracketsClose) {
55
+ if (state.equals("]")) {
54
56
  state.next();
55
57
  return arr;
56
58
  }
57
- if (state.isComma) {
59
+ if (state.equals(",")) {
58
60
  arr.push(undefined);
59
61
  continue;
60
62
  }
@@ -65,21 +67,21 @@ const parseArray = (state, firstValue) => {
65
67
  const parseObject = (state, firstKey) => {
66
68
  const obj = Object.create(null);
67
69
  let key = firstKey;
68
- while (!state.isEmpty) {
69
- if (!state.isColon) {
70
+ while (!state.isEnded) {
71
+ if (!state.equals(":")) {
70
72
  state.throwError("missing object key separator");
71
73
  }
72
74
  state.next();
73
- obj[key] = state.isComma || state.isBracketsClose ? undefined : parseLiteral(state);
74
- if (state.isBracketsClose) {
75
+ obj[key] = state.equals(",") || state.equals("]") ? undefined : parseLiteral(state);
76
+ if (state.equals("]")) {
75
77
  state.next();
76
78
  return obj;
77
79
  }
78
- if (!state.isComma) {
80
+ if (!state.equals(",")) {
79
81
  state.throwError("missing object property separator");
80
82
  }
81
83
  state.next();
82
- if (state.isBracketsClose) {
84
+ if (state.equals("]")) {
83
85
  state.next();
84
86
  return obj;
85
87
  }
@@ -100,12 +102,12 @@ const parseLiteral = (state) => {
100
102
  state.next();
101
103
  return value;
102
104
  }
103
- if (state.isType && state.type.isVoid) {
105
+ if (state.isType && state.type.isNull) {
104
106
  state.next();
105
107
  return undefined;
106
108
  }
107
- if (state.isToken) {
108
- const token = state.token;
109
+ if (state.isIdentifier) {
110
+ const token = state.identifier;
109
111
  if (token === "NaN") {
110
112
  state.next();
111
113
  return NaN;
@@ -116,10 +118,10 @@ const parseLiteral = (state) => {
116
118
  }
117
119
  state.throwError(`invalid value ${token}`);
118
120
  }
119
- if (state.isOperator && (state.operator === funcAdd || state.operator === funcSubtract)) {
120
- const negative = state.operator === funcSubtract;
121
+ if (state.equals("+", "-")) {
122
+ const negative = state.equals("-");
121
123
  state.next();
122
- if (state.isToken && state.token === "Infinity") {
124
+ if (state.isIdentifier && state.identifier === "Infinity") {
123
125
  state.next();
124
126
  return negative ? -Infinity : Infinity;
125
127
  }
@@ -129,28 +131,28 @@ const parseLiteral = (state) => {
129
131
  const value = state.literal.value;
130
132
  state.next();
131
133
  return negative
132
- ? typeof value === "bigint" ? boundInteger(-value) : -value
134
+ ? typeof value === "bigint" ? int64(-value) : -value
133
135
  : value;
134
136
  }
135
- if (state.isBracketsOpen) {
137
+ if (state.equals("[")) {
136
138
  state.next();
137
- if (state.isBracketsClose) {
139
+ if (state.equals("]")) {
138
140
  state.next();
139
141
  return [];
140
142
  }
141
- if (state.isColon) {
143
+ if (state.equals(":")) {
142
144
  state.next();
143
- if (!state.isBracketsClose) {
145
+ if (!state.equals("]")) {
144
146
  state.throwError("missing closing object bracket");
145
147
  }
146
148
  state.next();
147
149
  return Object.create(null);
148
150
  }
149
- if (state.isComma) {
151
+ if (state.equals(",")) {
150
152
  return parseArray(state, undefined);
151
153
  }
152
154
  const first = parseLiteral(state);
153
- if (state.isColon) {
155
+ if (state.equals(":")) {
154
156
  if (typeof first !== "string") {
155
157
  state.throwError("object key must be a string");
156
158
  }
@@ -165,18 +167,18 @@ export const parseAN = (value) => {
165
167
  return undefined;
166
168
  }
167
169
  const state = new ParserState(value).next();
168
- if (state.isEmpty) {
170
+ if (state.isEnded) {
169
171
  return undefined;
170
172
  }
171
173
  const result = parseLiteral(state);
172
- if (!state.isEmpty) {
174
+ if (!state.isEnded) {
173
175
  state.throwError("unexpected token");
174
176
  }
175
177
  return result;
176
178
  };
177
- const funcFormatAN = new Constant((value, whitespace) => formatAN(value, whitespace), Type.functionType(Type.String, [Type.Unknown, Type.OptionalString]));
178
- const funcParseAN = new Constant((value) => parseAN(value), Type.functionType(typeAN, [Type.OptionalString]));
179
- export const constAN = Object.assign(Object.create(null), {
179
+ const funcFormatAN = new Constant((value, whitespace) => formatAN(value, whitespace), Type.functionType([[Type.String, [Type.Any, Type.OptionalString]]]));
180
+ const funcParseAN = new Constant((value) => parseAN(value), Type.functionType([[typeAN, [Type.OptionalString]]]));
181
+ export const globAN = Object.assign(Object.create(null), {
180
182
  Format: funcFormatAN,
181
183
  Parse: funcParseAN,
182
184
  });
@@ -1 +1 @@
1
- export declare const constIP: any;
1
+ export declare const globIP: any;
@@ -45,8 +45,8 @@ function encodeIP(value) {
45
45
  const lastPart = zeroCompressionFlag ? endParts[endParts.length - 1] : beginParts[beginParts.length - 1];
46
46
  const ipv4TailFlag = lastPart?.includes(".");
47
47
  if (ipv4TailFlag) {
48
- if (zeroCompressionFlag && beginParts.length + endParts.length > 6
49
- || !zeroCompressionFlag && beginParts.length + endParts.length !== 7) {
48
+ if (zeroCompressionFlag && beginParts.length + endParts.length > 6 ||
49
+ !zeroCompressionFlag && beginParts.length + endParts.length !== 7) {
50
50
  throw new Error(`Invalid IP address: ${value}`);
51
51
  }
52
52
  const ipv4Parts = lastPart.split(".");
@@ -59,8 +59,8 @@ function encodeIP(value) {
59
59
  }
60
60
  }
61
61
  else {
62
- if (zeroCompressionFlag && beginParts.length + endParts.length > 7
63
- || !zeroCompressionFlag && beginParts.length + endParts.length !== 8) {
62
+ if (zeroCompressionFlag && beginParts.length + endParts.length > 7 ||
63
+ !zeroCompressionFlag && beginParts.length + endParts.length !== 8) {
64
64
  throw new Error(`Invalid IP address: ${value}`);
65
65
  }
66
66
  }
@@ -192,11 +192,10 @@ class IPSet {
192
192
  }
193
193
  }
194
194
  }
195
- const typeStringOrArray = Type.union(Type.String, Type.arrayType([Type.String]));
196
- const funcMatchIP = new Constant((values, search) => {
195
+ const funcMatchIP = new Constant((values, ...search) => {
197
196
  try {
198
197
  const ipset = new IPSet().add(values);
199
- for (const ip of search.flat()) {
198
+ for (const ip of search) {
200
199
  try {
201
200
  if (ipset.has(ip)) {
202
201
  return true;
@@ -207,7 +206,7 @@ const funcMatchIP = new Constant((values, search) => {
207
206
  }
208
207
  catch { }
209
208
  return false;
210
- }, Type.functionType(Type.Boolean, [Type.arrayType([Type.String]), Type.arrayType([typeStringOrArray])], true));
209
+ }, Type.functionType([[Type.Boolean, [Type.arrayType(Type.String), Type.arrayType(Type.String)], true]]));
211
210
  const funcEncodeIP = new Constant((value) => {
212
211
  if (value == null) {
213
212
  return EmptyBuffer;
@@ -218,7 +217,7 @@ const funcEncodeIP = new Constant((value) => {
218
217
  catch {
219
218
  return EmptyBuffer;
220
219
  }
221
- }, Type.functionType(Type.Buffer, [Type.OptionalString]));
220
+ }, Type.functionType([[Type.Buffer, [Type.OptionalString]]]));
222
221
  const funcDecodeIP = new Constant((value) => {
223
222
  if (value == null) {
224
223
  return undefined;
@@ -229,8 +228,8 @@ const funcDecodeIP = new Constant((value) => {
229
228
  catch {
230
229
  return undefined;
231
230
  }
232
- }, Type.functionType(Type.OptionalString, [Type.OptionalBuffer]));
233
- export const constIP = Object.assign(Object.create(null), {
231
+ }, Type.functionType([[Type.OptionalString, [Type.OptionalBuffer]]]));
232
+ export const globIP = Object.assign(Object.create(null), {
234
233
  Match: funcMatchIP,
235
234
  Encode: funcEncodeIP,
236
235
  Decode: funcDecodeIP,
@@ -1,3 +1,3 @@
1
1
  import { Value } from "../../Value.js";
2
2
  export declare const formatJSON: (value: Value, whitespace?: string) => string;
3
- export declare const constJSON: any;
3
+ export declare const globJSON: any;
@@ -1,10 +1,11 @@
1
1
  import { Constant } from "../../Constant.js";
2
+ import { normalize } from "../../Value.js";
2
3
  import { Type } from "../../Type.js";
3
- const typeJson = Type.union(Type.Void, Type.Boolean, Type.Timestamp, Type.Float, Type.Integer, Type.String, Type.Array, Type.Object);
4
- export const formatJSON = (value, whitespace) => value == null ? "" : JSON.stringify(value, (_key, value) => typeof value === "bigint" ? value.toString() : value, whitespace);
5
- const funcFormatJSON = new Constant((value, whitespace) => formatJSON(value, whitespace), Type.functionType(Type.String, [typeJson, Type.OptionalString]));
6
- const funcParseJSON = new Constant((value) => value == null ? undefined : JSON.parse(value), Type.functionType(typeJson, [Type.OptionalString]));
7
- export const constJSON = Object.assign(Object.create(null), {
4
+ const typeJson = Type.union(Type.Null, Type.Boolean, Type.Timestamp, Type.Float, Type.Integer, Type.String, Type.Array, Type.Object);
5
+ export const formatJSON = (value, whitespace) => value == null ? "null" : JSON.stringify(value, (_key, value) => typeof value === "bigint" ? value.toString() : value ?? null, whitespace);
6
+ const funcFormatJSON = new Constant((value, whitespace) => formatJSON(value, whitespace), Type.functionType([[Type.String, [typeJson, Type.OptionalString]]]));
7
+ const funcParseJSON = new Constant((value) => value == null ? undefined : normalize(JSON.parse(value)), Type.functionType([[typeJson, [Type.OptionalString]]]));
8
+ export const globJSON = Object.assign(Object.create(null), {
8
9
  Format: funcFormatJSON,
9
10
  Parse: funcParseJSON,
10
11
  });
@@ -0,0 +1,24 @@
1
+ import { AssignableNode, AssignmentResolver } from "./AssignableNode.js";
2
+ import { Node } from "./Node.js";
3
+ import { Constant } from "../Constant.js";
4
+ import { ParserSpan } from "../ParserSpan.js";
5
+ import { Value } from "../Value.js";
6
+ import { Type } from "../Type.js";
7
+ import { CallFrame } from "../CallFrame.js";
8
+ export declare class AccessNode extends AssignableNode {
9
+ protected _subnode: Node;
10
+ protected _inode: Node;
11
+ protected readonly _operator: Constant;
12
+ protected _type?: Type;
13
+ constructor(span: ParserSpan, subnode: Node, inode: Node, operator: Constant);
14
+ get type(): Type;
15
+ get assignable(): boolean;
16
+ get optionalAssignment(): boolean;
17
+ get constant(): boolean;
18
+ compile(type?: Type): Node;
19
+ compileAssignment(type: Type): AssignableNode;
20
+ evaluate(frame: CallFrame): Value;
21
+ resolver(frame: CallFrame): AssignmentResolver | undefined;
22
+ toString(indent?: number): string;
23
+ private _compileAccess;
24
+ }
@@ -0,0 +1,189 @@
1
+ import { AssignableNode } from "./AssignableNode.js";
2
+ import { ConstantNode } from "./ConstantNode.js";
3
+ import { Constant } from "../Constant.js";
4
+ import { Type } from "../Type.js";
5
+ import { CallFrame } from "../CallFrame.js";
6
+ import { funcOptionalAt } from "../native/Composite.js";
7
+ export class AccessNode extends AssignableNode {
8
+ _subnode;
9
+ _inode;
10
+ _operator;
11
+ _type;
12
+ constructor(span, subnode, inode, operator) {
13
+ super(span);
14
+ this._subnode = subnode;
15
+ this._inode = inode;
16
+ this._operator = operator;
17
+ }
18
+ get type() {
19
+ return this._type ?? Type.Any;
20
+ }
21
+ get assignable() {
22
+ return this._subnode instanceof AssignableNode ? this._subnode.assignable : !this._subnode.constant;
23
+ }
24
+ get optionalAssignment() {
25
+ return this._operator === funcOptionalAt && this._subnode.type.isOptional ||
26
+ this._subnode instanceof AccessNode && this._subnode.optionalAssignment;
27
+ }
28
+ get constant() {
29
+ return this._subnode.constant && this._inode.constant;
30
+ }
31
+ compile(type = Type.Any) {
32
+ this._compileAccess();
33
+ if (!this._subnode.type.isNever) {
34
+ this._type = this.type.toOptional();
35
+ }
36
+ super.compile(type);
37
+ if (this.constant && !this.type.intersects(Type.Reference)) {
38
+ return new ConstantNode(this, new Constant(this.evaluate(new CallFrame()), this.type));
39
+ }
40
+ return this;
41
+ }
42
+ compileAssignment(type) {
43
+ this._compileAccess();
44
+ const compiledType = this.reduceAssignmentType(type);
45
+ if (!compiledType) {
46
+ this._throwTypeError(type);
47
+ }
48
+ this._type = compiledType;
49
+ return this;
50
+ }
51
+ evaluate(frame) {
52
+ const func = this._operator.value;
53
+ const composite = this._subnode.evaluate(frame);
54
+ if (func === funcOptionalAt.value && composite == null) {
55
+ return undefined;
56
+ }
57
+ const compositeType = this._operator.type.functionAtomArgType(0) ?? Type.Any;
58
+ if (!compositeType.acceptsValue(composite)) {
59
+ this.throwError("indexed value must be an array or object");
60
+ }
61
+ const value = func(composite, this._inode.evaluate(frame));
62
+ if (value != null && !this.type.acceptsValue(value)) {
63
+ this.throwError(`indexed value mismatch with expected type ${this._type}`);
64
+ }
65
+ return value;
66
+ }
67
+ resolver(frame) {
68
+ const target = this._subnode instanceof AccessNode ? this._subnode : undefined;
69
+ const resolver = target?.resolver(frame);
70
+ if (target && !resolver) {
71
+ return undefined;
72
+ }
73
+ const composite = resolver ? resolver.get() : this._subnode.evaluate(frame);
74
+ if (composite == null) {
75
+ if (this._operator === funcOptionalAt) {
76
+ return undefined;
77
+ }
78
+ this.throwError("cannot assign through null");
79
+ }
80
+ const compositeType = resolver?.type ?? this._subnode.type;
81
+ const key = this._inode.evaluate(frame);
82
+ if (Array.isArray(composite)) {
83
+ if (typeof key !== "bigint") {
84
+ this.throwError("array index must be an integer");
85
+ }
86
+ const num = Number(key);
87
+ const index = num < 0 ? composite.length + num : num;
88
+ const type = compositeType.arrayAtomValType(index);
89
+ return {
90
+ type,
91
+ get: () => index >= 0 && index < composite.length ? composite[index] : undefined,
92
+ set: (value) => {
93
+ if (index < 0 || index >= composite.length) {
94
+ this.throwError("array index is out of range");
95
+ }
96
+ if (!type.acceptsValue(value)) {
97
+ this.throwError(`indexed value mismatch with expected type ${type}`);
98
+ }
99
+ let arr;
100
+ for (const constraint of new Set([compositeType, ...frame.definitions(composite)])) {
101
+ if (constraint.isAny || constraint.equals(Type.Array)) {
102
+ continue;
103
+ }
104
+ if (!arr) {
105
+ arr = composite.slice();
106
+ arr[index] = value;
107
+ }
108
+ if (!constraint.acceptsValue(arr)) {
109
+ this.throwError(`indexed value mismatch with expected type ${constraint}`);
110
+ }
111
+ }
112
+ composite[index] = value;
113
+ return value;
114
+ },
115
+ };
116
+ }
117
+ if (!Type.Object.acceptsValue(composite)) {
118
+ this.throwError("indexed value must be an array or object");
119
+ }
120
+ if (typeof key !== "string") {
121
+ this.throwError("object key must be a string");
122
+ }
123
+ const object = composite;
124
+ const type = compositeType.objectAtomValType(key);
125
+ return {
126
+ type,
127
+ get: () => Object.hasOwn(object, key) ? object[key] : undefined,
128
+ set: (value) => {
129
+ if (!type.acceptsValue(value)) {
130
+ this.throwError(`indexed value mismatch with expected type ${type}`);
131
+ }
132
+ let obj;
133
+ for (const constraint of new Set([compositeType, ...frame.definitions(object)])) {
134
+ if (constraint.isAny || constraint.equals(Type.Object)) {
135
+ continue;
136
+ }
137
+ if (!obj) {
138
+ obj = Object.assign(Object.create(null), object);
139
+ obj[key] = value;
140
+ }
141
+ if (!constraint.acceptsValue(obj)) {
142
+ this.throwError(`indexed value mismatch with expected type ${constraint}`);
143
+ }
144
+ }
145
+ object[key] = value;
146
+ return value;
147
+ },
148
+ };
149
+ }
150
+ toString(indent = 0) {
151
+ return `${super.toString(indent)} index node subnode:\n${this._subnode.toString(indent + 1)}\n`
152
+ + `${super.toString(indent)} index node inode:\n${this._inode.toString(indent + 1)}`;
153
+ }
154
+ _compileAccess() {
155
+ if (this._type) {
156
+ return;
157
+ }
158
+ const receiverType = this._operator.type.functionAtomArgType(0) ?? Type.Any;
159
+ this._subnode = this._subnode.compile(receiverType);
160
+ const compositeType = this._subnode.type;
161
+ const mandatoryType = compositeType.toMandatory();
162
+ let indexType = this._operator.type.functionAtomArgType(1) ?? Type.Any;
163
+ if (!mandatoryType.isAny) {
164
+ if (mandatoryType.isArray) {
165
+ indexType = Type.Integer;
166
+ }
167
+ else if (mandatoryType.isObject) {
168
+ indexType = Type.String;
169
+ }
170
+ }
171
+ this._inode = this._inode.compile(indexType);
172
+ if (this._inode.type.isNever) {
173
+ this._inode.throwError("index must produce a value");
174
+ }
175
+ const index = this._inode instanceof ConstantNode ? this._inode.value : undefined;
176
+ if (compositeType.isNever) {
177
+ this._type = Type.Never;
178
+ }
179
+ else if (this._inode.type.isInteger) {
180
+ this._type = compositeType.arrayAtomValType(typeof index === "bigint" ? Number(index) : undefined);
181
+ }
182
+ else if (this._inode.type.isString) {
183
+ this._type = compositeType.objectAtomValType(typeof index === "string" ? index : undefined);
184
+ }
185
+ else {
186
+ this._type = Type.Any;
187
+ }
188
+ }
189
+ }
@@ -1,14 +1,17 @@
1
- import { Node } from "../Node.js";
2
- import { ScriptSpan } from "../ScriptSpan.js";
1
+ import { Node } from "./Node.js";
2
+ import { ParserSpan } from "../ParserSpan.js";
3
3
  import { Value } from "../Value.js";
4
4
  import { Type } from "../Type.js";
5
5
  import { CallFrame } from "../CallFrame.js";
6
6
  export declare class ArrayNode extends Node {
7
7
  protected _subnodes: Node[];
8
+ protected _uniform: boolean;
8
9
  protected _type: Type;
9
- constructor(span: ScriptSpan, _subnodes: Node[]);
10
+ constructor(span: ParserSpan, subnodes: Node[], uniform?: boolean);
10
11
  get type(): Type;
11
- compile(type: Type): Node;
12
+ satisfies(type: Type): boolean;
13
+ compile(type?: Type): Node;
12
14
  evaluate(frame: CallFrame): Value;
15
+ get constant(): boolean;
13
16
  toString(ident?: number): string;
14
17
  }
@@ -1,31 +1,42 @@
1
- import { Node } from "../Node.js";
1
+ import { Node } from "./Node.js";
2
2
  import { Type } from "../Type.js";
3
3
  export class ArrayNode extends Node {
4
4
  _subnodes;
5
+ _uniform;
5
6
  _type;
6
- constructor(span, _subnodes) {
7
+ constructor(span, subnodes, uniform = false) {
7
8
  super(span);
8
- this._subnodes = _subnodes;
9
- this._type = Type.arrayType(_subnodes.map((i) => i.type));
9
+ this._subnodes = subnodes;
10
+ this._uniform = uniform;
11
+ const types = subnodes.map((i) => i.type);
12
+ this._type = Type.arrayType(uniform ? Type.union(...types) : types);
10
13
  }
11
14
  get type() {
12
15
  return this._type;
13
16
  }
14
- compile(type) {
17
+ satisfies(type) {
18
+ return this.type.isNever || super.satisfies(type) &&
19
+ this._subnodes.every((node, index) => node.satisfies(type.arrayAtomValType(index)));
20
+ }
21
+ compile(type = Type.Any) {
22
+ const valTypes = [];
23
+ let never = false;
15
24
  for (let i = 0; i < this._subnodes.length; ++i) {
16
- const valType = type.arrayAtomValType(i);
17
- this._subnodes[i] = this._subnodes[i].compile(valType);
25
+ this._subnodes[i] = this._subnodes[i].compile(type.arrayAtomValType(i));
26
+ never ||= this._subnodes[i].type.isNever;
27
+ valTypes.push(this._subnodes[i].type);
18
28
  }
19
- this._type = Type.arrayType(this._subnodes.map((node) => node.type));
20
- this._type = this.reduceType(type);
21
- return this;
29
+ this._type = never
30
+ ? Type.Never
31
+ : Type.arrayType(this._uniform ? Type.union(...valTypes) : valTypes);
32
+ return super.compile(type);
22
33
  }
23
34
  evaluate(frame) {
24
- const result = [];
25
- for (const subnode of this._subnodes) {
26
- result.push(subnode.evaluate(frame));
27
- }
28
- return result;
35
+ const result = this._subnodes.map((node) => node.evaluate(frame));
36
+ return frame.define(result, this.type);
37
+ }
38
+ get constant() {
39
+ return this._subnodes.every((node) => node.constant);
29
40
  }
30
41
  toString(ident = 0) {
31
42
  const subnodes = this._subnodes.map((s) => s.toString(ident + 1)).join("\n");
@@ -0,0 +1,16 @@
1
+ import { Node } from "./Node.js";
2
+ import { Type } from "../Type.js";
3
+ import { Value } from "../Value.js";
4
+ import { CallFrame } from "../CallFrame.js";
5
+ export interface AssignmentResolver {
6
+ readonly type?: Type;
7
+ set: (value: Value) => Value;
8
+ get: () => Value;
9
+ }
10
+ export declare abstract class AssignableNode extends Node {
11
+ abstract get assignable(): boolean;
12
+ get optionalAssignment(): boolean;
13
+ abstract compileAssignment(type: Type): AssignableNode;
14
+ abstract resolver(frame: CallFrame): AssignmentResolver | undefined;
15
+ reduceAssignmentType(type: Type): Type | undefined;
16
+ }
@@ -0,0 +1,14 @@
1
+ import { Node } from "./Node.js";
2
+ export class AssignableNode extends Node {
3
+ get optionalAssignment() {
4
+ return false;
5
+ }
6
+ reduceAssignmentType(type) {
7
+ const targetType = this.type;
8
+ if (!targetType.accepts(type)) {
9
+ return undefined;
10
+ }
11
+ const compiledType = targetType.reduce(type);
12
+ return compiledType?.accepts(type) ? compiledType : targetType;
13
+ }
14
+ }
@@ -0,0 +1,20 @@
1
+ import { Node } from "./Node.js";
2
+ import { InvocationNode } from "./InvocationNode.js";
3
+ import { AssignableNode } from "./AssignableNode.js";
4
+ import { Constant } from "../Constant.js";
5
+ import { ParserSpan } from "../ParserSpan.js";
6
+ import { Value } from "../Value.js";
7
+ import { Type } from "../Type.js";
8
+ import { CallFrame } from "../CallFrame.js";
9
+ export declare class AssignmentNode extends InvocationNode {
10
+ protected _anode: AssignableNode;
11
+ protected _subnode: Node;
12
+ protected readonly _operator?: Constant;
13
+ private _type?;
14
+ constructor(span: ParserSpan, anode: AssignableNode, subnode: Node, operator?: Constant);
15
+ get type(): Type;
16
+ satisfies(type: Type): boolean;
17
+ compile(type?: Type): Node;
18
+ evaluate(frame: CallFrame): Value;
19
+ toString(ident?: number): string;
20
+ }