@jplorg/jpl 1.5.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. package/dist/esm/main.js +3474 -0
  2. package/dist/types/applyDefaults.d.ts +2 -0
  3. package/dist/types/builtins/funcContains.d.ts +3 -0
  4. package/dist/types/builtins/funcEndsWith.d.ts +3 -0
  5. package/dist/types/builtins/funcError.d.ts +3 -0
  6. package/dist/types/builtins/funcFromJSON.d.ts +3 -0
  7. package/dist/types/builtins/funcHas.d.ts +3 -0
  8. package/dist/types/builtins/funcIn.d.ts +3 -0
  9. package/dist/types/builtins/funcKeys.d.ts +3 -0
  10. package/dist/types/builtins/funcLength.d.ts +3 -0
  11. package/dist/types/builtins/funcNow.d.ts +3 -0
  12. package/dist/types/builtins/funcStartsWith.d.ts +3 -0
  13. package/dist/types/builtins/funcToJSON.d.ts +3 -0
  14. package/dist/types/builtins/funcToLowerCase.d.ts +3 -0
  15. package/dist/types/builtins/funcToNumber.d.ts +3 -0
  16. package/dist/types/builtins/funcToString.d.ts +3 -0
  17. package/dist/types/builtins/funcToUpperCase.d.ts +3 -0
  18. package/dist/types/builtins/funcTrim.d.ts +3 -0
  19. package/dist/types/builtins/funcTrimEnd.d.ts +3 -0
  20. package/dist/types/builtins/funcTrimStart.d.ts +3 -0
  21. package/dist/types/builtins/funcType.d.ts +3 -0
  22. package/dist/types/builtins/funcVoid.d.ts +3 -0
  23. package/dist/types/builtins/index.d.ts +2 -0
  24. package/dist/types/builtins/internals.d.ts +1 -0
  25. package/dist/types/builtins/math.d.ts +17 -0
  26. package/dist/types/createSingleton.d.ts +1 -0
  27. package/dist/types/interpreter/index.d.ts +21 -0
  28. package/dist/types/interpreter/parse.d.ts +194 -0
  29. package/{src/interpreter/parseFunction.js → dist/types/interpreter/parseFunction.d.ts} +2 -10
  30. package/dist/types/interpreter/system.d.ts +3 -0
  31. package/dist/types/interpreter/util.d.ts +89 -0
  32. package/dist/types/library/apply.d.ts +32 -0
  33. package/dist/types/library/definition.d.ts +79 -0
  34. package/dist/types/library/errors/adaptErrors.d.ts +6 -0
  35. package/dist/types/library/errors/enclosure.d.ts +6 -0
  36. package/dist/types/library/errors/error.d.ts +6 -0
  37. package/dist/types/library/errors/execution.d.ts +12 -0
  38. package/dist/types/library/errors/fatal.d.ts +4 -0
  39. package/dist/types/library/errors/runtime.d.ts +46 -0
  40. package/dist/types/library/errors/syntax.d.ts +7 -0
  41. package/{src/library/functions.js → dist/types/library/functions.d.ts} +9 -30
  42. package/dist/types/library/index.d.ts +18 -0
  43. package/dist/types/library/mux.d.ts +19 -0
  44. package/{src/library/ops/op.js → dist/types/library/ops/op.d.ts} +25 -49
  45. package/{src/library/ops/opa.js → dist/types/library/ops/opa.d.ts} +4 -7
  46. package/{src/library/ops/opc.js → dist/types/library/ops/opc.d.ts} +6 -11
  47. package/{src/library/ops/opm.js → dist/types/library/ops/opm.d.ts} +5 -9
  48. package/{src/library/ops/opu.js → dist/types/library/ops/opu.d.ts} +8 -15
  49. package/dist/types/library/runtimeScope.d.ts +23 -0
  50. package/dist/types/library/runtimeSignal.d.ts +25 -0
  51. package/dist/types/library/types.d.ts +97 -0
  52. package/dist/types/main.d.ts +19 -0
  53. package/dist/types/program/handler.d.ts +12 -0
  54. package/dist/types/program/index.d.ts +40 -0
  55. package/dist/types/program/ops/index.d.ts +5 -0
  56. package/dist/types/program/ops/opAccess/index.d.ts +11 -0
  57. package/dist/types/program/ops/opAccess/opaField.d.ts +11 -0
  58. package/dist/types/program/ops/opAccess/opaFunction.d.ts +11 -0
  59. package/dist/types/program/ops/opAccess/opaIter.d.ts +11 -0
  60. package/dist/types/program/ops/opAccess/opaSlice.d.ts +11 -0
  61. package/dist/types/program/ops/opAnd.d.ts +11 -0
  62. package/dist/types/program/ops/opArrayConstructor.d.ts +11 -0
  63. package/dist/types/program/ops/opAssignment/index.d.ts +11 -0
  64. package/dist/types/program/ops/opAssignment/opaAssignField.d.ts +11 -0
  65. package/dist/types/program/ops/opAssignment/opaAssignIter.d.ts +11 -0
  66. package/dist/types/program/ops/opAssignment/opaAssignSlice.d.ts +11 -0
  67. package/dist/types/program/ops/opAssignment/opuAddition.d.ts +11 -0
  68. package/dist/types/program/ops/opAssignment/opuDivision.d.ts +11 -0
  69. package/dist/types/program/ops/opAssignment/opuMultiplication.d.ts +11 -0
  70. package/dist/types/program/ops/opAssignment/opuNullCoalescence.d.ts +11 -0
  71. package/dist/types/program/ops/opAssignment/opuRemainder.d.ts +11 -0
  72. package/dist/types/program/ops/opAssignment/opuSet.d.ts +11 -0
  73. package/dist/types/program/ops/opAssignment/opuSubtraction.d.ts +11 -0
  74. package/dist/types/program/ops/opAssignment/opuUpdate.d.ts +11 -0
  75. package/dist/types/program/ops/opCalculation/index.d.ts +11 -0
  76. package/dist/types/program/ops/opCalculation/opmAddition.d.ts +11 -0
  77. package/dist/types/program/ops/opCalculation/opmDivision.d.ts +11 -0
  78. package/dist/types/program/ops/opCalculation/opmMultiplication.d.ts +11 -0
  79. package/dist/types/program/ops/opCalculation/opmRemainder.d.ts +11 -0
  80. package/dist/types/program/ops/opCalculation/opmSubtraction.d.ts +11 -0
  81. package/dist/types/program/ops/opComparison/index.d.ts +11 -0
  82. package/dist/types/program/ops/opComparison/opcEqual.d.ts +11 -0
  83. package/dist/types/program/ops/opComparison/opcGreater.d.ts +11 -0
  84. package/dist/types/program/ops/opComparison/opcGreaterEqual.d.ts +11 -0
  85. package/dist/types/program/ops/opComparison/opcLess.d.ts +11 -0
  86. package/dist/types/program/ops/opComparison/opcLessEqual.d.ts +11 -0
  87. package/dist/types/program/ops/opComparison/opcUnequal.d.ts +11 -0
  88. package/dist/types/program/ops/opConstant.d.ts +11 -0
  89. package/dist/types/program/ops/opConstantFalse.d.ts +11 -0
  90. package/dist/types/program/ops/opConstantNull.d.ts +11 -0
  91. package/dist/types/program/ops/opConstantTrue.d.ts +11 -0
  92. package/dist/types/program/ops/opFunctionDefinition.d.ts +11 -0
  93. package/dist/types/program/ops/opIf.d.ts +11 -0
  94. package/dist/types/program/ops/opInterpolatedString.d.ts +11 -0
  95. package/dist/types/program/ops/opNegation.d.ts +11 -0
  96. package/dist/types/program/ops/opNot.d.ts +11 -0
  97. package/dist/types/program/ops/opNullCoalescence.d.ts +11 -0
  98. package/dist/types/program/ops/opNumber.d.ts +11 -0
  99. package/dist/types/program/ops/opObjectConstructor.d.ts +11 -0
  100. package/dist/types/program/ops/opOr.d.ts +11 -0
  101. package/dist/types/program/ops/opOutputConcat.d.ts +11 -0
  102. package/dist/types/program/ops/opString.d.ts +11 -0
  103. package/dist/types/program/ops/opTry.d.ts +11 -0
  104. package/dist/types/program/ops/opVariable.d.ts +11 -0
  105. package/dist/types/program/ops/opVariableDefinition.d.ts +11 -0
  106. package/dist/types/program/ops/opVoid.d.ts +11 -0
  107. package/dist/types/program/ops/utils.d.ts +5 -0
  108. package/dist/types/program/params.d.ts +68 -0
  109. package/dist/types/runtime/index.d.ts +83 -0
  110. package/package.json +66 -49
  111. package/{repl.js → repl.ts} +85 -39
  112. package/lib/applyDefaults.js +0 -34
  113. package/lib/builtins/funcContains.js +0 -25
  114. package/lib/builtins/funcEndsWith.js +0 -21
  115. package/lib/builtins/funcError.js +0 -11
  116. package/lib/builtins/funcFromJSON.js +0 -26
  117. package/lib/builtins/funcHas.js +0 -24
  118. package/lib/builtins/funcIn.js +0 -24
  119. package/lib/builtins/funcKeys.js +0 -20
  120. package/lib/builtins/funcLength.js +0 -24
  121. package/lib/builtins/funcNow.js +0 -10
  122. package/lib/builtins/funcStartsWith.js +0 -21
  123. package/lib/builtins/funcToJSON.js +0 -10
  124. package/lib/builtins/funcToLowerCase.js +0 -17
  125. package/lib/builtins/funcToNumber.js +0 -26
  126. package/lib/builtins/funcToString.js +0 -10
  127. package/lib/builtins/funcToUpperCase.js +0 -17
  128. package/lib/builtins/funcTrim.js +0 -17
  129. package/lib/builtins/funcTrimEnd.js +0 -17
  130. package/lib/builtins/funcTrimStart.js +0 -17
  131. package/lib/builtins/funcType.js +0 -10
  132. package/lib/builtins/funcVoid.js +0 -10
  133. package/lib/builtins/index.js +0 -205
  134. package/lib/builtins/internals.js +0 -8
  135. package/lib/builtins/math.js +0 -40
  136. package/lib/builtins/native.js +0 -180
  137. package/lib/createSingleton.js +0 -14
  138. package/lib/index.js +0 -79
  139. package/lib/interpreter/index.js +0 -56
  140. package/lib/interpreter/parse.js +0 -2377
  141. package/lib/interpreter/parseFunction.js +0 -24
  142. package/lib/interpreter/system.js +0 -10
  143. package/lib/interpreter/util.js +0 -349
  144. package/lib/library/apply.js +0 -142
  145. package/lib/library/definition.js +0 -9
  146. package/lib/library/errors/adaptErrors.js +0 -34
  147. package/lib/library/errors/enclosure.js +0 -16
  148. package/lib/library/errors/error.js +0 -18
  149. package/lib/library/errors/execution.js +0 -20
  150. package/lib/library/errors/fatal.js +0 -15
  151. package/lib/library/errors/runtime.js +0 -78
  152. package/lib/library/errors/syntax.js +0 -17
  153. package/lib/library/functions.js +0 -82
  154. package/lib/library/index.js +0 -335
  155. package/lib/library/mux.js +0 -106
  156. package/lib/library/ops/index.js +0 -60
  157. package/lib/library/ops/op.js +0 -180
  158. package/lib/library/ops/opa.js +0 -41
  159. package/lib/library/ops/opc.js +0 -59
  160. package/lib/library/ops/opm.js +0 -50
  161. package/lib/library/ops/opu.js +0 -77
  162. package/lib/library/runtimeScope.js +0 -38
  163. package/lib/library/runtimeSignal.js +0 -72
  164. package/lib/library/types.js +0 -304
  165. package/lib/program/index.js +0 -101
  166. package/lib/program/ops/index.js +0 -61
  167. package/lib/program/ops/opAccess/index.js +0 -55
  168. package/lib/program/ops/opAccess/opaField.js +0 -50
  169. package/lib/program/ops/opAccess/opaFunction.js +0 -50
  170. package/lib/program/ops/opAccess/opaIter.js +0 -31
  171. package/lib/program/ops/opAccess/opaSlice.js +0 -44
  172. package/lib/program/ops/opAnd.js +0 -30
  173. package/lib/program/ops/opArrayConstructor.js +0 -20
  174. package/lib/program/ops/opAssignment/index.js +0 -90
  175. package/lib/program/ops/opAssignment/opaAssignField.js +0 -125
  176. package/lib/program/ops/opAssignment/opaAssignIter.js +0 -69
  177. package/lib/program/ops/opAssignment/opaAssignSlice.js +0 -99
  178. package/lib/program/ops/opAssignment/opuAddition.js +0 -31
  179. package/lib/program/ops/opAssignment/opuDivision.js +0 -31
  180. package/lib/program/ops/opAssignment/opuMultiplication.js +0 -31
  181. package/lib/program/ops/opAssignment/opuNullCoalescence.js +0 -25
  182. package/lib/program/ops/opAssignment/opuRemainder.js +0 -31
  183. package/lib/program/ops/opAssignment/opuSet.js +0 -19
  184. package/lib/program/ops/opAssignment/opuSubtraction.js +0 -31
  185. package/lib/program/ops/opAssignment/opuUpdate.js +0 -19
  186. package/lib/program/ops/opCalculation/index.js +0 -57
  187. package/lib/program/ops/opCalculation/opmAddition.js +0 -49
  188. package/lib/program/ops/opCalculation/opmDivision.js +0 -42
  189. package/lib/program/ops/opCalculation/opmMultiplication.js +0 -40
  190. package/lib/program/ops/opCalculation/opmRemainder.js +0 -34
  191. package/lib/program/ops/opCalculation/opmSubtraction.js +0 -53
  192. package/lib/program/ops/opComparison/index.js +0 -59
  193. package/lib/program/ops/opComparison/opcEqual.js +0 -19
  194. package/lib/program/ops/opComparison/opcGreater.js +0 -19
  195. package/lib/program/ops/opComparison/opcGreaterEqual.js +0 -19
  196. package/lib/program/ops/opComparison/opcLess.js +0 -19
  197. package/lib/program/ops/opComparison/opcLessEqual.js +0 -19
  198. package/lib/program/ops/opComparison/opcUnequal.js +0 -19
  199. package/lib/program/ops/opConstant.js +0 -18
  200. package/lib/program/ops/opConstantFalse.js +0 -16
  201. package/lib/program/ops/opConstantNull.js +0 -16
  202. package/lib/program/ops/opConstantTrue.js +0 -16
  203. package/lib/program/ops/opFunctionDefinition.js +0 -21
  204. package/lib/program/ops/opIf.js +0 -38
  205. package/lib/program/ops/opInterpolatedString.js +0 -24
  206. package/lib/program/ops/opNegation.js +0 -25
  207. package/lib/program/ops/opNot.js +0 -16
  208. package/lib/program/ops/opNullCoalescence.js +0 -34
  209. package/lib/program/ops/opNumber.js +0 -18
  210. package/lib/program/ops/opObjectConstructor.js +0 -37
  211. package/lib/program/ops/opOr.js +0 -30
  212. package/lib/program/ops/opOutputConcat.js +0 -19
  213. package/lib/program/ops/opString.js +0 -18
  214. package/lib/program/ops/opTry.js +0 -37
  215. package/lib/program/ops/opVariable.js +0 -20
  216. package/lib/program/ops/opVariableDefinition.js +0 -24
  217. package/lib/program/ops/opVoid.js +0 -16
  218. package/lib/program/ops/utils.js +0 -35
  219. package/lib/runtime/index.js +0 -258
  220. package/src/applyDefaults.js +0 -35
  221. package/src/builtins/funcContains.js +0 -27
  222. package/src/builtins/funcEndsWith.js +0 -21
  223. package/src/builtins/funcError.js +0 -7
  224. package/src/builtins/funcFromJSON.js +0 -24
  225. package/src/builtins/funcHas.js +0 -25
  226. package/src/builtins/funcIn.js +0 -25
  227. package/src/builtins/funcKeys.js +0 -20
  228. package/src/builtins/funcLength.js +0 -26
  229. package/src/builtins/funcNow.js +0 -5
  230. package/src/builtins/funcStartsWith.js +0 -21
  231. package/src/builtins/funcToJSON.js +0 -5
  232. package/src/builtins/funcToLowerCase.js +0 -20
  233. package/src/builtins/funcToNumber.js +0 -25
  234. package/src/builtins/funcToString.js +0 -5
  235. package/src/builtins/funcToUpperCase.js +0 -20
  236. package/src/builtins/funcTrim.js +0 -16
  237. package/src/builtins/funcTrimEnd.js +0 -16
  238. package/src/builtins/funcTrimStart.js +0 -16
  239. package/src/builtins/funcType.js +0 -5
  240. package/src/builtins/funcVoid.js +0 -5
  241. package/src/builtins/index.js +0 -193
  242. package/src/builtins/internals.js +0 -9
  243. package/src/builtins/math.js +0 -44
  244. package/src/createSingleton.js +0 -9
  245. package/src/index.js +0 -44
  246. package/src/interpreter/index.js +0 -48
  247. package/src/interpreter/parse.js +0 -1473
  248. package/src/interpreter/system.js +0 -5
  249. package/src/interpreter/util.js +0 -237
  250. package/src/library/apply.js +0 -135
  251. package/src/library/definition.js +0 -3
  252. package/src/library/errors/adaptErrors.js +0 -28
  253. package/src/library/errors/enclosure.js +0 -11
  254. package/src/library/errors/error.js +0 -14
  255. package/src/library/errors/execution.js +0 -15
  256. package/src/library/errors/fatal.js +0 -10
  257. package/src/library/errors/runtime.js +0 -71
  258. package/src/library/errors/syntax.js +0 -12
  259. package/src/library/index.js +0 -41
  260. package/src/library/mux.js +0 -98
  261. package/src/library/runtimeScope.js +0 -35
  262. package/src/library/runtimeSignal.js +0 -67
  263. package/src/library/types.js +0 -299
  264. package/src/program/index.js +0 -114
  265. package/src/program/ops/index.js +0 -82
  266. package/src/program/ops/opAccess/index.js +0 -55
  267. package/src/program/ops/opAccess/opaField.js +0 -58
  268. package/src/program/ops/opAccess/opaFunction.js +0 -52
  269. package/src/program/ops/opAccess/opaIter.js +0 -31
  270. package/src/program/ops/opAccess/opaSlice.js +0 -58
  271. package/src/program/ops/opAnd.js +0 -32
  272. package/src/program/ops/opArrayConstructor.js +0 -16
  273. package/src/program/ops/opAssignment/index.js +0 -102
  274. package/src/program/ops/opAssignment/opaAssignField.js +0 -156
  275. package/src/program/ops/opAssignment/opaAssignIter.js +0 -74
  276. package/src/program/ops/opAssignment/opaAssignSlice.js +0 -157
  277. package/src/program/ops/opAssignment/opuAddition.js +0 -29
  278. package/src/program/ops/opAssignment/opuDivision.js +0 -29
  279. package/src/program/ops/opAssignment/opuMultiplication.js +0 -29
  280. package/src/program/ops/opAssignment/opuNullCoalescence.js +0 -26
  281. package/src/program/ops/opAssignment/opuRemainder.js +0 -29
  282. package/src/program/ops/opAssignment/opuSet.js +0 -15
  283. package/src/program/ops/opAssignment/opuSubtraction.js +0 -29
  284. package/src/program/ops/opAssignment/opuUpdate.js +0 -15
  285. package/src/program/ops/opCalculation/index.js +0 -64
  286. package/src/program/ops/opCalculation/opmAddition.js +0 -63
  287. package/src/program/ops/opCalculation/opmDivision.js +0 -47
  288. package/src/program/ops/opCalculation/opmMultiplication.js +0 -52
  289. package/src/program/ops/opCalculation/opmRemainder.js +0 -49
  290. package/src/program/ops/opCalculation/opmSubtraction.js +0 -72
  291. package/src/program/ops/opComparison/index.js +0 -67
  292. package/src/program/ops/opComparison/opcEqual.js +0 -17
  293. package/src/program/ops/opComparison/opcGreater.js +0 -17
  294. package/src/program/ops/opComparison/opcGreaterEqual.js +0 -17
  295. package/src/program/ops/opComparison/opcLess.js +0 -17
  296. package/src/program/ops/opComparison/opcLessEqual.js +0 -17
  297. package/src/program/ops/opComparison/opcUnequal.js +0 -17
  298. package/src/program/ops/opConstant.js +0 -13
  299. package/src/program/ops/opConstantFalse.js +0 -11
  300. package/src/program/ops/opConstantNull.js +0 -11
  301. package/src/program/ops/opConstantTrue.js +0 -11
  302. package/src/program/ops/opFunctionDefinition.js +0 -17
  303. package/src/program/ops/opIf.js +0 -44
  304. package/src/program/ops/opInterpolatedString.js +0 -27
  305. package/src/program/ops/opNegation.js +0 -26
  306. package/src/program/ops/opNot.js +0 -11
  307. package/src/program/ops/opNullCoalescence.js +0 -36
  308. package/src/program/ops/opNumber.js +0 -13
  309. package/src/program/ops/opObjectConstructor.js +0 -40
  310. package/src/program/ops/opOr.js +0 -32
  311. package/src/program/ops/opOutputConcat.js +0 -17
  312. package/src/program/ops/opString.js +0 -13
  313. package/src/program/ops/opTry.js +0 -38
  314. package/src/program/ops/opVariable.js +0 -17
  315. package/src/program/ops/opVariableDefinition.js +0 -18
  316. package/src/program/ops/opVoid.js +0 -11
  317. package/src/program/ops/utils.js +0 -19
  318. package/src/runtime/index.js +0 -309
  319. /package/{src/builtins/native.js → dist/types/builtins/native.d.ts} +0 -0
  320. /package/{src/library/ops/index.js → dist/types/library/ops/index.d.ts} +0 -0
@@ -0,0 +1,3474 @@
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.defineProperty, t = (t, n) => {
3
+ let r = {};
4
+ for (var i in t) e(r, i, {
5
+ get: t[i],
6
+ enumerable: !0
7
+ });
8
+ return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
+ };
10
+ //#endregion
11
+ //#region lib/createSingleton.ts
12
+ function n(e) {
13
+ let t;
14
+ return () => (t ??= e(), t);
15
+ }
16
+ //#endregion
17
+ //#region lib/applyDefaults.ts
18
+ function r(e, t, ...n) {
19
+ let r = (e, t, n) => {
20
+ if (Array.isArray(e)) return e;
21
+ if (typeof e == "object") {
22
+ if (e === null || Array.isArray(t) || typeof t != "object" || !t) return e;
23
+ let i = { ...e }, a = n.some((e) => e.length === 0);
24
+ return Object.keys({
25
+ ...e,
26
+ ...t
27
+ }).forEach((e) => {
28
+ a ? Object.hasOwn(i, e) || (i[e] = t[e]) : i[e] = r(i[e], t[e], n.filter((t) => t[0] === e).map((e) => e.slice(1))), i[e] === void 0 && delete i[e];
29
+ }), i;
30
+ }
31
+ return e === void 0 ? t : e;
32
+ };
33
+ return r(e, t, n.map((e) => typeof e == "string" ? e.split(".") : e));
34
+ }
35
+ //#endregion
36
+ //#region lib/library/apply.ts
37
+ function i(e, t) {
38
+ let n = e, r = !0;
39
+ return t.forEach((e) => {
40
+ let [t, i] = e;
41
+ if (e.length === 1) {
42
+ if (!Object.hasOwn(n, t)) return;
43
+ if (r) {
44
+ let { [t]: e, ...i } = n;
45
+ n = i, r = !1;
46
+ } else delete n[t];
47
+ return;
48
+ }
49
+ Object.hasOwn(n, t) && n[t] === i || (r ? (n = {
50
+ ...n,
51
+ [t]: i
52
+ }, r = !1) : n[t] = i);
53
+ }), n;
54
+ }
55
+ function a(e, t, n = null) {
56
+ let r = e, i = !0;
57
+ return t.forEach((e) => {
58
+ let [t, a] = e, o = t >= 0 ? t : r.length + t;
59
+ if (!(o >= 0 && o < r.length && r[o] === a)) {
60
+ if (t >= 0) {
61
+ let e = o + 1 - r.length;
62
+ e > 0 && (r = [...r, ...Array(e).fill(n)], i = !1);
63
+ } else {
64
+ let e = -o;
65
+ e > 0 && (r = [...Array(e).fill(n), ...r], i = !1, o = 0);
66
+ }
67
+ i &&= (r = [...r], !1), r[o] = a;
68
+ }
69
+ }), r;
70
+ }
71
+ function o(e, t) {
72
+ let n = t.length, r = 1, i = t.map((e) => {
73
+ let t = e.length;
74
+ return r *= t, [
75
+ t,
76
+ 0,
77
+ e
78
+ ];
79
+ });
80
+ if (r === 0) return [];
81
+ let a = e, o = e.length;
82
+ o !== n && (a = o > n ? a.slice(0, n) : [...a, ...Array(n - o)]);
83
+ let s = Array(r), c = 0;
84
+ for (;;) {
85
+ let e = a, t = !0;
86
+ if (i.forEach(([, n, r], i) => {
87
+ let a = r[n];
88
+ e[i] !== a && (t &&= (e = [...e], !1), e[i] = a);
89
+ }), s[c] = e, c += 1, c >= r) break;
90
+ for (let e = n - 1; e >= 0; --e) {
91
+ let t = i[e], [n, r] = t, a = r + 1;
92
+ if (a < n) {
93
+ t[1] = a;
94
+ break;
95
+ }
96
+ t[1] = 0;
97
+ }
98
+ }
99
+ return s;
100
+ }
101
+ //#endregion
102
+ //#region lib/library/ops/op.ts
103
+ var s = "$.", c = "and", l = "[]", u = "$=", d = "clc", f = "cmp", p = "cnt", ee = "fls", te = "nul", ne = "tru", re = "fun", ie = "if", ae = "\"$\"", oe = "neg", se = "not", ce = "??", le = "nbr", ue = "{}", de = "or", fe = ",", pe = "\"\"", me = "try", he = "var", ge = "va=", _e = "vod", ve = "$.$", ye = "$()", be = "$[]", xe = "[:]", Se = "==", Ce = ">", we = ">=", Te = "<", Ee = "<=", De = "!=", Oe = "+", ke = "/", Ae = "*", je = "%", Me = "-", Ne = "+=", Pe = "/=", Fe = "*=", Ie = "?=", Le = "%=", Re = "=", ze = "-=", Be = "|=", Ve = 1, He = 0, m = "1.0", h = class extends Error {
104
+ static is(e) {
105
+ return e instanceof this;
106
+ }
107
+ constructor(e, t = "JPLError") {
108
+ super(e), this.name = t;
109
+ }
110
+ }, g = class extends h {
111
+ #e;
112
+ constructor(e, t = "JPLExecutionError") {
113
+ super(e, t), this.#e = typeof e == "string" && e ? e : null;
114
+ }
115
+ set value(e) {
116
+ this.#e = e;
117
+ }
118
+ get value() {
119
+ return this.#e;
120
+ }
121
+ };
122
+ //#endregion
123
+ //#region lib/library/errors/adaptErrors.ts
124
+ function Ue(e) {
125
+ try {
126
+ return e();
127
+ } catch (e) {
128
+ throw _(e);
129
+ }
130
+ }
131
+ async function We(e) {
132
+ try {
133
+ return await e();
134
+ } catch (e) {
135
+ throw _(e);
136
+ }
137
+ }
138
+ function _(e) {
139
+ return h.is(e) ? e : new g(e?.message);
140
+ }
141
+ //#endregion
142
+ //#region lib/library/errors/enclosure.ts
143
+ var v = class extends h {
144
+ inner;
145
+ constructor(e) {
146
+ super(e?.toString(), "JPLErrorEnclosure"), this.inner = e;
147
+ }
148
+ }, y = class extends h {
149
+ constructor(e) {
150
+ super(e, "JPLFatalError");
151
+ }
152
+ }, b = class {
153
+ static is(e) {
154
+ return e instanceof this;
155
+ }
156
+ #e;
157
+ constructor(e) {
158
+ this.#e = Ge(e);
159
+ }
160
+ get value() {
161
+ return this.#e;
162
+ }
163
+ get json() {
164
+ return this.#e;
165
+ }
166
+ async alter(e) {
167
+ return x(await e(this.value));
168
+ }
169
+ toJSON() {
170
+ try {
171
+ return this.json;
172
+ } catch (e) {
173
+ throw _(e);
174
+ }
175
+ }
176
+ };
177
+ function Ge(e) {
178
+ return b.is(e) ? e.value : x(e);
179
+ }
180
+ function x(e) {
181
+ return E(e, void 0, Xe);
182
+ }
183
+ function S(e) {
184
+ return b.is(e) ? Ue(() => e.value) : e;
185
+ }
186
+ var Ke = [
187
+ "null",
188
+ "function",
189
+ "boolean",
190
+ "number",
191
+ "string",
192
+ "array",
193
+ "object"
194
+ ];
195
+ function qe(e) {
196
+ let t = S(e);
197
+ if (t === null) return "null";
198
+ if (Array.isArray(t)) return "array";
199
+ let n = typeof t;
200
+ switch (n) {
201
+ case "function":
202
+ case "boolean":
203
+ case "number":
204
+ case "string":
205
+ case "object": return n;
206
+ default: throw new y(`invalid type ${n} (${e})`);
207
+ }
208
+ }
209
+ function Je(e, t) {
210
+ if (b.is(e)) throw new y(w("unexpected type: JPLTypes (%*<100v) are not allowed here", e));
211
+ let n = qe(e);
212
+ if (n !== t) throw new y(w("unexpected type: %s (%*<100v) cannot be used as %s", n, e, t));
213
+ return e;
214
+ }
215
+ function C(e, t, n) {
216
+ let r = n ? E(e, (e, t) => typeof S(t) == "function" ? "<function>" : t) : E(e);
217
+ return t && typeof r == "string" ? r : JSON.stringify(r);
218
+ }
219
+ function w(e, ...t) {
220
+ let n = 0;
221
+ return T(e).replace(/%([*\-<]+)?([1-9][0-9]*)?(.)/g, (e, r, i, a) => {
222
+ switch (a) {
223
+ case "%": return "%";
224
+ default:
225
+ }
226
+ let o = t[n] ?? null;
227
+ n += 1;
228
+ let s;
229
+ switch (a) {
230
+ case "s":
231
+ s = T(o);
232
+ break;
233
+ case "v":
234
+ s = Ye(o);
235
+ break;
236
+ default: throw new y(`format ${e} has unknown verb ${a}`);
237
+ }
238
+ let c = !0, l = !1, u = !1;
239
+ [...r ?? []].forEach((t) => {
240
+ switch (t) {
241
+ case "*":
242
+ c = !1;
243
+ break;
244
+ case "-":
245
+ l = !0;
246
+ break;
247
+ case "<":
248
+ u = !0;
249
+ break;
250
+ default: throw new y(`format ${e} has unknown flag ${t}`);
251
+ }
252
+ });
253
+ let d = +(i ?? 0);
254
+ if (d > 0) {
255
+ let e = [...s].length;
256
+ if (c && e < d) {
257
+ let t = " ".repeat(d - e);
258
+ s = l ? `${s}${t}` : `${t}${s}`;
259
+ } else u && e > d && (s = `${s.substring(0, d - 1)}…`);
260
+ }
261
+ return s;
262
+ });
263
+ }
264
+ function T(e) {
265
+ return C(e, !0, !0);
266
+ }
267
+ function Ye(e) {
268
+ return C(e, !1, !0);
269
+ }
270
+ function E(e, t, n = Qe) {
271
+ let r = (e, i) => {
272
+ let a = i;
273
+ return t && (a = t(e ?? "", a)), n(e, a, r);
274
+ };
275
+ return r(null, e);
276
+ }
277
+ function Xe(e, t, n) {
278
+ return b.is(t) || typeof t == "function" ? t : D(e, t, n);
279
+ }
280
+ function Ze(e, t, n) {
281
+ let r = t;
282
+ return b.is(r) && (r = r.toJSON()), typeof r == "function" ? r : D(e, r, n);
283
+ }
284
+ function Qe(e, t, n) {
285
+ let r = t;
286
+ return b.is(r) && (r = r.toJSON()), D(e, r, n);
287
+ }
288
+ function $e(e, t, n) {
289
+ let r = t;
290
+ return typeof r?.toJSON == "function" && (r = r.toJSON()), D(e, r, n);
291
+ }
292
+ function D(e, t, n) {
293
+ let r = e == null;
294
+ switch (typeof t) {
295
+ case "string":
296
+ case "boolean": return t;
297
+ case "number": return Number.isFinite(t) ? t : null;
298
+ case "undefined":
299
+ case "function": return r ? null : void 0;
300
+ case "object": return t === null ? null : Array.isArray(t) ? a(t, Array.from(Array(t.length), (e, r) => [r, n(`${r}`, t[r]) ?? null])) : i(t, Object.entries(t).map(([e, t]) => {
301
+ let r = n(e, t);
302
+ return r === void 0 ? [e] : [e, r];
303
+ }));
304
+ default: throw new y(`unexpected ${typeof t}`);
305
+ }
306
+ }
307
+ //#endregion
308
+ //#region lib/library/errors/runtime.ts
309
+ function O(e, t) {
310
+ return t.length > 0 ? w(e, ...t) : T(e);
311
+ }
312
+ var k = class extends g {
313
+ constructor(e, ...t) {
314
+ let n = O(e, t);
315
+ super(n, "JPLRuntimeError"), this.value = t.length > 0 ? n : x(e);
316
+ }
317
+ }, A = class extends k {
318
+ constructor(e, ...t) {
319
+ super(`TypeError - ${O(e, t)}`);
320
+ }
321
+ }, et = class extends k {
322
+ constructor(e, ...t) {
323
+ super(`ReferenceError - ${O(e, t)}`);
324
+ }
325
+ }, j = class extends k {
326
+ constructor(e, ...t) {
327
+ super(`ZeroDivisionError - ${O(e, t)}`);
328
+ }
329
+ }, tt = class extends k {
330
+ constructor(e, ...t) {
331
+ super(`TypeConversionError - ${O(e, t)}`);
332
+ }
333
+ }, nt = class extends h {
334
+ src;
335
+ at;
336
+ constructor(e, t = "", n = 0) {
337
+ super(e, "JPLSyntaxError"), this.src = t, this.at = n;
338
+ }
339
+ }, rt = class e {
340
+ #e;
341
+ #t;
342
+ #n;
343
+ #r;
344
+ constructor(e) {
345
+ this.#e = e, this.#t = !1, this.#n = {}, this.#r = 0;
346
+ }
347
+ get parent() {
348
+ return this.#e;
349
+ }
350
+ get exited() {
351
+ return this.#t ||= this.parent?.exited ?? !1, this.#t;
352
+ }
353
+ checkHealth() {
354
+ if (this.exited) throw new y("execution aborted");
355
+ }
356
+ exit = () => {
357
+ this.exited || (this.#t = !0, Object.values(this.#n).forEach((e) => {
358
+ e();
359
+ }), this.#n = {});
360
+ };
361
+ subscribe = (e) => {
362
+ if (this.exited) return setTimeout(e), () => {};
363
+ let t = this.#r;
364
+ this.#r += 1, this.#n[t] = e;
365
+ let n = (this.parent?.subscribe ?? (() => () => {}))(e);
366
+ return () => {
367
+ delete this.#n[t], n();
368
+ };
369
+ };
370
+ next = () => new e(this);
371
+ }, it = class e {
372
+ #e;
373
+ #t;
374
+ constructor(e = {}) {
375
+ this.#e = e.signal ?? new rt(), this.#t = e.vars ?? {};
376
+ }
377
+ get signal() {
378
+ return this.#e;
379
+ }
380
+ get vars() {
381
+ return this.#t;
382
+ }
383
+ next(t) {
384
+ return new e({
385
+ signal: t.signal ?? this.signal,
386
+ vars: i(this.vars, Object.entries(t.vars ?? {}))
387
+ });
388
+ }
389
+ };
390
+ //#endregion
391
+ //#region lib/library/functions.ts
392
+ function at(e, t, n, r, ...i) {
393
+ let { argNames: a, pipe: o, scope: s } = this;
394
+ return e.executeInstructions(o, [r], s.next({
395
+ signal: t,
396
+ vars: Object.fromEntries(a.map((e, t) => [e, i[t] ?? null]))
397
+ }), n);
398
+ }
399
+ function ot(e, t, n) {
400
+ return at.bind({
401
+ argNames: e,
402
+ pipe: t,
403
+ scope: n
404
+ });
405
+ }
406
+ function st(e, t, n) {
407
+ return ot(e, t, new it(n));
408
+ }
409
+ function ct(e) {
410
+ return async (t, n, r, i, ...a) => {
411
+ let o = await e(t, i, ...a);
412
+ return t.muxAll([o], r);
413
+ };
414
+ }
415
+ //#endregion
416
+ //#region lib/library/mux.ts
417
+ function lt(e, t) {
418
+ let n = e.length;
419
+ if (n === 1) {
420
+ e[0].forEach((e) => t(e));
421
+ return;
422
+ }
423
+ let r = 1, i = e.map((e) => {
424
+ let t = e?.length ?? 0;
425
+ return r *= t, [
426
+ t,
427
+ 0,
428
+ e
429
+ ];
430
+ });
431
+ if (r === 0) return;
432
+ let a = e.map(([e]) => e), o = 0;
433
+ for (; t(...a), o += 1, !(o >= r);) for (let e = n - 1; e >= 0; --e) {
434
+ let t = i[e], [n, r, o] = t, s = r + 1;
435
+ if (s < n) {
436
+ t[1] = s, a[e] = o[s];
437
+ break;
438
+ }
439
+ t[1] = 0, [a[e]] = o;
440
+ }
441
+ }
442
+ function M(e, t) {
443
+ let n = e.length;
444
+ if (n === 1) return e[0].map((e) => t(e));
445
+ let r = 1, i = e.map((e) => {
446
+ let t = e?.length ?? 0;
447
+ return r *= t, [
448
+ t,
449
+ 0,
450
+ e
451
+ ];
452
+ });
453
+ if (r === 0) return [];
454
+ let a = Array(r), o = e.map(([e]) => e), s = 0;
455
+ for (; a[s] = t(...o), s += 1, !(s >= r);) for (let e = n - 1; e >= 0; --e) {
456
+ let t = i[e], [n, r, a] = t, s = r + 1;
457
+ if (s < n) {
458
+ t[1] = s, o[e] = a[s];
459
+ break;
460
+ }
461
+ t[1] = 0, [o[e]] = a;
462
+ }
463
+ return a;
464
+ }
465
+ function N(e, t) {
466
+ return Promise.all(M(e, t));
467
+ }
468
+ async function ut(e, t) {
469
+ return dt(await N(e, t));
470
+ }
471
+ function dt(e) {
472
+ return e.length === 0 ? e : e.length === 1 ? e[0] : e.flat(1);
473
+ }
474
+ //#endregion
475
+ //#region lib/runtime/index.ts
476
+ var ft = { vars: {} };
477
+ function P(e = {}, t = {}) {
478
+ return r(e, t, "vars");
479
+ }
480
+ var pt = class {
481
+ #e;
482
+ #t;
483
+ constructor(e, t) {
484
+ this.#e = P(t?.runtime, ft), this.#t = e;
485
+ }
486
+ get options() {
487
+ return this.#e;
488
+ }
489
+ get program() {
490
+ return this.#t;
491
+ }
492
+ createScope = (e) => new it(e);
493
+ execute = async (e) => {
494
+ let t = this.createScope({ vars: Object.fromEntries(this.muxOne([Object.entries(this.options.vars)], ([e, t]) => [e, this.normalizeValue(t)])) });
495
+ try {
496
+ return await this.executeInstructions(this.program.definition.instructions ?? [], e, t, this.options.adjustResult);
497
+ } finally {
498
+ t.signal.exit();
499
+ }
500
+ };
501
+ executeInstructions = (e, t, n, r = (e) => [e]) => {
502
+ let i = async (t, n, a) => {
503
+ if (await void 0, a.signal.checkHealth(), t >= e.length) return r(n, a);
504
+ let { op: o, params: s } = e[t], c = this.program.ops[o];
505
+ if (!c) throw new y(`invalid OP '${o}'`);
506
+ return c.op(this, n, s ?? {}, a, (e, n) => i(t + 1, e, n));
507
+ };
508
+ return this.muxAll([t], (e) => i(0, e, n));
509
+ };
510
+ op(e, t, n, r, i = (e) => [e]) {
511
+ let a = this.program.ops[e];
512
+ if (!a) throw new y(`invalid OP '${e}'`);
513
+ let o = a.map(this, t);
514
+ return this.muxAll([n], (e) => a.op(this, e, o ?? {}, r, i));
515
+ }
516
+ normalizeValue = x;
517
+ normalizeValues = (e = [], t = "values") => {
518
+ if (!Array.isArray(e)) throw new y(`expected ${t} to be an array`);
519
+ return this.normalizeValue(e);
520
+ };
521
+ unwrapValue = S;
522
+ unwrapValues = (e = [], t = "values") => {
523
+ if (!Array.isArray(e)) throw new y(`expected ${t} to be an array`);
524
+ return this.muxOne([e], (e) => this.unwrapValue(e));
525
+ };
526
+ stripValue = (e) => E(e, (e, t) => this.unwrapValue(t));
527
+ stripValues = (e = [], t = "values") => {
528
+ if (!Array.isArray(e)) throw new y(`expected ${t} to be an array`);
529
+ return this.muxOne([e], (e) => this.stripValue(e));
530
+ };
531
+ alterValue = async (e, t) => b.is(e) ? We(() => e.alter(t)) : this.normalizeValue(await t(e));
532
+ type = qe;
533
+ assertType = Je;
534
+ truthy = (e) => {
535
+ let t = this.unwrapValue(e);
536
+ return t !== null && t !== !1;
537
+ };
538
+ compare = F.bind(this);
539
+ compareStrings = (e, t) => {
540
+ let n = this.type(e);
541
+ if (n !== "string") throw new y(`unexpected type ${n}`);
542
+ let r = this.type(t);
543
+ if (r !== "string") throw new y(`unexpected type ${r}`);
544
+ return I(this.unwrapValue(e), this.unwrapValue(t));
545
+ };
546
+ compareArrays = (e, t) => {
547
+ let n = this.type(e);
548
+ if (n !== "array") throw new y(`unexpected type ${n}`);
549
+ let r = this.type(t);
550
+ if (r !== "array") throw new y(`unexpected type ${r}`);
551
+ return mt.call(this, this.unwrapValue(e), this.unwrapValue(t));
552
+ };
553
+ compareObjects = (e, t) => {
554
+ let n = this.type(e);
555
+ if (n !== "object") throw new y(`unexpected type ${n}`);
556
+ let r = this.type(t);
557
+ if (r !== "object") throw new y(`unexpected type ${r}`);
558
+ return ht.call(this, this.unwrapValue(e), this.unwrapValue(t));
559
+ };
560
+ equals = (e, t) => this.compare(e, t) === 0;
561
+ merge = async (e, t) => (await void 0, this.type(e) !== "object" || this.type(t) !== "object" ? t : this.alterValue(e, async (e) => i(e, await Promise.all(Object.entries(this.unwrapValue(t)).map(async ([t, n]) => [t, await this.merge(e[t] ?? null, n)])))));
562
+ stringifyJSON = (e, t) => C(e, t);
563
+ stripJSON = (e) => E(e);
564
+ mux = lt;
565
+ muxOne = M;
566
+ muxAsync = N;
567
+ muxAll = ut;
568
+ };
569
+ function F(e, t) {
570
+ let n = this.type(e), r = this.type(t);
571
+ if (n !== r) return Ke.indexOf(n) - Ke.indexOf(r);
572
+ let i = this.unwrapValue(e), a = this.unwrapValue(t);
573
+ switch (n) {
574
+ case "null":
575
+ case "function": return 0;
576
+ case "boolean":
577
+ case "number": return i - +a;
578
+ case "string": return I(i, a);
579
+ case "array": return mt.call(this, i, a);
580
+ case "object": return ht.call(this, i, a);
581
+ default: throw new y(`unexpected type ${n}`);
582
+ }
583
+ }
584
+ function I(e, t) {
585
+ let n = Math.min(e.length, t.length), r = 0;
586
+ for (let i of e) {
587
+ if (r >= n) break;
588
+ let i = e.codePointAt(r), a = i - t.codePointAt(r);
589
+ if (a !== 0) return a;
590
+ r += 1, i > 65535 && (r += 1);
591
+ }
592
+ return e.length - t.length;
593
+ }
594
+ function mt(e, t) {
595
+ let n = Math.min(e.length, t.length);
596
+ for (let r = 0; r < n; r += 1) {
597
+ let n = F.call(this, e[r], t[r]);
598
+ if (n !== 0) return n;
599
+ }
600
+ return e.length - t.length;
601
+ }
602
+ function ht(e, t) {
603
+ let n = Object.keys(e).sort(I), r = Object.keys(t).sort(I), i = mt.call(this, n, r);
604
+ if (i !== 0) return i;
605
+ for (let r of n) if (i = F.call(this, e[r], t[r]), i !== 0) return i;
606
+ return 0;
607
+ }
608
+ //#endregion
609
+ //#region lib/program/ops/utils.ts
610
+ function L(e) {
611
+ return [{
612
+ op: "cnt",
613
+ params: { value: e ?? null }
614
+ }];
615
+ }
616
+ function R(e) {
617
+ return [{
618
+ op: "$.",
619
+ params: {
620
+ pipe: L(Je(e, "function")),
621
+ selectors: [{
622
+ op: "$()",
623
+ params: {
624
+ args: [],
625
+ bound: !1,
626
+ optional: !1
627
+ }
628
+ }]
629
+ }
630
+ }];
631
+ }
632
+ //#endregion
633
+ //#region lib/program/ops/opAccess/opaField.ts
634
+ var gt = {
635
+ op(e, t, n, r, i, a) {
636
+ let o = e.unwrapValue(n), s = e.type(o);
637
+ return e.executeInstructions(r.pipe ?? [], [t], i, (t) => {
638
+ let n = e.unwrapValue(t), i = e.type(n);
639
+ switch (s) {
640
+ case "null":
641
+ if (["string", "number"].includes(i)) return a(null);
642
+ break;
643
+ case "object":
644
+ if (i === "string") return a(o[n] ?? null);
645
+ break;
646
+ case "array":
647
+ if (i === "number") {
648
+ let e = Math.trunc(n);
649
+ return a(o[e >= 0 ? e : o.length + e] ?? null);
650
+ }
651
+ break;
652
+ case "string":
653
+ if (i === "number") {
654
+ let e = Math.trunc(n), t = [...o];
655
+ return a(t[e >= 0 ? e : t.length + e] ?? null);
656
+ }
657
+ break;
658
+ default:
659
+ }
660
+ if (r.optional) return [];
661
+ throw new A("cannot access field of %s (%*<100v) with %s (%*<100v)", s, o, i, n);
662
+ });
663
+ },
664
+ map(e, t) {
665
+ return {
666
+ pipe: R(t.pipe),
667
+ optional: e.assertType(t.optional, "boolean")
668
+ };
669
+ }
670
+ }, _t = {
671
+ async op(e, t, n, r, i, a) {
672
+ let o = e.unwrapValue(n), s = e.type(o);
673
+ switch (s) {
674
+ case "function": {
675
+ let n = await e.muxAsync([r.args ?? []], (n) => e.executeInstructions(n ?? [], [t], i));
676
+ return e.muxAll(n, async (...n) => {
677
+ try {
678
+ let s = async (e) => {
679
+ try {
680
+ return await a(e);
681
+ } catch (e) {
682
+ throw new v(e);
683
+ }
684
+ };
685
+ return r.bound ? await o(e, i.signal, s, n[0] ?? null, ...n.slice(1)) : await o(e, i.signal, s, t, ...n);
686
+ } catch (e) {
687
+ throw v.is(e) ? e.inner : _(e);
688
+ }
689
+ });
690
+ }
691
+ default:
692
+ }
693
+ if (r.optional) return [];
694
+ throw new A("cannot execute %s (%*<100v)", s, o);
695
+ },
696
+ map(e, t) {
697
+ return {
698
+ args: e.muxOne([t.args], (e) => R(e)),
699
+ bound: e.assertType(t.bound, "boolean"),
700
+ optional: e.assertType(t.optional, "boolean")
701
+ };
702
+ }
703
+ }, vt = {
704
+ op(e, t, n, r, i, a) {
705
+ let o = e.unwrapValue(n), s = e.type(o);
706
+ switch (s) {
707
+ case "null": return [];
708
+ case "object": return e.muxAll([Object.values(o)], a);
709
+ case "array": return e.muxAll([o], a);
710
+ case "string": return e.muxAll([[...o]], a);
711
+ default:
712
+ }
713
+ if (r.optional) return [];
714
+ throw new A("cannot iterate over %s (%*<100v)", s, o);
715
+ },
716
+ map(e, t) {
717
+ return { optional: e.assertType(t.optional, "boolean") };
718
+ }
719
+ }, yt = {
720
+ async op(e, t, n, r, i, a) {
721
+ let o = e.unwrapValue(n), s = e.type(o), [c, l] = await Promise.all([e.executeInstructions(r.from ?? [], [t], i), e.executeInstructions(r.to ?? [], [t], i)]);
722
+ return e.muxAll([e.unwrapValues(c), e.unwrapValues(l)], (t, n) => {
723
+ let i = e.type(t), c = e.type(n);
724
+ switch (s) {
725
+ case "null": return a(null);
726
+ case "array":
727
+ if (["number", "null"].includes(i) && ["number", "null"].includes(c)) return a(o.slice(Math.trunc(t ?? 0), Math.trunc(n ?? o.length)));
728
+ break;
729
+ case "string":
730
+ if (["number", "null"].includes(i) && ["number", "null"].includes(c)) {
731
+ let e = [...o];
732
+ return a(e.slice(Math.trunc(t ?? 0), Math.trunc(n ?? e.length)).join(""));
733
+ }
734
+ break;
735
+ default:
736
+ }
737
+ if (r.optional) return [];
738
+ throw new A("cannot slice %s (%*<100v) with %s (%*<100v) and %s (%*<100v)", s, o, i, t, c, n);
739
+ });
740
+ },
741
+ map(e, t) {
742
+ return {
743
+ from: R(t.from),
744
+ to: R(t.to),
745
+ optional: e.assertType(t.optional, "boolean")
746
+ };
747
+ }
748
+ }, bt = {
749
+ op(e, t, n, r, i) {
750
+ let a = async (o, s) => {
751
+ if (await void 0, r.signal.checkHealth(), o >= (n.selectors?.length ?? 0)) return i(s, r);
752
+ let { op: c, params: l } = n.selectors[o], u = xt[c];
753
+ if (!u) throw new y(`invalid OPA '${c}'`);
754
+ return u.op(e, t, s, l ?? {}, r, (e) => a(o + 1, e));
755
+ };
756
+ return e.executeInstructions(n.pipe ?? [], [t], r, (e) => a(0, e));
757
+ },
758
+ map(e, t) {
759
+ return {
760
+ pipe: R(t.pipe),
761
+ selectors: e.muxOne([t.selectors], ({ op: t, params: n }) => {
762
+ let r = xt[t];
763
+ if (!r) throw new y(`invalid OPA '${t}'`);
764
+ return {
765
+ op: e.assertType(t, "string"),
766
+ params: r.map(e, n)
767
+ };
768
+ })
769
+ };
770
+ }
771
+ }, xt = {
772
+ "$.$": gt,
773
+ "$()": _t,
774
+ "$[]": vt,
775
+ "[:]": yt
776
+ }, St = {
777
+ op(e, t, n, r, i) {
778
+ let a = async (o) => {
779
+ if (await void 0, r.signal.checkHealth(), o >= (n.pipes?.length ?? 0)) return i(!0, r);
780
+ let s = n.pipes[o];
781
+ return e.executeInstructions(s ?? [], [t], r, (t) => e.truthy(t) ? a(o + 1) : i(!1, r));
782
+ };
783
+ return a(0);
784
+ },
785
+ map(e, t) {
786
+ return { pipes: e.muxOne([t.pipes], (e) => R(e)) };
787
+ }
788
+ }, Ct = {
789
+ async op(e, t, n, r, i) {
790
+ return i(await e.executeInstructions(n.pipe ?? [], [t], r), r);
791
+ },
792
+ map(e, t) {
793
+ return { pipe: R(t.pipe) };
794
+ }
795
+ }, wt = {
796
+ async op(e, t, n, r, o, s) {
797
+ let c, l = e.unwrapValue(n), u = e.type(n);
798
+ switch (u) {
799
+ case "null":
800
+ case "object":
801
+ case "array":
802
+ c = l;
803
+ break;
804
+ case "string":
805
+ c = [...l];
806
+ break;
807
+ default:
808
+ if (r.optional) return [void 0];
809
+ throw new A("cannot access fields of %s (%*<100v) (assignment)", u, l);
810
+ }
811
+ let d = await e.executeInstructions(r.pipe ?? [], [t], o, (e) => [e]), f = async (t, n) => {
812
+ if (await void 0, o.signal.checkHealth(), t >= d.length) return [n];
813
+ let c = u === "string" ? u : e.type(n), l = e.unwrapValue(d[t]), p = e.type(l);
814
+ switch (c) {
815
+ case "null":
816
+ switch (p) {
817
+ case "string": return e.muxAll([await s(null)], (e) => e === void 0 ? f(t + 1, n) : f(t + 1, { [l]: e }));
818
+ case "number": {
819
+ let r = Math.trunc(l);
820
+ return e.muxAll([await s(null)], (e) => e === void 0 ? f(t + 1, n) : f(t + 1, a([], [[r, e]])));
821
+ }
822
+ default:
823
+ }
824
+ break;
825
+ case "object":
826
+ if (p === "string") {
827
+ let r = n[l];
828
+ return e.muxAll([await s(r ?? null)], (e) => e === void 0 ? f(t + 1, n) : f(t + 1, i(n, [[l, e]])));
829
+ }
830
+ break;
831
+ case "array":
832
+ if (p === "number") {
833
+ let r = Math.trunc(l), i = n[r >= 0 ? r : n.length + r];
834
+ return e.muxAll([await s(i ?? null)], (e) => e === void 0 ? f(t + 1, n) : f(t + 1, a(n, [[r, e]])));
835
+ }
836
+ break;
837
+ case "string":
838
+ if (p === "number") {
839
+ let r = Math.trunc(l), i = n[r >= 0 ? r : n.length + r];
840
+ return e.muxAll([await s(i ?? null)], (i) => {
841
+ if (i === void 0) return f(t + 1, n);
842
+ let o = e.unwrapValue(i), s = e.type(o);
843
+ switch (s) {
844
+ case "null":
845
+ case "string": return f(t + 1, a(n, [[r, i ?? " "]], " "));
846
+ default:
847
+ }
848
+ throw new A("cannot assign %s (%*<100v) to string (%*<100v)", s, o, n.join(""));
849
+ });
850
+ }
851
+ break;
852
+ default:
853
+ }
854
+ if (r.optional) return f(t + 1, n);
855
+ throw new A("cannot access field of %s (%*<100v) with %s (%*<100v) (assignment)", c, c === "string" ? n.join("") : n, p, l);
856
+ };
857
+ return e.muxAsync([await f(0, c)], (t) => {
858
+ if (c === t) return n;
859
+ switch (u === "string" ? u : e.type(t)) {
860
+ case "null": return;
861
+ case "object":
862
+ case "array": return e.alterValue(n, () => t);
863
+ case "string": return e.alterValue(n, () => t.join(""));
864
+ default:
865
+ }
866
+ });
867
+ },
868
+ map(e, t) {
869
+ return {
870
+ pipe: R(t.pipe),
871
+ optional: e.assertType(t.optional, "boolean")
872
+ };
873
+ }
874
+ }, Tt = {
875
+ async op(e, t, n, r, i, a) {
876
+ let s = e.unwrapValue(n), c = e.type(s);
877
+ switch (c) {
878
+ case "null": return [void 0];
879
+ case "object": {
880
+ let t = Object.entries(s), r = await e.muxAsync([t], async (t) => e.muxAsync([await a(t[1] ?? null)], (e) => e === void 0 ? t : [t[0], e]));
881
+ return e.muxAsync([o(t, r)], (r) => t === r ? n : e.alterValue(n, () => Object.fromEntries(r)));
882
+ }
883
+ case "array": {
884
+ let t = s, r = await e.muxAsync([t], async (t) => e.muxAsync([await a(t ?? null)], (e) => e === void 0 ? t : e));
885
+ return e.muxAsync([o(t, r)], (r) => t === r ? n : e.alterValue(n, () => r));
886
+ }
887
+ case "string": {
888
+ let t = [...s], r = await e.muxAsync([t], async (t) => e.muxAsync([await a(t)], (n) => {
889
+ if (n === void 0) return t;
890
+ let r = e.unwrapValue(n), i = e.type(r);
891
+ switch (i) {
892
+ case "null":
893
+ case "string": return r ?? " ";
894
+ default:
895
+ }
896
+ throw new A("cannot assign %s (%*<100v) to string (%*<100v)", i, r, s);
897
+ }));
898
+ return e.muxAsync([o(t, r)], (r) => t === r ? n : e.alterValue(n, () => r.join("")));
899
+ }
900
+ default:
901
+ }
902
+ if (r.optional) return [void 0];
903
+ throw new A("cannot iterate over %s (%*<100v) (assignment)", c, s);
904
+ },
905
+ map(e, t) {
906
+ return { optional: e.assertType(t.optional, "boolean") };
907
+ }
908
+ };
909
+ //#endregion
910
+ //#region lib/program/ops/opAssignment/opaAssignSlice.ts
911
+ function Et(e, t) {
912
+ return e.length === t.length ? e.every((e, n) => e === t[n]) : !1;
913
+ }
914
+ var Dt = {
915
+ async op(e, t, n, r, i, a) {
916
+ let [o, s] = await Promise.all([e.executeInstructions(r.from ?? [], [t], i), e.executeInstructions(r.to ?? [], [t], i)]), c = e.muxOne([e.unwrapValues(o), e.unwrapValues(s)], (e, t) => [e, t]), l = async (t, n) => {
917
+ if (await void 0, i.signal.checkHealth(), t >= c.length) return [n];
918
+ let o = e.unwrapValue(n), s = e.type(n), [u, d] = c[t], f = e.type(u), p = e.type(d);
919
+ switch (s) {
920
+ case "null": return l(t + 1, n);
921
+ case "array":
922
+ if (["number", "null"].includes(f) && ["number", "null"].includes(p)) return e.muxAll([await a(o.slice(Math.trunc(u ?? 0), Math.trunc(d ?? o.length)))], async (r) => r === void 0 ? l(t + 1, n) : l(t + 1, await e.alterValue(n, (t) => {
923
+ let n = e.unwrapValue(r), i = e.type(n);
924
+ switch (i) {
925
+ case "null":
926
+ case "array": {
927
+ let e = Math.trunc(u ?? 0), r = Math.trunc(d ?? t.length);
928
+ if (e = e >= 0 ? Math.min(t.length, e) : Math.max(0, t.length + e), r = Math.max(e, r >= 0 ? Math.min(t.length, r) : Math.max(0, t.length + r)), Et(t.slice(e, r), n ?? [])) return t;
929
+ let i = [...t];
930
+ return i.splice(e, r - e, ...n ?? []), i;
931
+ }
932
+ default:
933
+ }
934
+ throw new A("cannot assign %s (%*<100v) to slice of %s (%*<100v)", i, n, s, t);
935
+ })));
936
+ break;
937
+ case "string":
938
+ if (["number", "null"].includes(f) && ["number", "null"].includes(p)) {
939
+ let r = [...o];
940
+ return e.muxAll([await a(r.slice(Math.trunc(u ?? 0), Math.trunc(d ?? r.length)).join(""))], async (r) => r === void 0 ? l(t + 1, n) : l(t + 1, await e.alterValue(n, (t) => {
941
+ let n = e.unwrapValue(r), i = e.type(n);
942
+ switch (i) {
943
+ case "null":
944
+ case "string": {
945
+ let e = [...t], r = Math.trunc(u ?? 0), i = Math.trunc(d ?? e.length);
946
+ return r = r >= 0 ? Math.min(e.length, r) : Math.max(0, e.length + r), i = Math.max(r, i >= 0 ? Math.min(e.length, i) : Math.max(0, e.length + i)), Et(e.slice(r, i), n ?? []) ? t : (e.splice(r, i - r, ...n ?? []), e.join(""));
947
+ }
948
+ default:
949
+ }
950
+ throw new A("cannot assign %s (%*<100v) to slice of %s (%*<100v)", i, n, s, t);
951
+ })));
952
+ }
953
+ break;
954
+ default:
955
+ }
956
+ if (r.optional) return l(t + 1, n);
957
+ throw new A("cannot slice %s (%*<100v) with %s (%*<100v) and %s (%*<100v) (assignment)", s, o, f, u, p, d);
958
+ };
959
+ return e.muxOne([await l(0, n)], (t) => e.type(t) === "null" ? void 0 : t);
960
+ },
961
+ map(e, t) {
962
+ return {
963
+ from: R(t.from),
964
+ to: R(t.to),
965
+ optional: e.assertType(t.optional, "boolean")
966
+ };
967
+ }
968
+ }, Ot = {
969
+ op(e, t, n, r, i, a) {
970
+ return e.executeInstructions([{
971
+ op: "clc",
972
+ params: {
973
+ pipe: L(n),
974
+ operations: [{
975
+ op: "+",
976
+ params: { by: r.pipe ?? [] }
977
+ }]
978
+ }
979
+ }], [t], i, a);
980
+ },
981
+ map(e, t) {
982
+ return { pipe: R(t.pipe) };
983
+ }
984
+ }, kt = {
985
+ op(e, t, n, r, i, a) {
986
+ return e.executeInstructions([{
987
+ op: "clc",
988
+ params: {
989
+ pipe: L(n),
990
+ operations: [{
991
+ op: "/",
992
+ params: { by: r.pipe ?? [] }
993
+ }]
994
+ }
995
+ }], [t], i, a);
996
+ },
997
+ map(e, t) {
998
+ return { pipe: R(t.pipe) };
999
+ }
1000
+ }, At = {
1001
+ op(e, t, n, r, i, a) {
1002
+ return e.executeInstructions([{
1003
+ op: "clc",
1004
+ params: {
1005
+ pipe: L(n),
1006
+ operations: [{
1007
+ op: "*",
1008
+ params: { by: r.pipe ?? [] }
1009
+ }]
1010
+ }
1011
+ }], [t], i, a);
1012
+ },
1013
+ map(e, t) {
1014
+ return { pipe: R(t.pipe) };
1015
+ }
1016
+ }, jt = {
1017
+ op(e, t, n, r, i, a) {
1018
+ return e.executeInstructions([{
1019
+ op: "??",
1020
+ params: { pipes: [L(n), r.pipe ?? []] }
1021
+ }], [t], i, a);
1022
+ },
1023
+ map(e, t) {
1024
+ return { pipe: R(t.pipe) };
1025
+ }
1026
+ }, Mt = {
1027
+ op(e, t, n, r, i, a) {
1028
+ return e.executeInstructions([{
1029
+ op: "clc",
1030
+ params: {
1031
+ pipe: L(n),
1032
+ operations: [{
1033
+ op: "%",
1034
+ params: { by: r.pipe ?? [] }
1035
+ }]
1036
+ }
1037
+ }], [t], i, a);
1038
+ },
1039
+ map(e, t) {
1040
+ return { pipe: R(t.pipe) };
1041
+ }
1042
+ }, Nt = {
1043
+ op(e, t, n, r, i, a) {
1044
+ return e.executeInstructions(r.pipe ?? [], [t], i, a);
1045
+ },
1046
+ map(e, t) {
1047
+ return { pipe: R(t.pipe) };
1048
+ }
1049
+ }, Pt = {
1050
+ op(e, t, n, r, i, a) {
1051
+ return e.executeInstructions([{
1052
+ op: "clc",
1053
+ params: {
1054
+ pipe: L(n),
1055
+ operations: [{
1056
+ op: "-",
1057
+ params: { by: r.pipe ?? [] }
1058
+ }]
1059
+ }
1060
+ }], [t], i, a);
1061
+ },
1062
+ map(e, t) {
1063
+ return { pipe: R(t.pipe) };
1064
+ }
1065
+ }, Ft = {
1066
+ op(e, t, n, r, i, a) {
1067
+ return e.executeInstructions(r.pipe ?? [], [n], i, a);
1068
+ },
1069
+ map(e, t) {
1070
+ return { pipe: R(t.pipe) };
1071
+ }
1072
+ }, It = {
1073
+ op(e, t, n, r, i) {
1074
+ let a = async (i, o) => {
1075
+ if (await void 0, r.signal.checkHealth(), i >= (n.selectors?.length ?? 0)) {
1076
+ let { op: i, params: a } = n.assignment ?? {}, s = Rt[i];
1077
+ if (!s) throw new y(`invalid OPU '${i}'`);
1078
+ return s.op(e, t, o, a ?? {}, r, (e) => [e]);
1079
+ }
1080
+ let { op: s, params: c } = n.selectors[i], l = Lt[s];
1081
+ if (!l) throw new y(`invalid OPA '${s}' (assignment)`);
1082
+ return l.op(e, t, o, c ?? {}, r, (e) => a(i + 1, e));
1083
+ };
1084
+ return e.executeInstructions(n.pipe ?? [], [t], r, async (t) => e.muxAll([await a(0, t)], (e) => i(e === void 0 ? t : e, r)));
1085
+ },
1086
+ map(e, t) {
1087
+ return {
1088
+ pipe: R(t.pipe),
1089
+ selectors: e.muxOne([t.selectors], ({ op: t, params: n }) => {
1090
+ let r = Lt[t];
1091
+ if (!r) throw new y(`invalid OPA '${t}' (assignment)`);
1092
+ return {
1093
+ op: e.assertType(t, "string"),
1094
+ params: r.map(e, n)
1095
+ };
1096
+ }),
1097
+ assignment: (({ op: t, params: n }) => {
1098
+ let r = Rt[t];
1099
+ if (!r) throw new y(`invalid OPU '${t}'`);
1100
+ return {
1101
+ op: e.assertType(t, "string"),
1102
+ params: r.map(e, n)
1103
+ };
1104
+ })(t.assignment)
1105
+ };
1106
+ }
1107
+ }, Lt = {
1108
+ "$.$": wt,
1109
+ "$[]": Tt,
1110
+ "[:]": Dt
1111
+ }, Rt = {
1112
+ "+=": Ot,
1113
+ "/=": kt,
1114
+ "*=": At,
1115
+ "?=": jt,
1116
+ "%=": Mt,
1117
+ "=": Nt,
1118
+ "-=": Pt,
1119
+ "|=": Ft
1120
+ }, zt = {
1121
+ op(e, t, n, r, a, o) {
1122
+ return e.executeInstructions(r.by ?? [], [t], a, async (t) => o(await e.alterValue(n, (n) => {
1123
+ let r = e.unwrapValue(t), a = e.type(n), o = e.type(r);
1124
+ if (a === "null" || o === "null") return a === "null" ? o === "null" ? null : r : n;
1125
+ switch (a) {
1126
+ case "number":
1127
+ if (o === "number") return n + r;
1128
+ break;
1129
+ case "array":
1130
+ if (o === "array") return r.length === 0 ? n : n.length === 0 ? r : [...n, ...r];
1131
+ break;
1132
+ case "string":
1133
+ if (o === "string") return n + r;
1134
+ break;
1135
+ case "object":
1136
+ if (o === "object") return i(n, Object.entries(r));
1137
+ break;
1138
+ default:
1139
+ }
1140
+ throw new A("%s (%*<100v) and %s (%*<100v) cannot be added together", a, n, o, r);
1141
+ })));
1142
+ },
1143
+ map(e, t) {
1144
+ return { by: R(t.by) };
1145
+ }
1146
+ }, Bt = {
1147
+ op(e, t, n, r, i, a) {
1148
+ return e.executeInstructions(r.by ?? [], [t], i, async (t) => a(await e.alterValue(n, (n) => {
1149
+ let r = e.unwrapValue(t), i = e.type(n), a = e.type(r);
1150
+ switch (i) {
1151
+ case "number":
1152
+ if (a === "number") {
1153
+ if (r === 0) throw new j("%s (%*<100v) cannot be divided by zero", i, n);
1154
+ return n / r;
1155
+ }
1156
+ break;
1157
+ case "string":
1158
+ if (a === "string") return r === "" ? [...n] : n.split(r);
1159
+ break;
1160
+ default:
1161
+ }
1162
+ throw new A("%s (%*<100v) cannot be divided by %s (%*<100v)", i, n, a, r);
1163
+ })));
1164
+ },
1165
+ map(e, t) {
1166
+ return { by: R(t.by) };
1167
+ }
1168
+ }, Vt = {
1169
+ op(e, t, n, r, i, a) {
1170
+ return e.executeInstructions(r.by ?? [], [t], i, async (t) => a(await e.alterValue(n, (n) => {
1171
+ let r = e.unwrapValue(t), i = e.type(n), a = e.type(r);
1172
+ switch (i) {
1173
+ case "number":
1174
+ if (a === "number") return n * r;
1175
+ break;
1176
+ case "string":
1177
+ if (a === "number") return r < 1 ? null : n.repeat(r);
1178
+ break;
1179
+ case "object":
1180
+ if (a === "object") return e.merge(n, r);
1181
+ break;
1182
+ default:
1183
+ }
1184
+ throw new A("%s (%*<100v) and %s (%*<100v) cannot be multiplied together", i, n, a, r);
1185
+ })));
1186
+ },
1187
+ map(e, t) {
1188
+ return { by: R(t.by) };
1189
+ }
1190
+ }, Ht = {
1191
+ op(e, t, n, r, i, a) {
1192
+ return e.executeInstructions(r.by ?? [], [t], i, async (t) => a(await e.alterValue(n, (n) => {
1193
+ let r = e.unwrapValue(t), i = e.type(n), a = e.type(r);
1194
+ switch (i) {
1195
+ case "number":
1196
+ if (a === "number") {
1197
+ if (r === 0) throw new j("%s (%*<100v) cannot be divided by zero (remainder)", i, n);
1198
+ return n % r;
1199
+ }
1200
+ break;
1201
+ default:
1202
+ }
1203
+ throw new A("%s (%*<100v) cannot be divided by %s (%*<100v) (remainder)", i, n, a, r);
1204
+ })));
1205
+ },
1206
+ map(e, t) {
1207
+ return { by: R(t.by) };
1208
+ }
1209
+ }, Ut = {
1210
+ op(e, t, n, r, a, o) {
1211
+ return e.executeInstructions(r.by ?? [], [t], a, async (t) => o(await e.alterValue(n, (n) => {
1212
+ let r = e.unwrapValue(t), a = e.type(n), o = e.type(r);
1213
+ switch (a) {
1214
+ case "number":
1215
+ if (o === "number") return n - r;
1216
+ break;
1217
+ case "array":
1218
+ if (o === "array") {
1219
+ if (n.length === 0 || r.length === 0) return n;
1220
+ let t = n.filter((t) => !r.some((n) => e.equals(t, n)));
1221
+ return n.length === t.length ? n : t;
1222
+ }
1223
+ break;
1224
+ case "string":
1225
+ if (o === "string") return n.replaceAll(r, "");
1226
+ break;
1227
+ case "object":
1228
+ switch (o) {
1229
+ case "array": return r.length === 0 ? n : i(n, Object.entries(n).filter(([, t]) => r.some((n) => e.equals(t, n))).map(([e]) => [e]));
1230
+ case "string": return i(n, [[r]]);
1231
+ default:
1232
+ }
1233
+ break;
1234
+ default:
1235
+ }
1236
+ throw new A("%s (%*<100v) and %s (%*<100v) cannot be subtracted", a, n, o, r);
1237
+ })));
1238
+ },
1239
+ map(e, t) {
1240
+ return { by: R(t.by) };
1241
+ }
1242
+ }, Wt = {
1243
+ op(e, t, n, r, i) {
1244
+ let a = async (o, s) => {
1245
+ if (await void 0, r.signal.checkHealth(), o >= (n.operations?.length ?? 0)) return i(s, r);
1246
+ let { op: c, params: l } = n.operations[o], u = Gt[c];
1247
+ if (!u) throw new y(`invalid OPM '${c}'`);
1248
+ return u.op(e, t, s, l ?? {}, r, (e) => a(o + 1, e));
1249
+ };
1250
+ return e.executeInstructions(n.pipe ?? [], [t], r, (e) => a(0, e));
1251
+ },
1252
+ map(e, t) {
1253
+ return {
1254
+ pipe: R(t.pipe),
1255
+ operations: e.muxOne([t.operations], ({ op: t, params: n }) => {
1256
+ let r = Gt[t];
1257
+ if (!r) throw new y(`invalid OPM '${t}'`);
1258
+ return {
1259
+ op: e.assertType(t, "string"),
1260
+ params: r.map(e, n)
1261
+ };
1262
+ })
1263
+ };
1264
+ }
1265
+ }, Gt = {
1266
+ "+": zt,
1267
+ "/": Bt,
1268
+ "*": Vt,
1269
+ "%": Ht,
1270
+ "-": Ut
1271
+ }, Kt = {
1272
+ op(e, t, n, r, i, a) {
1273
+ return e.executeInstructions(r.by ?? [], [t], i, (t) => a(e.equals(n, t)));
1274
+ },
1275
+ map(e, t) {
1276
+ return { by: R(t.by) };
1277
+ }
1278
+ }, qt = {
1279
+ op(e, t, n, r, i, a) {
1280
+ return e.executeInstructions(r.by ?? [], [t], i, (t) => a(e.compare(n, t) > 0));
1281
+ },
1282
+ map(e, t) {
1283
+ return { by: R(t.by) };
1284
+ }
1285
+ }, Jt = {
1286
+ op(e, t, n, r, i, a) {
1287
+ return e.executeInstructions(r.by ?? [], [t], i, (t) => a(e.compare(n, t) >= 0));
1288
+ },
1289
+ map(e, t) {
1290
+ return { by: R(t.by) };
1291
+ }
1292
+ }, Yt = {
1293
+ op(e, t, n, r, i, a) {
1294
+ return e.executeInstructions(r.by ?? [], [t], i, (t) => a(e.compare(n, t) < 0));
1295
+ },
1296
+ map(e, t) {
1297
+ return { by: R(t.by) };
1298
+ }
1299
+ }, Xt = {
1300
+ op(e, t, n, r, i, a) {
1301
+ return e.executeInstructions(r.by ?? [], [t], i, (t) => a(e.compare(n, t) <= 0));
1302
+ },
1303
+ map(e, t) {
1304
+ return { by: R(t.by) };
1305
+ }
1306
+ }, Zt = {
1307
+ op(e, t, n, r, i, a) {
1308
+ return e.executeInstructions(r.by ?? [], [t], i, (t) => a(!e.equals(n, t)));
1309
+ },
1310
+ map(e, t) {
1311
+ return { by: R(t.by) };
1312
+ }
1313
+ }, Qt = {
1314
+ op(e, t, n, r, i) {
1315
+ let a = async (o, s) => {
1316
+ if (await void 0, r.signal.checkHealth(), o >= (n.comparisons?.length ?? 0)) return i(s, r);
1317
+ let { op: c, params: l } = n.comparisons[o], u = $t[c];
1318
+ if (!u) throw new y(`invalid OPC '${c}'`);
1319
+ return u.op(e, t, s, l ?? {}, r, (e) => a(o + 1, e));
1320
+ };
1321
+ return e.executeInstructions(n.pipe ?? [], [t], r, (e) => a(0, e));
1322
+ },
1323
+ map(e, t) {
1324
+ return {
1325
+ pipe: R(t.pipe),
1326
+ comparisons: e.muxOne([t.comparisons], ({ op: t, params: n }) => {
1327
+ let r = $t[t];
1328
+ if (!r) throw new y(`invalid OPC '${t}'`);
1329
+ return {
1330
+ op: e.assertType(t, "string"),
1331
+ params: r.map(e, n)
1332
+ };
1333
+ })
1334
+ };
1335
+ }
1336
+ }, $t = {
1337
+ "==": Kt,
1338
+ ">": qt,
1339
+ ">=": Jt,
1340
+ "<": Yt,
1341
+ "<=": Xt,
1342
+ "!=": Zt
1343
+ }, en = {
1344
+ "$.": bt,
1345
+ and: St,
1346
+ "[]": Ct,
1347
+ "$=": It,
1348
+ clc: Wt,
1349
+ cmp: Qt,
1350
+ cnt: {
1351
+ op(e, t, n, r, i) {
1352
+ return i(n.value ?? null, r);
1353
+ },
1354
+ map(e, t) {
1355
+ return { value: e.normalizeValue(t.value) };
1356
+ }
1357
+ },
1358
+ fls: {
1359
+ op(e, t, n, r, i) {
1360
+ return i(!1, r);
1361
+ },
1362
+ map(e, t) {
1363
+ return {};
1364
+ }
1365
+ },
1366
+ nul: {
1367
+ op(e, t, n, r, i) {
1368
+ return i(null, r);
1369
+ },
1370
+ map(e, t) {
1371
+ return {};
1372
+ }
1373
+ },
1374
+ tru: {
1375
+ op(e, t, n, r, i) {
1376
+ return i(!0, r);
1377
+ },
1378
+ map(e, t) {
1379
+ return {};
1380
+ }
1381
+ },
1382
+ fun: {
1383
+ op(e, t, n, r, i) {
1384
+ return i(ot(n.argNames ?? [], n.pipe ?? [], r), r);
1385
+ },
1386
+ map(e, t) {
1387
+ return {
1388
+ argNames: e.muxOne([t.argNames], (t) => e.assertType(t, "string")),
1389
+ pipe: R(t.pipe)
1390
+ };
1391
+ }
1392
+ },
1393
+ if: {
1394
+ op(e, t, n, r, i) {
1395
+ let a = async (o) => {
1396
+ if (await void 0, r.signal.checkHealth(), o >= (n.ifs?.length ?? 0)) return e.executeInstructions(n.else ?? [], [t], r, (e) => i(e, r));
1397
+ let s = n.ifs[o];
1398
+ return e.executeInstructions(s.if ?? [], [t], r, (n) => e.truthy(n) ? e.executeInstructions(s.then ?? [], [t], r, (e) => i(e, r)) : a(o + 1));
1399
+ };
1400
+ return a(0);
1401
+ },
1402
+ map(e, t) {
1403
+ return {
1404
+ ifs: e.muxOne([t.ifs], (e) => ({
1405
+ if: R(e.if),
1406
+ then: R(e.then)
1407
+ })),
1408
+ else: R(t.else)
1409
+ };
1410
+ }
1411
+ },
1412
+ "\"$\"": {
1413
+ async op(e, t, n, r, i) {
1414
+ let a = await e.muxAsync([n.interpolations ?? []], (n) => e.executeInstructions(n.pipe ?? [], [t], r, (t) => [(n.before ?? "") + e.stringifyJSON(t, !0)]));
1415
+ return e.muxAll(a, (...e) => i(e.join("") + (n.after ?? ""), r));
1416
+ },
1417
+ map(e, t) {
1418
+ return {
1419
+ interpolations: e.muxOne([t.interpolations], (t) => ({
1420
+ before: e.assertType(t.before, "string"),
1421
+ pipe: R(t.pipe)
1422
+ })),
1423
+ after: e.assertType(t.after, "string")
1424
+ };
1425
+ }
1426
+ },
1427
+ neg: {
1428
+ async op(e, t, n, r, i) {
1429
+ return i(await e.alterValue(t, (t) => {
1430
+ let n = e.type(t);
1431
+ switch (n) {
1432
+ case "number": return -t;
1433
+ default:
1434
+ }
1435
+ throw new A("%s (%*<100v) cannot be negated", n, t);
1436
+ }), r);
1437
+ },
1438
+ map(e, t) {
1439
+ return {};
1440
+ }
1441
+ },
1442
+ not: {
1443
+ op(e, t, n, r, i) {
1444
+ return i(!e.truthy(t), r);
1445
+ },
1446
+ map(e, t) {
1447
+ return {};
1448
+ }
1449
+ },
1450
+ "??": {
1451
+ op(e, t, n, r, i) {
1452
+ let a = async (o) => {
1453
+ if (await void 0, r.signal.checkHealth(), o >= (n.pipes?.length ?? 0)) return i(null, r);
1454
+ let s = n.pipes[o];
1455
+ return e.executeInstructions(s ?? [], [t], r, (t) => {
1456
+ switch (e.type(t)) {
1457
+ case "null": return a(o + 1);
1458
+ default: return i(t, r);
1459
+ }
1460
+ });
1461
+ };
1462
+ return a(0);
1463
+ },
1464
+ map(e, t) {
1465
+ return { pipes: e.muxOne([t.pipes], (e) => R(e)) };
1466
+ }
1467
+ },
1468
+ nbr: {
1469
+ op(e, t, n, r, i) {
1470
+ return i(n.number ?? 0, r);
1471
+ },
1472
+ map(e, t) {
1473
+ return { number: e.assertType(t.number, "number") };
1474
+ }
1475
+ },
1476
+ "{}": {
1477
+ async op(e, t, n, r, i) {
1478
+ let a = await e.muxAsync([n.fields ?? []], async (n) => {
1479
+ let [i, a] = await Promise.all([e.executeInstructions(n.key ?? [], [t], r), e.executeInstructions(n.value ?? [], [t], r)]);
1480
+ return e.muxAll([e.unwrapValues(i), a], (t, r) => {
1481
+ let i = e.type(t);
1482
+ switch (i) {
1483
+ case "string": return [[t, r]];
1484
+ default:
1485
+ }
1486
+ if (n.optional) return [];
1487
+ throw new A("cannot use %s (%*<100v) as object key", i, t);
1488
+ });
1489
+ });
1490
+ return e.muxAll(a, (...e) => i(Object.fromEntries(e), r));
1491
+ },
1492
+ map(e, t) {
1493
+ return { fields: e.muxOne([t.fields], (t) => ({
1494
+ key: R(t.key),
1495
+ value: R(t.value),
1496
+ optional: e.assertType(t.optional, "boolean")
1497
+ })) };
1498
+ }
1499
+ },
1500
+ or: {
1501
+ op(e, t, n, r, i) {
1502
+ let a = async (o) => {
1503
+ if (await void 0, r.signal.checkHealth(), o >= (n.pipes?.length ?? 0)) return i(!1, r);
1504
+ let s = n.pipes[o];
1505
+ return e.executeInstructions(s ?? [], [t], r, (t) => e.truthy(t) ? i(!0, r) : a(o + 1));
1506
+ };
1507
+ return a(0);
1508
+ },
1509
+ map(e, t) {
1510
+ return { pipes: e.muxOne([t.pipes], (e) => R(e)) };
1511
+ }
1512
+ },
1513
+ ",": {
1514
+ op(e, t, n, r, i) {
1515
+ return e.muxAll([n.pipes ?? []], (n) => e.executeInstructions(n ?? [], [t], r, (e) => i(e, r)));
1516
+ },
1517
+ map(e, t) {
1518
+ return { pipes: e.muxOne([t.pipes], (e) => R(e)) };
1519
+ }
1520
+ },
1521
+ "\"\"": {
1522
+ op(e, t, n, r, i) {
1523
+ return i(n.string ?? "", r);
1524
+ },
1525
+ map(e, t) {
1526
+ return { string: e.assertType(t.string, "string") };
1527
+ }
1528
+ },
1529
+ try: {
1530
+ async op(e, t, n, r, i) {
1531
+ let a = r.next({ signal: r.signal.next() });
1532
+ try {
1533
+ return await e.executeInstructions(n.try ?? [], [t], a, async (e) => {
1534
+ try {
1535
+ return await i(e, r);
1536
+ } catch (e) {
1537
+ throw new v(e);
1538
+ }
1539
+ });
1540
+ } catch (t) {
1541
+ if (v.is(t)) throw t.inner;
1542
+ if (!g.is(t)) throw t;
1543
+ return a.signal.exit(), e.executeInstructions(n.catch ?? [], [t.value], r, (e) => i(e, r));
1544
+ }
1545
+ },
1546
+ map(e, t) {
1547
+ return {
1548
+ try: R(t.try),
1549
+ catch: R(t.catch)
1550
+ };
1551
+ }
1552
+ },
1553
+ var: {
1554
+ op(e, t, n, r, i) {
1555
+ if (!Object.hasOwn(r.vars, n.name ?? "")) throw new et("%s is not defined", n.name ?? "");
1556
+ return i(r.vars[n.name ?? ""], r);
1557
+ },
1558
+ map(e, t) {
1559
+ return { name: e.assertType(t.name, "string") };
1560
+ }
1561
+ },
1562
+ "va=": {
1563
+ op(e, t, n, r, i) {
1564
+ return e.executeInstructions(n.pipe ?? [], [t], r, (e) => i(t, r.next({ vars: { [n.name ?? ""]: e } })));
1565
+ },
1566
+ map(e, t) {
1567
+ return {
1568
+ name: e.assertType(t.name, "string"),
1569
+ pipe: R(t.pipe)
1570
+ };
1571
+ }
1572
+ },
1573
+ vod: {
1574
+ op(e, t, n, r, i) {
1575
+ return [];
1576
+ },
1577
+ map(e, t) {
1578
+ return {};
1579
+ }
1580
+ }
1581
+ }, tn = {};
1582
+ function nn(e = {}, t = {}) {
1583
+ return r(e, t);
1584
+ }
1585
+ function z(e) {
1586
+ let t = e?.version, [, n, r] = typeof t == "string" ? /^(\d+)\.(\d+)?$/g.exec(t) ?? [] : [];
1587
+ if (!n || !r || !Array.isArray(e.instructions)) throw new y("invalid program definition");
1588
+ if (+n != 1 || +r > 0) throw new y(`unsupported program definition v${n}.${r} - this version of JPL only supports v1 (up to v${m})`);
1589
+ }
1590
+ var rn = class e {
1591
+ #e;
1592
+ #t;
1593
+ #n;
1594
+ #r;
1595
+ constructor(e, t) {
1596
+ z(e), this.#e = nn(t?.program, tn), this.#t = t?.runtime, this.#n = e, this.#r = en;
1597
+ }
1598
+ get options() {
1599
+ return this.#e;
1600
+ }
1601
+ get definition() {
1602
+ return this.#n;
1603
+ }
1604
+ get ops() {
1605
+ return this.#r;
1606
+ }
1607
+ run = async (e, t) => {
1608
+ let n = new pt(this, { runtime: P(t?.runtime, this.#t) }), r = n.normalizeValues(e, "program inputs"), i = await n.execute(r);
1609
+ return n.stripJSON(i);
1610
+ };
1611
+ prepend = (t) => (z(t), new e({
1612
+ version: m,
1613
+ instructions: [...t.instructions, ...this.definition.instructions]
1614
+ }, {
1615
+ program: this.#e,
1616
+ runtime: this.#t
1617
+ }));
1618
+ append = (t) => (z(t), new e({
1619
+ version: m,
1620
+ instructions: [...this.definition.instructions, ...t.instructions]
1621
+ }, {
1622
+ program: this.#e,
1623
+ runtime: this.#t
1624
+ }));
1625
+ }, an = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", on = "0123456789", sn = `${an}_$`, cn = `${sn}${on}`, ln = cn, un = " \xA0\r\n ", dn = `${on}abcdefABCDEF`;
1626
+ function B(e, t, n) {
1627
+ let r = t, i = !1;
1628
+ for (;;) {
1629
+ let t = V(e, r, n, { phrase: "#" });
1630
+ if (t.is) {
1631
+ for ({i: r} = t;;) {
1632
+ let t = U(e, r, n, { set: "\r\n" });
1633
+ if (t.is) {
1634
+ ({i: r} = t);
1635
+ break;
1636
+ }
1637
+ let i = G(e, r, n);
1638
+ if (i.is) {
1639
+ ({i: r} = i);
1640
+ break;
1641
+ }
1642
+ r += 1;
1643
+ }
1644
+ i = !0;
1645
+ continue;
1646
+ }
1647
+ if (t = V(e, r, n, { phrase: "/*" }), t.is) {
1648
+ for ({i: r} = t;;) {
1649
+ if (t = V(e, r, n, { phrase: "*/" }), t.is) {
1650
+ ({i: r} = t);
1651
+ break;
1652
+ }
1653
+ let i = G(e, r, n);
1654
+ if (i.is) return {i: r} = i, K(e, r, n, {
1655
+ operator: "comment",
1656
+ message: "incomplete comment"
1657
+ });
1658
+ r += 1;
1659
+ }
1660
+ i = !0;
1661
+ continue;
1662
+ }
1663
+ let a = U(e, r, n, { set: un });
1664
+ if ({i: r} = a, !a.is) break;
1665
+ i = !0;
1666
+ }
1667
+ return {
1668
+ i: r,
1669
+ is: i
1670
+ };
1671
+ }
1672
+ function V(e, t, n, { phrase: r, notBeforeSet: i, spaceBefore: a, spaceAfter: o }) {
1673
+ let s = t;
1674
+ if (a && t > 0 && !U(e, s - 1, n, {
1675
+ set: ln,
1676
+ exclusive: !0
1677
+ }).is) return {
1678
+ i: s,
1679
+ is: !1
1680
+ };
1681
+ for (let t = 0; t < r.length; t += 1, s += 1) {
1682
+ let i = G(e, s, n);
1683
+ if (i.is || e[s] !== r[t]) return {
1684
+ i: i.i,
1685
+ is: !1
1686
+ };
1687
+ }
1688
+ return !G(e, s, n).is && (i && U(e, s, n, { set: i }).is || o && !U(e, s, n, {
1689
+ set: ln,
1690
+ exclusive: !0
1691
+ }).is) ? {
1692
+ i: s,
1693
+ is: !1
1694
+ } : {
1695
+ i: s,
1696
+ is: !0
1697
+ };
1698
+ }
1699
+ function H(e, t, n, { phrase: r, notBeforeSet: i, spaceBefore: a, spaceAfter: o }) {
1700
+ let s = t, c = V(e, s, n, {
1701
+ phrase: r,
1702
+ notBeforeSet: i,
1703
+ spaceBefore: a,
1704
+ spaceAfter: o
1705
+ });
1706
+ return c.is ? ({i: s} = c, {i: s} = B(e, s, n), {
1707
+ i: s,
1708
+ is: !0
1709
+ }) : {
1710
+ i: c.i,
1711
+ is: !1
1712
+ };
1713
+ }
1714
+ function fn(e, t, n) {
1715
+ return U(e, t, n, { set: dn });
1716
+ }
1717
+ function U(e, t, n, { set: r, exclusive: i }) {
1718
+ let a = G(e, t, n);
1719
+ if (a.is) return {
1720
+ i: a.i,
1721
+ is: !1,
1722
+ value: ""
1723
+ };
1724
+ let o = e[t];
1725
+ return r.includes(o) === !i ? {
1726
+ i: t + 1,
1727
+ is: !0,
1728
+ value: o
1729
+ } : {
1730
+ i: t,
1731
+ is: !1,
1732
+ value: ""
1733
+ };
1734
+ }
1735
+ function pn(e, t, n) {
1736
+ let r = t, i = !1, a = "";
1737
+ for (;;) {
1738
+ let t = U(e, r, n, { set: i ? cn : sn });
1739
+ if ({i: r} = t, !t.is) break;
1740
+ i = !0, a += t.value;
1741
+ }
1742
+ return i && ({i: r} = B(e, r, n)), {
1743
+ i: r,
1744
+ is: i,
1745
+ value: a
1746
+ };
1747
+ }
1748
+ function W(e, t, n) {
1749
+ let r = pn(e, t, n);
1750
+ if (!r.is) return r;
1751
+ switch (r.value) {
1752
+ case "and":
1753
+ case "catch":
1754
+ case "func":
1755
+ case "elif":
1756
+ case "else":
1757
+ case "end":
1758
+ case "false":
1759
+ case "if":
1760
+ case "not":
1761
+ case "null":
1762
+ case "or":
1763
+ case "then":
1764
+ case "true":
1765
+ case "try": return {
1766
+ i: t,
1767
+ is: !1,
1768
+ value: r.value,
1769
+ reserved: !0
1770
+ };
1771
+ default: return r;
1772
+ }
1773
+ }
1774
+ function G(e, t, n) {
1775
+ return t >= e.length ? {
1776
+ i: e.length,
1777
+ is: !0
1778
+ } : {
1779
+ i: t,
1780
+ is: !1
1781
+ };
1782
+ }
1783
+ function mn(e, t, n) {
1784
+ let r = e.substring(0, t).split(/\r?\n|\r/), i = r[r.length - 1];
1785
+ return {
1786
+ i: t,
1787
+ line: r.length - 1,
1788
+ column: i.length
1789
+ };
1790
+ }
1791
+ function hn(e, t, n, { area: r = 25 } = {}) {
1792
+ let i = Math.max(Math.min(t, e.length - 1 - r), r) - r, a = Math.min(i + r + 1 + r, e.length), o = e.substring(i, a).replaceAll(/\r?\n|\r/g, "⏎").replaceAll(" ", "→"), s = " > ";
1793
+ i > 0 && (s += "…");
1794
+ let c = "";
1795
+ return a < e.length && (c = "…"), {
1796
+ i: t,
1797
+ value: `${s}${o}${c}\n${" ".repeat(s.length + (t - i))}^ here`
1798
+ };
1799
+ }
1800
+ function K(e, t, n, { operator: r, message: i } = {}) {
1801
+ let a;
1802
+ if (G(e, t, n).is) a = "unexpected EOT";
1803
+ else {
1804
+ let { line: r, column: i } = mn(e, t, n);
1805
+ a = `unexpected token '${e[t]}' at line ${r + 1}, column ${i + 1}`;
1806
+ }
1807
+ throw r && (a += ` while parsing ${r}`), i && (a += `: ${i}`), a += `\n${hn(e, t, n).value}`, new nt(a, e, t);
1808
+ }
1809
+ function gn(e, t, n, { operator: r, message: i } = {}) {
1810
+ let a = "error";
1811
+ throw r && (a += ` while parsing ${r}`), i && (a += `: ${i}`), a += `\n${hn(e, t, n).value}`, new nt(a, e, t);
1812
+ }
1813
+ //#endregion
1814
+ //#region lib/interpreter/parse.ts
1815
+ async function _n(e, t, n) {
1816
+ let r = t, i = await vn(e, r, n);
1817
+ return {i: r} = i, G(e, r, n).is ? i : K(e, r, n, {
1818
+ operator: "program",
1819
+ message: "expected EOT"
1820
+ });
1821
+ }
1822
+ function vn(e, t, n) {
1823
+ let r = t;
1824
+ return {i: r} = B(e, r, n), q(e, r, n);
1825
+ }
1826
+ function yn(e, t, n) {
1827
+ let r = t, i = H(e, r, n, { phrase: "(" });
1828
+ if ({i: r} = i, !i.is) return K(e, r, n, {
1829
+ operator: "function definition",
1830
+ message: "expected '('"
1831
+ });
1832
+ let a = [];
1833
+ if (i = H(e, r, n, { phrase: ")" }), i.is) ({i: r} = i);
1834
+ else for (;;) {
1835
+ let t = W(e, r, n);
1836
+ if (!t.is) return K(e, r, n, {
1837
+ operator: "function definition",
1838
+ message: "expected argument name"
1839
+ });
1840
+ let o;
1841
+ if ({i: r, value: o} = t, a.push(o), i = H(e, r, n, { phrase: ")" }), i.is) {
1842
+ ({i: r} = i);
1843
+ break;
1844
+ }
1845
+ if (i = H(e, r, n, { phrase: "," }), {i: r} = i, !i.is) return K(e, r, n, {
1846
+ operator: "function definition",
1847
+ message: "expected ',' or ')'"
1848
+ });
1849
+ }
1850
+ return i = H(e, r, n, { phrase: ":" }), {i: r} = i, i.is ? {
1851
+ i: r,
1852
+ argNames: a
1853
+ } : K(e, r, n, {
1854
+ operator: "function definition",
1855
+ message: "expected ':'"
1856
+ });
1857
+ }
1858
+ async function bn(e, t, n, { identity: r } = {}) {
1859
+ let i = t, a = [], o = !0;
1860
+ for (;;) {
1861
+ let t = H(e, i, n, { phrase: "." });
1862
+ if (!(r && a.length === 0) && t.is) {
1863
+ ({i: i} = t);
1864
+ let r = W(e, i, n);
1865
+ if (!r.is) return K(e, i, n, {
1866
+ operator: "field access operator",
1867
+ message: "expected field name"
1868
+ });
1869
+ let o;
1870
+ ({i: i, value: o} = r);
1871
+ let s = !1;
1872
+ t = H(e, i, n, {
1873
+ phrase: "?",
1874
+ notBeforeSet: "?="
1875
+ }), t.is && ({i: i, is: s} = t), a.push({
1876
+ op: "$.$",
1877
+ params: {
1878
+ pipe: [{
1879
+ op: "\"\"",
1880
+ params: { string: o }
1881
+ }],
1882
+ optional: s
1883
+ }
1884
+ });
1885
+ continue;
1886
+ }
1887
+ if (t = H(e, i, n, { phrase: "[" }), t.is) {
1888
+ if ({i: i} = t, t = H(e, i, n, { phrase: "]" }), t.is) {
1889
+ ({i: i} = t);
1890
+ let r = !1;
1891
+ t = H(e, i, n, {
1892
+ phrase: "?",
1893
+ notBeforeSet: "?="
1894
+ }), t.is && ({i: i, is: r} = t), a.push({
1895
+ op: "$[]",
1896
+ params: { optional: r }
1897
+ });
1898
+ continue;
1899
+ }
1900
+ if (t = H(e, i, n, { phrase: ":" }), t.is) {
1901
+ if ({i: i} = t, t = H(e, i, n, { phrase: "]" }), t.is) {
1902
+ ({i: i} = t);
1903
+ let r = !1;
1904
+ t = H(e, i, n, {
1905
+ phrase: "?",
1906
+ notBeforeSet: "?="
1907
+ }), t.is && ({i: i, is: r} = t), a.push({
1908
+ op: "[:]",
1909
+ params: {
1910
+ from: [{
1911
+ op: "nul",
1912
+ params: {}
1913
+ }],
1914
+ to: [{
1915
+ op: "nul",
1916
+ params: {}
1917
+ }],
1918
+ optional: r
1919
+ }
1920
+ });
1921
+ continue;
1922
+ }
1923
+ let r;
1924
+ if ({i: i, ops: r} = await q(e, i, n), t = H(e, i, n, { phrase: "]" }), {i: i} = t, !t.is) return K(e, i, n, {
1925
+ operator: "array slice operator",
1926
+ message: "expected ']'"
1927
+ });
1928
+ let o = !1;
1929
+ t = H(e, i, n, {
1930
+ phrase: "?",
1931
+ notBeforeSet: "?="
1932
+ }), t.is && ({i: i, is: o} = t), a.push({
1933
+ op: "[:]",
1934
+ params: {
1935
+ from: [{
1936
+ op: "nul",
1937
+ params: {}
1938
+ }],
1939
+ to: r,
1940
+ optional: o
1941
+ }
1942
+ });
1943
+ continue;
1944
+ }
1945
+ let r;
1946
+ if ({i: i, ops: r} = await q(e, i, n), t = H(e, i, n, { phrase: "]" }), t.is) {
1947
+ ({i: i} = t);
1948
+ let o = !1;
1949
+ t = H(e, i, n, {
1950
+ phrase: "?",
1951
+ notBeforeSet: "?="
1952
+ }), t.is && ({i: i, is: o} = t), a.push({
1953
+ op: "$.$",
1954
+ params: {
1955
+ pipe: r,
1956
+ optional: o
1957
+ }
1958
+ });
1959
+ continue;
1960
+ }
1961
+ if (t = H(e, i, n, { phrase: ":" }), !t.is) return K(e, i, n, {
1962
+ operator: "variable access operator",
1963
+ message: "expected ':' or ']'"
1964
+ });
1965
+ if ({i: i} = t, t = H(e, i, n, { phrase: "]" }), t.is) {
1966
+ ({i: i} = t);
1967
+ let o = !1;
1968
+ t = H(e, i, n, {
1969
+ phrase: "?",
1970
+ notBeforeSet: "?="
1971
+ }), t.is && ({i: i, is: o} = t), a.push({
1972
+ op: "[:]",
1973
+ params: {
1974
+ from: r,
1975
+ to: [{
1976
+ op: "nul",
1977
+ params: {}
1978
+ }],
1979
+ optional: o
1980
+ }
1981
+ });
1982
+ continue;
1983
+ }
1984
+ let o;
1985
+ if ({i: i, ops: o} = await q(e, i, n), t = H(e, i, n, { phrase: "]" }), {i: i} = t, !t.is) return K(e, i, n, {
1986
+ operator: "array slice operator",
1987
+ message: "expected ']'"
1988
+ });
1989
+ let s = !1;
1990
+ t = H(e, i, n, {
1991
+ phrase: "?",
1992
+ notBeforeSet: "?="
1993
+ }), t.is && ({i: i, is: s} = t), a.push({
1994
+ op: "[:]",
1995
+ params: {
1996
+ from: r,
1997
+ to: o,
1998
+ optional: s
1999
+ }
2000
+ });
2001
+ continue;
2002
+ }
2003
+ let s = !1;
2004
+ if (t = H(e, i, n, { phrase: "->" }), t.is && ({i: i, is: s} = t), t = H(e, i, n, { phrase: "(" }), !t.is && s) return K(e, i, n, {
2005
+ operator: "bound function call",
2006
+ message: "expected '('"
2007
+ });
2008
+ if (t.is) {
2009
+ ({i: i} = t);
2010
+ let r = [];
2011
+ if (t = H(e, i, n, { phrase: ")" }), t.is) ({i: i} = t);
2012
+ else for (;;) {
2013
+ let a;
2014
+ if ({i: i, ops: a} = await J(e, i, n), r.push(a), t = H(e, i, n, { phrase: ")" }), t.is) {
2015
+ ({i: i} = t);
2016
+ break;
2017
+ }
2018
+ if (t = H(e, i, n, { phrase: "," }), {i: i} = t, !t.is) return K(e, i, n, {
2019
+ operator: "function call",
2020
+ message: "expected ',' or ')'"
2021
+ });
2022
+ }
2023
+ let c = !1;
2024
+ t = H(e, i, n, {
2025
+ phrase: "?",
2026
+ notBeforeSet: "?="
2027
+ }), t.is && ({i: i, is: c} = t), a.push({
2028
+ op: "$()",
2029
+ params: {
2030
+ args: r,
2031
+ bound: s,
2032
+ optional: c
2033
+ }
2034
+ }), o = !1;
2035
+ continue;
2036
+ }
2037
+ break;
2038
+ }
2039
+ return {
2040
+ i,
2041
+ is: a.length > 0,
2042
+ selectors: a,
2043
+ canAssign: o
2044
+ };
2045
+ }
2046
+ async function xn(e, t, n) {
2047
+ let r = t, i = H(e, r, n, {
2048
+ phrase: "=",
2049
+ notBeforeSet: "="
2050
+ });
2051
+ if (i.is) {
2052
+ ({i: r} = i);
2053
+ let t;
2054
+ return {i: r, ops: t} = await Y(e, r, n), {
2055
+ i: r,
2056
+ is: !0,
2057
+ assignment: {
2058
+ op: "=",
2059
+ params: { pipe: t }
2060
+ }
2061
+ };
2062
+ }
2063
+ if (i = H(e, r, n, { phrase: "|=" }), i.is) {
2064
+ ({i: r} = i);
2065
+ let t;
2066
+ return {i: r, ops: t} = await Y(e, r, n), {
2067
+ i: r,
2068
+ is: !0,
2069
+ assignment: {
2070
+ op: "|=",
2071
+ params: { pipe: t }
2072
+ }
2073
+ };
2074
+ }
2075
+ if (i = H(e, r, n, { phrase: "+=" }), i.is) {
2076
+ ({i: r} = i);
2077
+ let t;
2078
+ return {i: r, ops: t} = await Y(e, r, n), {
2079
+ i: r,
2080
+ is: !0,
2081
+ assignment: {
2082
+ op: "+=",
2083
+ params: { pipe: t }
2084
+ }
2085
+ };
2086
+ }
2087
+ if (i = H(e, r, n, { phrase: "-=" }), i.is) {
2088
+ ({i: r} = i);
2089
+ let t;
2090
+ return {i: r, ops: t} = await Y(e, r, n), {
2091
+ i: r,
2092
+ is: !0,
2093
+ assignment: {
2094
+ op: "-=",
2095
+ params: { pipe: t }
2096
+ }
2097
+ };
2098
+ }
2099
+ if (i = H(e, r, n, { phrase: "*=" }), i.is) {
2100
+ ({i: r} = i);
2101
+ let t;
2102
+ return {i: r, ops: t} = await Y(e, r, n), {
2103
+ i: r,
2104
+ is: !0,
2105
+ assignment: {
2106
+ op: "*=",
2107
+ params: { pipe: t }
2108
+ }
2109
+ };
2110
+ }
2111
+ if (i = H(e, r, n, { phrase: "/=" }), i.is) {
2112
+ ({i: r} = i);
2113
+ let t;
2114
+ return {i: r, ops: t} = await Y(e, r, n), {
2115
+ i: r,
2116
+ is: !0,
2117
+ assignment: {
2118
+ op: "/=",
2119
+ params: { pipe: t }
2120
+ }
2121
+ };
2122
+ }
2123
+ if (i = H(e, r, n, { phrase: "%=" }), i.is) {
2124
+ ({i: r} = i);
2125
+ let t;
2126
+ return {i: r, ops: t} = await Y(e, r, n), {
2127
+ i: r,
2128
+ is: !0,
2129
+ assignment: {
2130
+ op: "%=",
2131
+ params: { pipe: t }
2132
+ }
2133
+ };
2134
+ }
2135
+ if (i = H(e, r, n, { phrase: "?=" }), i.is) {
2136
+ ({i: r} = i);
2137
+ let t;
2138
+ return {i: r, ops: t} = await Y(e, r, n), {
2139
+ i: r,
2140
+ is: !0,
2141
+ assignment: {
2142
+ op: "?=",
2143
+ params: { pipe: t }
2144
+ }
2145
+ };
2146
+ }
2147
+ return {
2148
+ i: r,
2149
+ is: !1
2150
+ };
2151
+ }
2152
+ function Sn(e, t, n) {
2153
+ let r = t, i = !1, a = "";
2154
+ for (;;) {
2155
+ let t = U(e, r, n, { set: "0123456789" });
2156
+ if (!t.is) break;
2157
+ ({i: r} = t), i = !0, a += t.value;
2158
+ }
2159
+ if (!i) return {
2160
+ i: r,
2161
+ is: !1
2162
+ };
2163
+ let o = V(e, r, n, { phrase: "." });
2164
+ if (o.is) for ({i: r} = o, a += ".";;) {
2165
+ let t = U(e, r, n, { set: "0123456789" });
2166
+ if (!t.is) break;
2167
+ ({i: r} = t), a += t.value;
2168
+ }
2169
+ let s = U(e, r, n, { set: "eE" });
2170
+ if (s.is) {
2171
+ ({i: r} = s), a += s.value, s = U(e, r, n, { set: "+-" }), s.is && ({i: r} = s, a += s.value);
2172
+ let t = !1;
2173
+ for (; s = U(e, r, n, { set: "0123456789" }), s.is;) ({i: r} = s), t = !0, a += s.value;
2174
+ if (!t) return K(e, r, n, {
2175
+ operator: "number",
2176
+ message: "expected digit"
2177
+ });
2178
+ }
2179
+ let c = +a;
2180
+ return Number.isFinite(c) ? ({i: r} = B(e, r, n), {
2181
+ i: r,
2182
+ is: !0,
2183
+ ops: [{
2184
+ op: "nbr",
2185
+ params: { number: c }
2186
+ }]
2187
+ }) : gn(e, r, n, {
2188
+ operator: "number",
2189
+ message: `invalid number ${c}`
2190
+ });
2191
+ }
2192
+ async function Cn(e, t, n) {
2193
+ let r = t, i = "", a = U(e, r, n, { set: "\"'`" });
2194
+ if (!a.is) return {
2195
+ i: r,
2196
+ is: !1
2197
+ };
2198
+ let o;
2199
+ ({i: r, value: o} = a);
2200
+ let s = o === "`", c = [];
2201
+ for (;;) {
2202
+ let t = V(e, r, n, { phrase: o });
2203
+ if (t.is) {
2204
+ ({i: r} = t);
2205
+ break;
2206
+ }
2207
+ let a = G(e, r, n);
2208
+ if (a.is) return {i: r} = a, K(e, r, n, {
2209
+ operator: "string",
2210
+ message: "incomplete string literal"
2211
+ });
2212
+ if (t = V(e, r, n, { phrase: "\\" }), t.is) {
2213
+ if ({i: r} = t, t = H(e, r, n, { phrase: "(" }), t.is) {
2214
+ ({i: r} = t);
2215
+ let a;
2216
+ if ({i: r, ops: a} = await q(e, r, n), t = V(e, r, n, { phrase: ")" }), {i: r} = t, !t.is) return K(e, r, n, {
2217
+ operator: "string interpolation",
2218
+ message: "expected ')'"
2219
+ });
2220
+ c.push({
2221
+ before: i,
2222
+ pipe: a
2223
+ }), i = "";
2224
+ continue;
2225
+ }
2226
+ if (s) switch (e[r]) {
2227
+ case "\n":
2228
+ r += 1;
2229
+ continue;
2230
+ case "\r":
2231
+ r += 1, !G(e, r, n).is && e[r] === "\n" && (r += 1);
2232
+ continue;
2233
+ default:
2234
+ }
2235
+ switch (e[r]) {
2236
+ case "\"":
2237
+ i += "\"", r += 1;
2238
+ continue;
2239
+ case "'":
2240
+ i += "'", r += 1;
2241
+ continue;
2242
+ case "`":
2243
+ i += "`", r += 1;
2244
+ continue;
2245
+ case "\\":
2246
+ i += "\\", r += 1;
2247
+ continue;
2248
+ case "/":
2249
+ i += "/", r += 1;
2250
+ continue;
2251
+ case "b":
2252
+ i += "\b", r += 1;
2253
+ continue;
2254
+ case "f":
2255
+ i += "\f", r += 1;
2256
+ continue;
2257
+ case "n":
2258
+ i += "\n", r += 1;
2259
+ continue;
2260
+ case "r":
2261
+ i += "\r", r += 1;
2262
+ continue;
2263
+ case "t":
2264
+ i += " ", r += 1;
2265
+ continue;
2266
+ case "u": {
2267
+ r += 1;
2268
+ let a = "";
2269
+ for (let i = 0; i < 4; i += 1) {
2270
+ if (t = fn(e, r, n), {i: r} = t, !t.is) return K(e, r, n, {
2271
+ operator: "string",
2272
+ message: "incomplete unicode escape sequence: expected hex digit"
2273
+ });
2274
+ a += t.value;
2275
+ }
2276
+ i += String.fromCodePoint(parseInt(a, 16));
2277
+ continue;
2278
+ }
2279
+ default: return K(e, r, n, {
2280
+ operator: "string",
2281
+ message: "invalid escape sequence"
2282
+ });
2283
+ }
2284
+ }
2285
+ if (s) switch (e[r]) {
2286
+ case "\n":
2287
+ case "\r":
2288
+ case " ":
2289
+ i += e[r], r += 1;
2290
+ continue;
2291
+ default:
2292
+ }
2293
+ if (e.charCodeAt(r) < 32) return K(e, r, n, { operator: "string" });
2294
+ i += e[r], r += 1;
2295
+ }
2296
+ return {i: r} = B(e, r, n), c.length === 0 ? {
2297
+ i: r,
2298
+ is: !0,
2299
+ ops: [{
2300
+ op: "\"\"",
2301
+ params: { string: i }
2302
+ }]
2303
+ } : {
2304
+ i: r,
2305
+ is: !0,
2306
+ ops: [{
2307
+ op: "\"$\"",
2308
+ params: {
2309
+ interpolations: c,
2310
+ after: i
2311
+ }
2312
+ }]
2313
+ };
2314
+ }
2315
+ async function q(e, t, n) {
2316
+ await void 0;
2317
+ let r = t, i = [];
2318
+ for (;;) {
2319
+ let t;
2320
+ ({i: r, ops: t} = await wn(e, r, n)), i.push(...t);
2321
+ let a = H(e, r, n, {
2322
+ phrase: "|",
2323
+ notBeforeSet: "="
2324
+ });
2325
+ if (!a.is) break;
2326
+ ({i: r} = a);
2327
+ }
2328
+ return {
2329
+ i: r,
2330
+ ops: i
2331
+ };
2332
+ }
2333
+ async function J(e, t, n) {
2334
+ await void 0;
2335
+ let r = t, i = [];
2336
+ for (;;) {
2337
+ let t;
2338
+ ({i: r, ops: t} = await X(e, r, n)), i.push(...t);
2339
+ let a = H(e, r, n, {
2340
+ phrase: "|",
2341
+ notBeforeSet: "="
2342
+ });
2343
+ if (!a.is) break;
2344
+ ({i: r} = a);
2345
+ }
2346
+ return {
2347
+ i: r,
2348
+ ops: i
2349
+ };
2350
+ }
2351
+ async function Y(e, t, n) {
2352
+ return await void 0, X(e, t, n);
2353
+ }
2354
+ async function wn(e, t, n) {
2355
+ let r = t, i = [];
2356
+ for (;;) {
2357
+ let t;
2358
+ ({i: r, ops: t} = await X(e, r, n)), i.push(t);
2359
+ let a = H(e, r, n, { phrase: "," });
2360
+ if (!a.is) break;
2361
+ ({i: r} = a);
2362
+ }
2363
+ return i.length === 1 ? {
2364
+ i: r,
2365
+ ops: i[0]
2366
+ } : {
2367
+ i: r,
2368
+ ops: [{
2369
+ op: ",",
2370
+ params: { pipes: i }
2371
+ }]
2372
+ };
2373
+ }
2374
+ async function X(e, t, n) {
2375
+ let r = t, i = H(e, r, n, {
2376
+ phrase: "try",
2377
+ spaceAfter: !0
2378
+ });
2379
+ if (!i.is) return Tn(e, r, n);
2380
+ ({i: r} = i);
2381
+ let a;
2382
+ ({i: r, ops: a} = await Tn(e, r, n));
2383
+ let o;
2384
+ return i = H(e, r, n, {
2385
+ spaceBefore: !0,
2386
+ phrase: "catch",
2387
+ spaceAfter: !0
2388
+ }), i.is ? ({i: r} = i, {i: r, ops: o} = await Tn(e, r, n)) : o = [{
2389
+ op: "vod",
2390
+ params: {}
2391
+ }], {
2392
+ i: r,
2393
+ ops: [{
2394
+ op: "try",
2395
+ params: {
2396
+ try: a,
2397
+ catch: o
2398
+ }
2399
+ }]
2400
+ };
2401
+ }
2402
+ async function Tn(e, t, n) {
2403
+ let r = t, i = [];
2404
+ for (;;) {
2405
+ let t;
2406
+ ({i: r, ops: t} = await En(e, r, n)), i.push(t);
2407
+ let a = H(e, r, n, {
2408
+ spaceBefore: !0,
2409
+ phrase: "or",
2410
+ spaceAfter: !0
2411
+ });
2412
+ if (!a.is) break;
2413
+ ({i: r} = a);
2414
+ }
2415
+ return i.length === 1 ? {
2416
+ i: r,
2417
+ ops: i[0]
2418
+ } : {
2419
+ i: r,
2420
+ ops: [{
2421
+ op: "or",
2422
+ params: { pipes: i }
2423
+ }]
2424
+ };
2425
+ }
2426
+ async function En(e, t, n) {
2427
+ let r = t, i = [];
2428
+ for (;;) {
2429
+ let t;
2430
+ ({i: r, ops: t} = await Dn(e, r, n)), i.push(t);
2431
+ let a = H(e, r, n, {
2432
+ spaceBefore: !0,
2433
+ phrase: "and",
2434
+ spaceAfter: !0
2435
+ });
2436
+ if (!a.is) break;
2437
+ ({i: r} = a);
2438
+ }
2439
+ return i.length === 1 ? {
2440
+ i: r,
2441
+ ops: i[0]
2442
+ } : {
2443
+ i: r,
2444
+ ops: [{
2445
+ op: "and",
2446
+ params: { pipes: i }
2447
+ }]
2448
+ };
2449
+ }
2450
+ async function Dn(e, t, n) {
2451
+ let r = t, i;
2452
+ ({i: r, ops: i} = await On(e, r, n));
2453
+ let a = [];
2454
+ for (;;) {
2455
+ let t = H(e, r, n, { phrase: "==" });
2456
+ if (t.is) {
2457
+ ({i: r} = t);
2458
+ let i;
2459
+ ({i: r, ops: i} = await On(e, r, n)), a.push({
2460
+ op: "==",
2461
+ params: { by: i }
2462
+ });
2463
+ continue;
2464
+ }
2465
+ if (t = H(e, r, n, { phrase: "!=" }), t.is) {
2466
+ ({i: r} = t);
2467
+ let i;
2468
+ ({i: r, ops: i} = await On(e, r, n)), a.push({
2469
+ op: "!=",
2470
+ params: { by: i }
2471
+ });
2472
+ continue;
2473
+ }
2474
+ break;
2475
+ }
2476
+ return a.length === 0 ? {
2477
+ i: r,
2478
+ ops: i
2479
+ } : {
2480
+ i: r,
2481
+ ops: [{
2482
+ op: "cmp",
2483
+ params: {
2484
+ pipe: i,
2485
+ comparisons: a
2486
+ }
2487
+ }]
2488
+ };
2489
+ }
2490
+ async function On(e, t, n) {
2491
+ let r = t, i;
2492
+ ({i: r, ops: i} = await Z(e, r, n));
2493
+ let a = [];
2494
+ for (;;) {
2495
+ let t = H(e, r, n, { phrase: "<=" });
2496
+ if (t.is) {
2497
+ ({i: r} = t);
2498
+ let i;
2499
+ ({i: r, ops: i} = await Z(e, r, n)), a.push({
2500
+ op: "<=",
2501
+ params: { by: i }
2502
+ });
2503
+ continue;
2504
+ }
2505
+ if (t = H(e, r, n, { phrase: "<" }), t.is) {
2506
+ ({i: r} = t);
2507
+ let i;
2508
+ ({i: r, ops: i} = await Z(e, r, n)), a.push({
2509
+ op: "<",
2510
+ params: { by: i }
2511
+ });
2512
+ continue;
2513
+ }
2514
+ if (t = H(e, r, n, { phrase: ">=" }), t.is) {
2515
+ ({i: r} = t);
2516
+ let i;
2517
+ ({i: r, ops: i} = await Z(e, r, n)), a.push({
2518
+ op: ">=",
2519
+ params: { by: i }
2520
+ });
2521
+ continue;
2522
+ }
2523
+ if (t = H(e, r, n, { phrase: ">" }), t.is) {
2524
+ ({i: r} = t);
2525
+ let i;
2526
+ ({i: r, ops: i} = await Z(e, r, n)), a.push({
2527
+ op: ">",
2528
+ params: { by: i }
2529
+ });
2530
+ continue;
2531
+ }
2532
+ break;
2533
+ }
2534
+ return a.length === 0 ? {
2535
+ i: r,
2536
+ ops: i
2537
+ } : {
2538
+ i: r,
2539
+ ops: [{
2540
+ op: "cmp",
2541
+ params: {
2542
+ pipe: i,
2543
+ comparisons: a
2544
+ }
2545
+ }]
2546
+ };
2547
+ }
2548
+ async function Z(e, t, n) {
2549
+ let r = t, i = H(e, r, n, {
2550
+ phrase: "not",
2551
+ spaceAfter: !0
2552
+ });
2553
+ if (!i.is) return kn(e, r, n);
2554
+ ({i: r} = i);
2555
+ let a;
2556
+ return {i: r, ops: a} = await kn(e, r, n), {
2557
+ i: r,
2558
+ ops: [...a, {
2559
+ op: "not",
2560
+ params: {}
2561
+ }]
2562
+ };
2563
+ }
2564
+ async function kn(e, t, n) {
2565
+ let r = t, i = await An(e, r, n);
2566
+ ({i: r} = i);
2567
+ let a = H(e, r, n, {
2568
+ phrase: "?",
2569
+ notBeforeSet: "?="
2570
+ });
2571
+ return a.is ? ({i: r} = a, {
2572
+ i: r,
2573
+ ops: [{
2574
+ op: "try",
2575
+ params: {
2576
+ try: i.ops,
2577
+ catch: [{
2578
+ op: "vod",
2579
+ params: {}
2580
+ }]
2581
+ }
2582
+ }]
2583
+ }) : i;
2584
+ }
2585
+ async function An(e, t, n) {
2586
+ let r = t, i;
2587
+ ({i: r, ops: i} = await jn(e, r, n));
2588
+ let a = [];
2589
+ for (;;) {
2590
+ let t = H(e, r, n, {
2591
+ phrase: "+",
2592
+ notBeforeSet: "="
2593
+ });
2594
+ if (t.is) {
2595
+ ({i: r} = t);
2596
+ let i;
2597
+ ({i: r, ops: i} = await jn(e, r, n)), a.push({
2598
+ op: "+",
2599
+ params: { by: i }
2600
+ });
2601
+ continue;
2602
+ }
2603
+ if (t = H(e, r, n, {
2604
+ phrase: "-",
2605
+ notBeforeSet: "=>"
2606
+ }), t.is) {
2607
+ ({i: r} = t);
2608
+ let i;
2609
+ ({i: r, ops: i} = await jn(e, r, n)), a.push({
2610
+ op: "-",
2611
+ params: { by: i }
2612
+ });
2613
+ continue;
2614
+ }
2615
+ break;
2616
+ }
2617
+ return a.length === 0 ? {
2618
+ i: r,
2619
+ ops: i
2620
+ } : {
2621
+ i: r,
2622
+ ops: [{
2623
+ op: "clc",
2624
+ params: {
2625
+ pipe: i,
2626
+ operations: a
2627
+ }
2628
+ }]
2629
+ };
2630
+ }
2631
+ async function jn(e, t, n) {
2632
+ let r = t, i;
2633
+ ({i: r, ops: i} = await Q(e, r, n));
2634
+ let a = [];
2635
+ for (;;) {
2636
+ let t = H(e, r, n, {
2637
+ phrase: "*",
2638
+ notBeforeSet: "="
2639
+ });
2640
+ if (t.is) {
2641
+ ({i: r} = t);
2642
+ let i;
2643
+ ({i: r, ops: i} = await Q(e, r, n)), a.push({
2644
+ op: "*",
2645
+ params: { by: i }
2646
+ });
2647
+ continue;
2648
+ }
2649
+ if (t = H(e, r, n, {
2650
+ phrase: "/",
2651
+ notBeforeSet: "="
2652
+ }), t.is) {
2653
+ ({i: r} = t);
2654
+ let i;
2655
+ ({i: r, ops: i} = await Q(e, r, n)), a.push({
2656
+ op: "/",
2657
+ params: { by: i }
2658
+ });
2659
+ continue;
2660
+ }
2661
+ if (t = H(e, r, n, {
2662
+ phrase: "%",
2663
+ notBeforeSet: "="
2664
+ }), t.is) {
2665
+ ({i: r} = t);
2666
+ let i;
2667
+ ({i: r, ops: i} = await Q(e, r, n)), a.push({
2668
+ op: "%",
2669
+ params: { by: i }
2670
+ });
2671
+ continue;
2672
+ }
2673
+ break;
2674
+ }
2675
+ return a.length === 0 ? {
2676
+ i: r,
2677
+ ops: i
2678
+ } : {
2679
+ i: r,
2680
+ ops: [{
2681
+ op: "clc",
2682
+ params: {
2683
+ pipe: i,
2684
+ operations: a
2685
+ }
2686
+ }]
2687
+ };
2688
+ }
2689
+ async function Q(e, t, n) {
2690
+ let r = t, i = [];
2691
+ for (;;) {
2692
+ let t;
2693
+ ({i: r, ops: t} = await Mn(e, r, n)), i.push(t);
2694
+ let a = H(e, r, n, { phrase: "??" });
2695
+ if (!a.is) break;
2696
+ ({i: r} = a);
2697
+ }
2698
+ return i.length === 1 ? {
2699
+ i: r,
2700
+ ops: i[0]
2701
+ } : {
2702
+ i: r,
2703
+ ops: [{
2704
+ op: "??",
2705
+ params: { pipes: i }
2706
+ }]
2707
+ };
2708
+ }
2709
+ async function Mn(e, t, n) {
2710
+ let r = t, i = H(e, r, n, {
2711
+ phrase: "-",
2712
+ notBeforeSet: "=>"
2713
+ });
2714
+ if (!i.is) return Nn(e, r, n);
2715
+ ({i: r} = i);
2716
+ let a;
2717
+ return {i: r, ops: a} = await Nn(e, r, n), {
2718
+ i: r,
2719
+ ops: [...a, {
2720
+ op: "neg",
2721
+ params: {}
2722
+ }]
2723
+ };
2724
+ }
2725
+ async function Nn(e, t, n) {
2726
+ let r = t, i = H(e, r, n, {
2727
+ phrase: "if",
2728
+ spaceAfter: !0
2729
+ });
2730
+ if (!i.is) return Pn(e, r, n);
2731
+ ({i: r} = i);
2732
+ let a = [];
2733
+ for (;;) {
2734
+ let t;
2735
+ if ({i: r, ops: t} = await q(e, r, n), i = H(e, r, n, {
2736
+ spaceBefore: !0,
2737
+ phrase: "then",
2738
+ spaceAfter: !0
2739
+ }), {i: r} = i, !i.is) return K(e, r, n, {
2740
+ operator: "if statement",
2741
+ message: "expected 'then'"
2742
+ });
2743
+ let o;
2744
+ if ({i: r, ops: o} = await q(e, r, n), a.push({
2745
+ if: t,
2746
+ then: o
2747
+ }), i = H(e, r, n, {
2748
+ spaceBefore: !0,
2749
+ phrase: "elif",
2750
+ spaceAfter: !0
2751
+ }), !i.is) break;
2752
+ ({i: r} = i);
2753
+ }
2754
+ let o;
2755
+ return i = H(e, r, n, {
2756
+ spaceBefore: !0,
2757
+ phrase: "else",
2758
+ spaceAfter: !0
2759
+ }), i.is ? ({i: r} = i, {i: r, ops: o} = await q(e, r, n)) : o = [], i = H(e, r, n, {
2760
+ spaceBefore: !0,
2761
+ phrase: "end"
2762
+ }), {i: r} = i, i.is ? {
2763
+ i: r,
2764
+ ops: [{
2765
+ op: "if",
2766
+ params: {
2767
+ ifs: a,
2768
+ else: o
2769
+ }
2770
+ }]
2771
+ } : K(e, r, n, {
2772
+ operator: "if statement",
2773
+ message: "expected 'end'"
2774
+ });
2775
+ }
2776
+ function Pn(e, t, n) {
2777
+ let r = t, i = H(e, r, n, {
2778
+ phrase: "true",
2779
+ spaceAfter: !0
2780
+ });
2781
+ return i.is ? ({i: r} = i, {
2782
+ i: r,
2783
+ ops: [{
2784
+ op: "tru",
2785
+ params: {}
2786
+ }]
2787
+ }) : (i = H(e, r, n, {
2788
+ phrase: "false",
2789
+ spaceAfter: !0
2790
+ }), i.is ? ({i: r} = i, {
2791
+ i: r,
2792
+ ops: [{
2793
+ op: "fls",
2794
+ params: {}
2795
+ }]
2796
+ }) : (i = H(e, r, n, {
2797
+ phrase: "null",
2798
+ spaceAfter: !0
2799
+ }), i.is ? ({i: r} = i, {
2800
+ i: r,
2801
+ ops: [{
2802
+ op: "nul",
2803
+ params: {}
2804
+ }]
2805
+ }) : Fn(e, r, n)));
2806
+ }
2807
+ async function Fn(e, t, n) {
2808
+ let r = t, i = await Sn(e, r, n);
2809
+ return i.is ? ({i: r} = i, {
2810
+ i: r,
2811
+ ops: i.ops
2812
+ }) : In(e, r, n);
2813
+ }
2814
+ async function In(e, t, n) {
2815
+ let r = t, i = H(e, r, n, {
2816
+ phrase: "func",
2817
+ spaceAfter: !0
2818
+ });
2819
+ if (!i.is) return Ln(e, r, n);
2820
+ ({i: r} = i);
2821
+ let a = W(e, r, n);
2822
+ if (!a.is) return Ln(e, t, n);
2823
+ let o;
2824
+ ({i: r, value: o} = a);
2825
+ let s;
2826
+ ({i: r, argNames: s} = await yn(e, r, n));
2827
+ let c;
2828
+ return {i: r, ops: c} = await Y(e, r, n), {
2829
+ i: r,
2830
+ ops: [{
2831
+ op: "va=",
2832
+ params: {
2833
+ name: o,
2834
+ pipe: [{
2835
+ op: "fun",
2836
+ params: {
2837
+ argNames: s,
2838
+ pipe: c
2839
+ }
2840
+ }]
2841
+ }
2842
+ }]
2843
+ };
2844
+ }
2845
+ async function Ln(e, t, n) {
2846
+ let r = t, i = H(e, r, n, {
2847
+ phrase: "func",
2848
+ spaceAfter: !0
2849
+ });
2850
+ if (!i.is) return Rn(e, r, n);
2851
+ ({i: r} = i);
2852
+ let a;
2853
+ ({i: r, argNames: a} = await yn(e, r, n));
2854
+ let o;
2855
+ return {i: r, ops: o} = await Y(e, r, n), {
2856
+ i: r,
2857
+ ops: [{
2858
+ op: "fun",
2859
+ params: {
2860
+ argNames: a,
2861
+ pipe: o
2862
+ }
2863
+ }]
2864
+ };
2865
+ }
2866
+ async function Rn(e, t, n) {
2867
+ let r = t, i = W(e, r, n);
2868
+ if (!i.is) return zn(e, r, n);
2869
+ let a;
2870
+ ({i: r, value: a} = i);
2871
+ let o, s, c = await bn(e, r, n);
2872
+ if (c.is ? {i: r, selectors: o, canAssign: s} = c : (o = [], s = !0), !s) {
2873
+ let e = [{
2874
+ op: "var",
2875
+ params: { name: a }
2876
+ }];
2877
+ return o.length === 0 ? {
2878
+ i: r,
2879
+ ops: e
2880
+ } : {
2881
+ i: r,
2882
+ ops: [{
2883
+ op: "$.",
2884
+ params: {
2885
+ pipe: e,
2886
+ selectors: o
2887
+ }
2888
+ }]
2889
+ };
2890
+ }
2891
+ let l = await xn(e, r, n);
2892
+ if (!l.is) {
2893
+ let e = [{
2894
+ op: "var",
2895
+ params: { name: a }
2896
+ }];
2897
+ return o.length === 0 ? {
2898
+ i: r,
2899
+ ops: e
2900
+ } : {
2901
+ i: r,
2902
+ ops: [{
2903
+ op: "$.",
2904
+ params: {
2905
+ pipe: e,
2906
+ selectors: o
2907
+ }
2908
+ }]
2909
+ };
2910
+ }
2911
+ let u;
2912
+ return {i: r, assignment: u} = l, o.length === 0 && u.op === "=" ? {
2913
+ i: r,
2914
+ ops: [{
2915
+ op: "va=",
2916
+ params: {
2917
+ name: a,
2918
+ pipe: u.params.pipe
2919
+ }
2920
+ }]
2921
+ } : {
2922
+ i: r,
2923
+ ops: [{
2924
+ op: "va=",
2925
+ params: {
2926
+ name: a,
2927
+ pipe: [{
2928
+ op: "$=",
2929
+ params: {
2930
+ pipe: [{
2931
+ op: "var",
2932
+ params: { name: a }
2933
+ }],
2934
+ selectors: o,
2935
+ assignment: u
2936
+ }
2937
+ }]
2938
+ }
2939
+ }]
2940
+ };
2941
+ }
2942
+ async function zn(e, t, n) {
2943
+ let r = t, i = [], a, o = H(e, r, n, { phrase: "." });
2944
+ if (!o.is) ({i: r, ops: a} = await Bn(e, r, n));
2945
+ else {
2946
+ ({i: r} = o), a = [];
2947
+ let t = W(e, r, n);
2948
+ if (t.is) {
2949
+ let a;
2950
+ ({i: r, value: a} = t);
2951
+ let s = !1;
2952
+ o = H(e, r, n, {
2953
+ phrase: "?",
2954
+ notBeforeSet: "?="
2955
+ }), o.is && ({i: r, is: s} = o), i.push({
2956
+ op: "$.$",
2957
+ params: {
2958
+ pipe: [{
2959
+ op: "\"\"",
2960
+ params: { string: a }
2961
+ }],
2962
+ optional: s
2963
+ }
2964
+ });
2965
+ }
2966
+ }
2967
+ let s = await bn(e, r, n, { identity: a.length === 0 && i.length === 0 }), c;
2968
+ if (s.is ? ({i: r, canAssign: c} = s, i.push(...s.selectors)) : c = i.length > 0, i.length === 0) return {
2969
+ i: r,
2970
+ ops: a
2971
+ };
2972
+ if (!c) return {
2973
+ i: r,
2974
+ ops: [{
2975
+ op: "$.",
2976
+ params: {
2977
+ pipe: a,
2978
+ selectors: i
2979
+ }
2980
+ }]
2981
+ };
2982
+ let l = await xn(e, r, n);
2983
+ if (!l.is) return {
2984
+ i: r,
2985
+ ops: [{
2986
+ op: "$.",
2987
+ params: {
2988
+ pipe: a,
2989
+ selectors: i
2990
+ }
2991
+ }]
2992
+ };
2993
+ let u;
2994
+ return {i: r, assignment: u} = l, {
2995
+ i: r,
2996
+ ops: [{
2997
+ op: "$=",
2998
+ params: {
2999
+ pipe: a,
3000
+ selectors: i,
3001
+ assignment: u
3002
+ }
3003
+ }]
3004
+ };
3005
+ }
3006
+ async function Bn(e, t, n) {
3007
+ let r = t, i = H(e, r, n, { phrase: "{" });
3008
+ if (!i.is) return Vn(e, r, n);
3009
+ ({i: r} = i);
3010
+ let a = [];
3011
+ if (i = H(e, r, n, { phrase: "}" }), i.is) ({i: r} = i);
3012
+ else for (;;) {
3013
+ if (i = H(e, r, n, { phrase: "(" }), i.is) {
3014
+ ({i: r} = i);
3015
+ let t;
3016
+ if ({i: r, ops: t} = await q(e, r, n), i = H(e, r, n, { phrase: ")" }), {i: r} = i, !i.is) return K(e, r, n, {
3017
+ operator: "object",
3018
+ message: "expected ')'"
3019
+ });
3020
+ let o;
3021
+ if ({i: r, is: o} = H(e, r, n, { phrase: "?" }), i = H(e, r, n, { phrase: ":" }), {i: r} = i, !i.is) return K(e, r, n, {
3022
+ operator: "object",
3023
+ message: "expected ':'"
3024
+ });
3025
+ let s;
3026
+ if ({i: r, ops: s} = await J(e, r, n), a.push({
3027
+ key: t,
3028
+ value: s,
3029
+ optional: o
3030
+ }), i = H(e, r, n, { phrase: "}" }), i.is) {
3031
+ ({i: r} = i);
3032
+ break;
3033
+ }
3034
+ if (i = H(e, r, n, { phrase: "," }), {i: r} = i, !i.is) return K(e, r, n, {
3035
+ operator: "object",
3036
+ message: "expected ',' or '}'"
3037
+ });
3038
+ continue;
3039
+ }
3040
+ let t = await Cn(e, r, n);
3041
+ if (t.is) {
3042
+ let o;
3043
+ if ({i: r, ops: o} = t, i = H(e, r, n, { phrase: ":" }), {i: r} = i, !i.is) return K(e, r, n, {
3044
+ operator: "object",
3045
+ message: "expected ':'"
3046
+ });
3047
+ let s;
3048
+ if ({i: r, ops: s} = await J(e, r, n), a.push({
3049
+ key: o,
3050
+ value: s,
3051
+ optional: !1
3052
+ }), i = H(e, r, n, { phrase: "}" }), i.is) {
3053
+ ({i: r} = i);
3054
+ break;
3055
+ }
3056
+ if (i = H(e, r, n, { phrase: "," }), {i: r} = i, !i.is) return K(e, r, n, {
3057
+ operator: "object",
3058
+ message: "expected ',' or '}'"
3059
+ });
3060
+ continue;
3061
+ }
3062
+ let o = W(e, r, n);
3063
+ if (o.is) {
3064
+ let t;
3065
+ ({i: r, value: t} = o);
3066
+ let s;
3067
+ if (i = H(e, r, n, { phrase: ":" }), i.is) ({i: r} = i), {i: r, ops: s} = await J(e, r, n);
3068
+ else {
3069
+ let i;
3070
+ ({i: r, is: i} = H(e, r, n, { phrase: "?" })), s = i ? [{
3071
+ op: "try",
3072
+ params: {
3073
+ try: [{
3074
+ op: "var",
3075
+ params: { name: t }
3076
+ }],
3077
+ catch: [{
3078
+ op: "vod",
3079
+ params: {}
3080
+ }]
3081
+ }
3082
+ }] : [{
3083
+ op: "var",
3084
+ params: { name: t }
3085
+ }];
3086
+ }
3087
+ if (a.push({
3088
+ key: [{
3089
+ op: "\"\"",
3090
+ params: { string: t }
3091
+ }],
3092
+ value: s,
3093
+ optional: !1
3094
+ }), i = H(e, r, n, { phrase: "}" }), i.is) {
3095
+ ({i: r} = i);
3096
+ break;
3097
+ }
3098
+ if (i = H(e, r, n, { phrase: "," }), {i: r} = i, !i.is) return K(e, r, n, {
3099
+ operator: "object",
3100
+ message: "expected ',' or '}'"
3101
+ });
3102
+ continue;
3103
+ }
3104
+ return K(e, r, n, {
3105
+ operator: "object",
3106
+ message: "expected field declaration"
3107
+ });
3108
+ }
3109
+ return {
3110
+ i: r,
3111
+ ops: [{
3112
+ op: "{}",
3113
+ params: { fields: a }
3114
+ }]
3115
+ };
3116
+ }
3117
+ async function Vn(e, t, n) {
3118
+ let r = t, i = H(e, r, n, { phrase: "[" });
3119
+ if ({i: r} = i, !i.is) return Hn(e, r, n);
3120
+ let a;
3121
+ if (i = H(e, r, n, { phrase: "]" }), i.is) ({i: r} = i), a = [{
3122
+ op: "vod",
3123
+ params: {}
3124
+ }];
3125
+ else if ({i: r, ops: a} = await q(e, r, n), i = H(e, r, n, { phrase: "]" }), {i: r} = i, !i.is) return K(e, r, n, {
3126
+ operator: "array",
3127
+ message: "expected ']'"
3128
+ });
3129
+ return {
3130
+ i: r,
3131
+ ops: [{
3132
+ op: "[]",
3133
+ params: { pipe: a }
3134
+ }]
3135
+ };
3136
+ }
3137
+ async function Hn(e, t, n) {
3138
+ let r = t, i = await Cn(e, r, n);
3139
+ return i.is ? ({i: r} = i, {
3140
+ i: r,
3141
+ ops: i.ops
3142
+ }) : Un(e, r, n);
3143
+ }
3144
+ async function Un(e, t, n) {
3145
+ let r = t, i = H(e, r, n, { phrase: "(" });
3146
+ if ({i: r} = i, !i.is) return K(e, r, n);
3147
+ let a;
3148
+ return {i: r, ops: a} = await q(e, r, n), i = H(e, r, n, { phrase: ")" }), {i: r} = i, i.is ? {
3149
+ i: r,
3150
+ ops: a
3151
+ } : K(e, r, n, {
3152
+ operator: "group",
3153
+ message: "expected ')'"
3154
+ });
3155
+ }
3156
+ //#endregion
3157
+ //#region lib/interpreter/index.ts
3158
+ var Wn = {};
3159
+ function Gn(e = {}, t = {}) {
3160
+ return r(e, t);
3161
+ }
3162
+ var Kn = class {
3163
+ #e;
3164
+ #t;
3165
+ #n;
3166
+ constructor(e) {
3167
+ this.#e = Gn(e?.interpreter, Wn), this.#t = e?.program, this.#n = e?.runtime;
3168
+ }
3169
+ get options() {
3170
+ return this.#e;
3171
+ }
3172
+ parse = async (e, t) => new rn({
3173
+ version: m,
3174
+ instructions: await this.parseInstructions(e)
3175
+ }, {
3176
+ program: nn(t?.program, this.#t),
3177
+ runtime: P(t?.runtime, this.#n)
3178
+ });
3179
+ parseInstructions = async (e) => {
3180
+ let { ops: t } = await _n(e, 0, { interpreter: this });
3181
+ return t;
3182
+ };
3183
+ }, qn = new Kn(), Jn = /* @__PURE__ */ t({ sortEntries: () => Yn }), Yn = ct(async (e, t) => [await e.alterValue(t, (t) => [...t].sort((t, n) => e.compareArrays(e.unwrapValue(t)[0], e.unwrapValue(n)[0])))]);
3184
+ //#endregion
3185
+ //#region lib/builtins/funcContains.ts
3186
+ function Xn(e, t, n, r, i) {
3187
+ let a = e.unwrapValue(r), o = e.type(a), s = e.unwrapValue(i ?? null), c = e.type(s);
3188
+ switch (o) {
3189
+ case "array": return n(a.some((t) => e.equals(t, s)));
3190
+ case "string":
3191
+ if (c === "string") return n(a.includes(s));
3192
+ break;
3193
+ case "object": return n(Object.values(a).some((t) => e.equals(t, s)));
3194
+ default:
3195
+ }
3196
+ throw new A("%s (%*<100v) cannot contain %s (%*<100v)", o, a, c, s);
3197
+ }
3198
+ //#endregion
3199
+ //#region lib/builtins/funcEndsWith.ts
3200
+ function Zn(e, t, n, r, i) {
3201
+ let a = e.unwrapValue(r), o = e.type(a), s = e.unwrapValue(i ?? null), c = e.type(s);
3202
+ switch (o) {
3203
+ case "string":
3204
+ if (c === "string") return n(a.endsWith(s));
3205
+ break;
3206
+ default:
3207
+ }
3208
+ throw new A("%s (%*<100v) cannot end with %s (%*<100v)", o, a, c, s);
3209
+ }
3210
+ //#endregion
3211
+ //#region lib/builtins/funcError.ts
3212
+ function Qn(e, t, n, r) {
3213
+ throw new k(r);
3214
+ }
3215
+ //#endregion
3216
+ //#region lib/builtins/funcFromJSON.ts
3217
+ function $n(e, t, n, r) {
3218
+ let i = e.unwrapValue(r), a = e.type(i);
3219
+ switch (a) {
3220
+ case "string": {
3221
+ let e;
3222
+ try {
3223
+ e = JSON.parse(i);
3224
+ } catch (e) {
3225
+ throw new k(e.message);
3226
+ }
3227
+ return n(e);
3228
+ }
3229
+ default:
3230
+ }
3231
+ throw new A("%s (%*<100v) cannot be parsed as JSON", a, i);
3232
+ }
3233
+ //#endregion
3234
+ //#region lib/builtins/funcHas.ts
3235
+ function er(e, t, n, r, i) {
3236
+ let a = e.unwrapValue(r), o = e.type(a), s = e.unwrapValue(i ?? null), c = e.type(s);
3237
+ switch (o) {
3238
+ case "array":
3239
+ if (c === "number") return n(s >= 0 && s < a.length);
3240
+ break;
3241
+ case "object":
3242
+ if (c === "string") return n(Object.hasOwn(a, s));
3243
+ break;
3244
+ default:
3245
+ }
3246
+ throw new A("%s (%*<100v) cannot have %s (%*<100v) as key", o, a, c, s);
3247
+ }
3248
+ //#endregion
3249
+ //#region lib/builtins/funcIn.ts
3250
+ function tr(e, t, n, r, i) {
3251
+ let a = e.unwrapValue(r), o = e.type(a), s = e.unwrapValue(i ?? null), c = e.type(s);
3252
+ switch (c) {
3253
+ case "array":
3254
+ if (o === "number") return n(a >= 0 && a < s.length);
3255
+ break;
3256
+ case "object":
3257
+ if (o === "string") return n(Object.hasOwn(s, a));
3258
+ break;
3259
+ default:
3260
+ }
3261
+ throw new A("%s (%*<100v) cannot have %s (%*<100v) as key", c, s, o, a);
3262
+ }
3263
+ //#endregion
3264
+ //#region lib/builtins/funcKeys.ts
3265
+ function nr(e, t, n, r) {
3266
+ let i = e.unwrapValue(r), a = e.type(i);
3267
+ switch (a) {
3268
+ case "array": return n(i.map((e, t) => t));
3269
+ case "object": return n(Object.keys(i));
3270
+ default:
3271
+ }
3272
+ throw new A("%s (%*<100v) has no keys", a, i);
3273
+ }
3274
+ //#endregion
3275
+ //#region lib/builtins/funcLength.ts
3276
+ function rr(e, t, n, r) {
3277
+ let i = e.unwrapValue(r), a = e.type(i);
3278
+ switch (a) {
3279
+ case "null": return n(0);
3280
+ case "array": return n(i.length);
3281
+ case "string": return n([...i].length);
3282
+ case "object": return n(Object.keys(i).length);
3283
+ default:
3284
+ }
3285
+ throw new A("%s (%*<100v) has no length", a, i);
3286
+ }
3287
+ //#endregion
3288
+ //#region lib/builtins/funcNow.ts
3289
+ function ir(e, t, n, r) {
3290
+ return n(Date.now());
3291
+ }
3292
+ //#endregion
3293
+ //#region lib/builtins/funcStartsWith.ts
3294
+ function ar(e, t, n, r, i) {
3295
+ let a = e.unwrapValue(r), o = e.type(a), s = e.unwrapValue(i ?? null), c = e.type(s);
3296
+ switch (o) {
3297
+ case "string":
3298
+ if (c === "string") return n(a.startsWith(s));
3299
+ break;
3300
+ default:
3301
+ }
3302
+ throw new A("%s (%*<100v) cannot start with %s (%*<100v)", o, a, c, s);
3303
+ }
3304
+ //#endregion
3305
+ //#region lib/builtins/funcToJSON.ts
3306
+ function or(e, t, n, r) {
3307
+ return n(e.stringifyJSON(r, !1));
3308
+ }
3309
+ //#endregion
3310
+ //#region lib/builtins/funcToLowerCase.ts
3311
+ async function sr(e, t, n, r) {
3312
+ let i = e.type(r);
3313
+ switch (i) {
3314
+ case "string": return n(await e.alterValue(r, (e) => e.toLowerCase()));
3315
+ default:
3316
+ }
3317
+ throw new A("%s (%*<100v) cannot be converted to lower case", i, e.unwrapValue(r));
3318
+ }
3319
+ //#endregion
3320
+ //#region lib/builtins/funcToNumber.ts
3321
+ function cr(e, t, n, r) {
3322
+ let i = e.unwrapValue(r), a = e.type(i);
3323
+ switch (a) {
3324
+ case "number": return n(i);
3325
+ case "string": {
3326
+ let t = e.normalizeValue(+i);
3327
+ if (i === "" || e.type(t) !== "number") throw new tt("%s (%*<100v) does not contain a valid number", a, i);
3328
+ return n(t);
3329
+ }
3330
+ default:
3331
+ }
3332
+ throw new A("%s (%*<100v) cannot be parsed as a number", a, i);
3333
+ }
3334
+ //#endregion
3335
+ //#region lib/builtins/funcToString.ts
3336
+ function lr(e, t, n, r) {
3337
+ return n(e.stringifyJSON(r, !0));
3338
+ }
3339
+ //#endregion
3340
+ //#region lib/builtins/funcToUpperCase.ts
3341
+ async function ur(e, t, n, r) {
3342
+ let i = e.type(r);
3343
+ switch (i) {
3344
+ case "string": return n(await e.alterValue(r, (e) => e.toUpperCase()));
3345
+ default:
3346
+ }
3347
+ throw new A("%s (%*<100v) cannot be converted to upper case", i, e.unwrapValue(r));
3348
+ }
3349
+ //#endregion
3350
+ //#region lib/builtins/funcTrim.ts
3351
+ async function dr(e, t, n, r) {
3352
+ let i = e.type(r);
3353
+ switch (i) {
3354
+ case "string": return n(await e.alterValue(r, (e) => e.trim()));
3355
+ default:
3356
+ }
3357
+ throw new A("%s (%*<100v) cannot be trimmed", i, e.unwrapValue(r));
3358
+ }
3359
+ //#endregion
3360
+ //#region lib/builtins/funcTrimEnd.ts
3361
+ async function fr(e, t, n, r) {
3362
+ let i = e.type(r);
3363
+ switch (i) {
3364
+ case "string": return n(await e.alterValue(r, (e) => e.trimEnd()));
3365
+ default:
3366
+ }
3367
+ throw new A("%s (%*<100v) cannot be trimmed", i, e.unwrapValue(r));
3368
+ }
3369
+ //#endregion
3370
+ //#region lib/builtins/funcTrimStart.ts
3371
+ async function pr(e, t, n, r) {
3372
+ let i = e.type(r);
3373
+ switch (i) {
3374
+ case "string": return n(await e.alterValue(r, (e) => e.trimStart()));
3375
+ default:
3376
+ }
3377
+ throw new A("%s (%*<100v) cannot be trimmed", i, e.unwrapValue(r));
3378
+ }
3379
+ //#endregion
3380
+ //#region lib/builtins/funcType.ts
3381
+ function mr(e, t, n, r) {
3382
+ return n(e.type(r));
3383
+ }
3384
+ //#endregion
3385
+ //#region lib/builtins/funcVoid.ts
3386
+ function hr(e, t, n, r) {
3387
+ return [];
3388
+ }
3389
+ //#endregion
3390
+ //#region lib/builtins/math.ts
3391
+ function gr(e, t) {
3392
+ let n = e.type(t), r = e.unwrapValue(t);
3393
+ if (n !== "number") throw new A("%s (%*<100v) cannot be used for mathematical operations", n, r);
3394
+ return r;
3395
+ }
3396
+ function $(e) {
3397
+ return async function(t, n, r, i, ...a) {
3398
+ let o = t.type(i);
3399
+ if (o !== "number") throw new A("%s (%*<100v) cannot be used for mathematical operations", o, t.unwrapValue(i));
3400
+ return r(await t.alterValue(i, (n) => e(t, n, ...a)));
3401
+ };
3402
+ }
3403
+ var _r = $((e, t, n) => t ** gr(e, n ?? null)), vr = $((e, t) => Math.sqrt(t)), yr = $((e, t) => Math.exp(t)), br = $((e, t) => Math.log(t)), xr = $((e, t) => Math.log10(t)), Sr = $((e, t) => Math.sin(t)), Cr = $((e, t) => Math.cos(t)), wr = $((e, t) => Math.tan(t)), Tr = $((e, t) => Math.asin(t)), Er = $((e, t) => Math.acos(t)), Dr = $((e, t) => Math.atan(t)), Or = $((e, t) => Math.ceil(t)), kr = $((e, t) => Math.floor(t)), Ar = $((e, t) => Math.round(t)), jr = $((e, t) => Math.trunc(t)), Mr = $((e, t) => Math.abs(t)), Nr = /* @__PURE__ */ t({
3404
+ abs: () => Mr,
3405
+ acos: () => Er,
3406
+ asin: () => Tr,
3407
+ atan: () => Dr,
3408
+ ceil: () => Or,
3409
+ contains: () => Xn,
3410
+ cos: () => Cr,
3411
+ endsWith: () => Zn,
3412
+ error: () => Qn,
3413
+ exp: () => yr,
3414
+ floor: () => kr,
3415
+ fromJSON: () => $n,
3416
+ has: () => er,
3417
+ in: () => tr,
3418
+ keys: () => nr,
3419
+ length: () => rr,
3420
+ log: () => br,
3421
+ log10: () => xr,
3422
+ now: () => ir,
3423
+ pow: () => _r,
3424
+ round: () => Ar,
3425
+ sin: () => Sr,
3426
+ sqrt: () => vr,
3427
+ startsWith: () => ar,
3428
+ tan: () => wr,
3429
+ toJSON: () => or,
3430
+ toLowerCase: () => sr,
3431
+ toNumber: () => cr,
3432
+ toString: () => lr,
3433
+ toUpperCase: () => ur,
3434
+ trim: () => dr,
3435
+ trimEnd: () => fr,
3436
+ trimStart: () => pr,
3437
+ trunc: () => jr,
3438
+ type: () => mr,
3439
+ void: () => hr
3440
+ }), Pr = "\n# There are additional builtins that are implemented directly in the corresponding languages.\n# Also the functions in the \"internals\" namespace are not exposed to the public and are only to be used by the builtins below.\n\nfunc map(f): ([.[] | f()])\n| func mapValues(f): (.[] |= f())\n| func select(f): (if f() then . else void() end)\n| func reduce(f, s): (\n l = length()\n | func i(i, n, c): (if n < l then i(i, n + 1, f->(.[n], c, n)) else c end)\n | i(i, 0, s)\n)\n| func while(cond, f): (\n func i(i): (if cond() then ., i->(f(), i) else void() end)\n | i(i)\n)\n| func until(cond, f): (\n func i(i): (if cond() then . else i->(f(), i) end)\n | i(i)\n)\n| func range(from, to, step): (\n t = type->(from) | if t != \"number\" then error->(\"cannot use \\(t) as a number\") end\n | t = type->(to) | if t != \"number\" then error->(\"cannot use \\(t) as a number\") end\n | s = (step | if . != 0 and . != null then abs() else 1 end)\n | while->(\n from,\n if from <= to then func (): (. < to) else func (): (. > to) end,\n if from <= to then func (): (. + s) else func (): (. - s) end\n )\n)\n\n\n# type selectors:\n| func isArray(): (type() == \"array\")\n| func arrays(): (select(isArray))\n| func isObject(): (type() == \"object\")\n| func objects(): (select(isObject))\n| func isIterable(): (contains->([\"array\", \"object\"], type()))\n| func iterables(): (select(isIterable))\n| func isScalar(): (not contains->([\"array\", \"object\"], type()))\n| func scalars(): (select(isScalar))\n| func isBoolean(): (type() == \"boolean\")\n| func booleans(): (select(isBoolean))\n| func isNumber(): (type() == \"number\")\n| func numbers(): (select(isNumber))\n| func isString(): (type() == \"string\")\n| func strings(): (select(isString))\n| func isNull(): (type() == \"null\")\n| func nulls(): (select(isNull))\n| func isFunction(): (type() == \"function\")\n| func functions(): (select(isFunction))\n| func isNullLike(): (contains->([\"null\", \"function\"], type()))\n| func nullLikes(): (select(isNullLike))\n| func isValue(): (not contains->([\"null\", \"function\"], type()))\n| func values(): (select(isValue))\n| func isContent(): (isValue() and not contains->([[], {}, \"\"], .))\n| func contents(): (select(isContent))\n\n\n| func toEntries(): (o = . | keys() | map(func (): ({ key: ., value: o[.] })))\n| func fromEntries(): (\n reduce(\n func (s): (s + { (.key ?? .Key ?? .name ?? .Name): if has(\"value\") then .value else .Value end }),\n {}\n )\n)\n| func withEntries(f): (toEntries() | map(f) | fromEntries())\n\n| func add(): (reduce(func (sum): (sum + .)))\n| func join(sep): (\n reduce(\n func (sum): (\n if sum == null then \"\" else sum + sep end\n + (. | toString())\n )\n ) ?? \"\"\n)\n| func sortBy(f): ([.[] | [[f()], .]] | internals.sortEntries() | [.[][1]])\n| func sort(): (sortBy(func (): (.)))\n| func groupBy(f): (\n key = 0 | value = 1\n | [.[] | [[f()], [.]]] | internals.sortEntries()\n | if . == []\n then .\n else\n reduce->(\n .[1:],\n func (sum): (if sum[-1][key] == .[key] then (sum)[-1][value] += .[value] else sum + [.] end),\n .[:1]\n )\n | [.[][value]]\n end\n)\n| func group(): (groupBy(func (): (.)))\n| func uniqueBy(f): (groupBy(f) | map(func (): (.[0])))\n| func unique(): (group() | map(func (): (.[0])))\n| func recurseBy(f, cond): (\n c = cond ?? func (): (. != null)\n | func r(r): (., (f() | select(c) | r(r)))\n | r(r)\n)\n| func recurse(cond): (recurseBy(func (): ((arrays(), objects()) | .[]), cond))\n| func reverse(): ([.[length() - 1 - range(0, length())]])\n| func minBy(f): (\n key = 0 | value = 1\n | [.[] | [[f()], .]]\n | reduce->(.[1:], func (sum): (if .[key] < sum[key] then . else sum end), .[0])\n | .[value]\n)\n| func min(): (reduce->(.[1:], func (sum): (if . < sum then . else sum end), .[0]))\n| func maxBy(f): (\n key = 0 | value = 1\n | [.[] | [[f()], .]]\n | reduce->(.[1:], func (sum): (if .[key] > sum[key] then . else sum end), .[0])\n | .[value]\n)\n| func max(): (reduce->(.[1:], func (sum): (if . > sum then . else sum end), .[0]))\n| func first(f): ([f()][0])\n| func nth(which, f): (\n [f()]\n | .[if which | type() == \"number\" then which else length() | which() end]\n)\n| func last(f): ([f()][-1])\n| func isEmpty(f): (first(func (): ((f() | false), true)))\n| func allBy(f, cond): (isEmpty(func (): (f() | cond() and void())))\n| func all(cond): (allBy(func (): (.[]), cond))\n| func anyBy(f, cond): (not isEmpty(func (): (f() | cond() or void())))\n| func any(cond): (anyBy(func (): (.[]), cond))\n\n| func getPath(path): (\n fields = (path | if type() == 'string' then . / '.' end)\n | reduce->(fields, func (sum): sum[if type->(sum) == 'array' then toNumber() else toString() end], .)\n)\n| func updatePath(path, update): (\n fields = (path | if type() == 'string' then (. / '.')[] |= (v = . | try toNumber() catch v) end)\n | reduce->(\n reverse->(fields),\n func (sum): (\n field = .\n | func (): (\n if type() == 'array'\n then (\n input = .\n | try toNumber->(field) catch toString->(field)\n | if type() == 'number'\n then input[.] |= sum()\n else {}[.] |= sum()\n end\n ) elif type() == 'object'\n then (\n .[toString->(field)] |= sum()\n ) elif type->(field) == 'number'\n then (\n [][field] |= sum()\n ) else (\n {}[toString->(field)] |= sum()\n )\n end\n )\n ),\n update\n )->(.)\n)\n| func setPath(path, value): (\n updatePath(path, func (): value)\n)\n", Fr = n(async () => {
3441
+ await void 0;
3442
+ let e = { ...Nr };
3443
+ return await (await qn.parse(Pr, { runtime: {
3444
+ vars: {
3445
+ internals: Jn,
3446
+ ...Nr
3447
+ },
3448
+ adjustResult: (t, n) => {
3449
+ let { internals: r, ...a } = n.vars;
3450
+ return e = i(e, Object.entries(a)), [];
3451
+ }
3452
+ } })).run([null]), e;
3453
+ });
3454
+ //#endregion
3455
+ //#region lib/interpreter/parseFunction.ts
3456
+ async function Ir(e, t, n) {
3457
+ return st(e, await qn.parseInstructions(t), n);
3458
+ }
3459
+ //#endregion
3460
+ //#region lib/main.ts
3461
+ var Lr = n(async () => ({
3462
+ interpreter: {},
3463
+ program: {},
3464
+ runtime: { vars: { ...await Fr() } }
3465
+ })), Rr = async (e, t) => {
3466
+ let n = await Lr();
3467
+ return new Kn({
3468
+ interpreter: Gn(t?.interpreter, n.interpreter),
3469
+ program: nn(t?.program, n.program),
3470
+ runtime: P(t?.runtime, n.runtime)
3471
+ }).parse(e);
3472
+ }, zr = async (e, t, n) => (await Rr(e, n)).run(t);
3473
+ //#endregion
3474
+ export { m as DEFINITION_VERSION, Ve as DEFINITION_VERSION_MAJOR, He as DEFINITION_VERSION_MINOR, h as JPLError, v as JPLErrorEnclosure, g as JPLExecutionError, y as JPLFatalError, et as JPLReferenceError, k as JPLRuntimeError, it as JPLRuntimeScope, nt as JPLSyntaxError, b as JPLType, tt as JPLTypeConversionError, A as JPLTypeError, j as JPLZeroDivisionError, ve as OPA_FIELD, ye as OPA_FUNCTION, be as OPA_ITER, xe as OPA_SLICE, Se as OPC_EQUAL, Ce as OPC_GREATER, we as OPC_GREATEREQUAL, Te as OPC_LESS, Ee as OPC_LESSEQUAL, De as OPC_UNEQUAL, Oe as OPM_ADDITION, ke as OPM_DIVISION, Ae as OPM_MULTIPLICATION, je as OPM_REMAINDER, Me as OPM_SUBTRACTION, Ne as OPU_ADDITION, Pe as OPU_DIVISION, Fe as OPU_MULTIPLICATION, Ie as OPU_NULL_COALESCENCE, Le as OPU_REMAINDER, Re as OPU_SET, ze as OPU_SUBTRACTION, Be as OPU_UPDATE, s as OP_ACCESS, c as OP_AND, l as OP_ARRAY_CONSTRUCTOR, u as OP_ASSIGNMENT, d as OP_CALCULATION, f as OP_COMPARISON, p as OP_CONSTANT, ee as OP_CONSTANT_FALSE, te as OP_CONSTANT_NULL, ne as OP_CONSTANT_TRUE, re as OP_FUNCTION_DEFINITION, ie as OP_IF, ae as OP_INTERPOLATED_STRING, oe as OP_NEGATION, se as OP_NOT, ce as OP_NULL_COALESCENCE, le as OP_NUMBER, ue as OP_OBJECT_CONSTRUCTOR, de as OP_OR, fe as OP_OUTPUT_CONCAT, pe as OP_STRING, me as OP_TRY, he as OP_VARIABLE, ge as OP_VARIABLE_DEFINITION, _e as OP_VOID, _ as adaptError, Ue as adaptErrors, We as adaptErrorsAsync, a as applyArray, o as applyCombinations, i as applyObject, Je as assertType, T as displayValue, Fr as getBuiltins, Lr as getOptions, Qe as jplJSONStripper, Ze as jplStripper, Xe as jplTypedStripper, $e as jsonStripper, dt as mergeSegments, lt as mux, ut as muxAll, N as muxAsync, M as muxOne, ct as nativeFunction, x as normalize, st as orphanFunction, Rr as parse, Ir as parseFunction, D as rawStripper, zr as run, ot as scopedFunction, Ye as strictDisplayValue, C as stringify, E as strip, w as template, qe as typeOf, Ke as typeOrder, S as unwrap };