@jplorg/jpl 2.0.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 -33
  171. package/lib/program/ops/opAccess/opaSlice.js +0 -46
  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 -71
  177. package/lib/program/ops/opAssignment/opaAssignSlice.js +0 -101
  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 -34
  270. package/src/program/ops/opAccess/opaSlice.js +0 -61
  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 -77
  276. package/src/program/ops/opAssignment/opaAssignSlice.js +0 -160
  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
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _library = require("../library");
8
- var _system = _interopRequireDefault(require("./system"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- /**
11
- * Create an orphan JPL function from the specified source program string.
12
- *
13
- * Some optional scope presets may be specified, e.g. for allowing the function access to some specified variables.
14
- * Other than that, the function does not have access to any external variables.
15
- *
16
- * @param {string[]} argNames Names to bind the function arguments to
17
- * @param {string} source Source program string to execute
18
- * @param {{ vars: object? }} [presets] Optional scope presets
19
- */
20
- async function parseFunction(argNames, source, presets) {
21
- const instructions = await _system.default.parseInstructions(source);
22
- return (0, _library.orphanFunction)(argNames, instructions, presets);
23
- }
24
- var _default = exports.default = parseFunction;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _ = _interopRequireDefault(require("."));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- const systemInterpreter = new _.default();
10
- var _default = exports.default = systemInterpreter;
@@ -1,349 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.eot = eot;
7
- exports.errorGeneric = errorGeneric;
8
- exports.errorUnexpectedToken = errorUnexpectedToken;
9
- exports.hex = hex;
10
- exports.highlightLocation = highlightLocation;
11
- exports.match = match;
12
- exports.matchSet = matchSet;
13
- exports.matchWord = matchWord;
14
- exports.safeVariable = safeVariable;
15
- exports.variable = variable;
16
- exports.walkWhitespace = walkWhitespace;
17
- exports.whereIs = whereIs;
18
- var _library = require("../library");
19
- const setAZ = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
20
- const setDigit = '0123456789';
21
- const setVarFirst = `${setAZ}_$`;
22
- const setVarRest = `${setVarFirst}${setDigit}`;
23
- const setVarAll = setVarRest;
24
- const setWhitespace = ' \xa0\r\n\t';
25
- const setHex = `${setDigit}abcdefABCDEF`;
26
-
27
- /** Walk whitespace at i */
28
- function walkWhitespace(src, i, c) {
29
- let n = i;
30
- let is = false;
31
- for (;;) {
32
- let m = match(src, n, c, {
33
- phrase: '#'
34
- });
35
- if (m.is) {
36
- ({
37
- i: n
38
- } = m);
39
- for (;;) {
40
- const set = matchSet(src, n, c, {
41
- set: '\r\n'
42
- });
43
- if (set.is) {
44
- ({
45
- i: n
46
- } = set);
47
- break;
48
- }
49
- const end = eot(src, n, c);
50
- if (end.is) {
51
- ({
52
- i: n
53
- } = end);
54
- break;
55
- }
56
- n += 1;
57
- }
58
- is = true;
59
- continue;
60
- }
61
- m = match(src, n, c, {
62
- phrase: '/*'
63
- });
64
- if (m.is) {
65
- ({
66
- i: n
67
- } = m);
68
- for (;;) {
69
- m = match(src, n, c, {
70
- phrase: '*/'
71
- });
72
- if (m.is) {
73
- ({
74
- i: n
75
- } = m);
76
- break;
77
- }
78
- const end = eot(src, n, c);
79
- if (end.is) {
80
- ({
81
- i: n
82
- } = end);
83
- return errorUnexpectedToken(src, n, c, {
84
- operator: 'comment',
85
- message: 'incomplete comment'
86
- });
87
- }
88
- n += 1;
89
- }
90
- is = true;
91
- continue;
92
- }
93
- const set = matchSet(src, n, c, {
94
- set: setWhitespace
95
- });
96
- ({
97
- i: n
98
- } = set);
99
- if (!set.is) break;
100
- is = true;
101
- }
102
- return {
103
- i: n,
104
- is
105
- };
106
- }
107
-
108
- /**
109
- * Check if src matches phrase at i.
110
- * If notBeforeSet is provided, the phrase is only considered to be matching if it is not immediately followed by one of the symbols of the set.
111
- * If spaceBefore is true, the phrase is only considered to be matching if there is space (not to be confused with whitespace) before i (or i is 0).
112
- * If spaceAfter is true, the phrase is only considered to be matching if there is space (not to be confused with whitespace) after the phrase (or the end is reached).
113
- * The returned index is positioned directly after the phrase or at the first unmatched character, even if spaceAfter is true.
114
- * Space is defined as anything that cannot occur in a variable name.
115
- */
116
- function match(src, i, c, {
117
- phrase,
118
- notBeforeSet,
119
- spaceBefore,
120
- spaceAfter
121
- }) {
122
- let n = i;
123
- if (spaceBefore && i > 0) {
124
- if (!matchSet(src, n - 1, c, {
125
- set: setVarAll,
126
- exclusive: true
127
- }).is) return {
128
- i: n,
129
- is: false
130
- };
131
- }
132
- for (let j = 0; j < phrase.length; j += 1, n += 1) {
133
- const end = eot(src, n, c);
134
- if (end.is || src[n] !== phrase[j]) return {
135
- i: end.i,
136
- is: false
137
- };
138
- }
139
- if (!eot(src, n, c).is) {
140
- if (notBeforeSet && matchSet(src, n, c, {
141
- set: notBeforeSet
142
- }).is) return {
143
- i: n,
144
- is: false
145
- };
146
- if (spaceAfter && !matchSet(src, n, c, {
147
- set: setVarAll,
148
- exclusive: true
149
- }).is) return {
150
- i: n,
151
- is: false
152
- };
153
- }
154
- return {
155
- i: n,
156
- is: true
157
- };
158
- }
159
-
160
- /** The same as match, but also walk whitespace after the match if present */
161
- function matchWord(src, i, c, {
162
- phrase,
163
- notBeforeSet,
164
- spaceBefore,
165
- spaceAfter
166
- }) {
167
- let n = i;
168
- const m = match(src, n, c, {
169
- phrase,
170
- notBeforeSet,
171
- spaceBefore,
172
- spaceAfter
173
- });
174
- if (!m.is) return {
175
- i: m.i,
176
- is: false
177
- };
178
- ({
179
- i: n
180
- } = m);
181
- ({
182
- i: n
183
- } = walkWhitespace(src, n, c));
184
- return {
185
- i: n,
186
- is: true
187
- };
188
- }
189
-
190
- /** Check if i is a hexadecimal value */
191
- function hex(src, i, c) {
192
- return matchSet(src, i, c, {
193
- set: setHex
194
- });
195
- }
196
-
197
- /**
198
- * Check if i is one of the chars in set.
199
- * If exclusive is true, i must not be one of the chars in set for the check to succeed.
200
- */
201
- function matchSet(src, i, c, {
202
- set,
203
- exclusive
204
- }) {
205
- const end = eot(src, i, c);
206
- if (end.is) return {
207
- i: end.i,
208
- is: false
209
- };
210
- const char = src[i];
211
- if (set.includes(char) === !exclusive) return {
212
- i: i + 1,
213
- is: true,
214
- value: char
215
- };
216
- return {
217
- i,
218
- is: false,
219
- value: ''
220
- };
221
- }
222
-
223
- /** Parse variable selector at i */
224
- function variable(src, i, c) {
225
- let n = i;
226
- let is = false;
227
- let value = '';
228
- for (;;) {
229
- const set = matchSet(src, n, c, {
230
- set: !is ? setVarFirst : setVarRest
231
- });
232
- ({
233
- i: n
234
- } = set);
235
- if (!set.is) break;
236
- is = true;
237
- value += set.value;
238
- }
239
- if (is) ({
240
- i: n
241
- } = walkWhitespace(src, n, c));
242
- return {
243
- i: n,
244
- is,
245
- value
246
- };
247
- }
248
-
249
- /** The same as variable, but also check that the result is not a reserved term */
250
- function safeVariable(src, i, c) {
251
- const v = variable(src, i, c);
252
- if (!v.is) return v;
253
- switch (v.value) {
254
- case 'and':
255
- case 'catch':
256
- case 'func':
257
- case 'elif':
258
- case 'else':
259
- case 'end':
260
- case 'false':
261
- case 'if':
262
- case 'not':
263
- case 'null':
264
- case 'or':
265
- case 'then':
266
- case 'true':
267
- case 'try':
268
- return {
269
- i,
270
- is: false,
271
- value: v.value,
272
- reserved: true
273
- };
274
- default:
275
- return v;
276
- }
277
- }
278
-
279
- /** Check if i is at the end of src */
280
- function eot(src, i) {
281
- if (i >= src.length) return {
282
- i: src.length,
283
- is: true
284
- };
285
- return {
286
- i,
287
- is: false
288
- };
289
- }
290
-
291
- /** Get (zero based) line and column for i */
292
- function whereIs(src, i) {
293
- const lines = src.substring(0, i).split(/\r?\n|\r/);
294
- const line = lines[lines.length - 1];
295
- return {
296
- i,
297
- line: lines.length - 1,
298
- column: line.length
299
- };
300
- }
301
-
302
- /** Get a descriptive text highlighting i */
303
- function highlightLocation(src, i, c, {
304
- area = 25
305
- } = {}) {
306
- const s = Math.max(Math.min(i, src.length - 1 - area), area) - area;
307
- const e = Math.min(s + area + 1 + area, src.length);
308
- const view = src.substring(s, e).replaceAll(/\r?\n|\r/g, '⏎').replaceAll('\t', '→');
309
- let prefix = ' > ';
310
- if (s > 0) prefix += '…';
311
- let suffix = '';
312
- if (e < src.length) suffix = '…';
313
- const description = `${prefix}${view}${suffix}\n${' '.repeat(prefix.length + (i - s))}^ here`;
314
- return {
315
- i,
316
- value: description
317
- };
318
- }
319
-
320
- /** Throw an error caused by an unexpected token at i */
321
- function errorUnexpectedToken(src, i, c, {
322
- operator,
323
- message
324
- } = {}) {
325
- let errorMessage;
326
- if (eot(src, i, c).is) errorMessage = 'unexpected EOT';else {
327
- const {
328
- line,
329
- column
330
- } = whereIs(src, i, c);
331
- errorMessage = `unexpected token '${src[i]}' at line ${line + 1}, column ${column + 1}`;
332
- }
333
- if (operator) errorMessage += ` while parsing ${operator}`;
334
- if (message) errorMessage += `: ${message}`;
335
- errorMessage += `\n${highlightLocation(src, i, c).value}`;
336
- throw new _library.JPLSyntaxError(errorMessage, src, i);
337
- }
338
-
339
- /** Throw an error caused by a generic parser error at i */
340
- function errorGeneric(src, i, c, {
341
- operator,
342
- message
343
- } = {}) {
344
- let errorMessage = 'error';
345
- if (operator) errorMessage += ` while parsing ${operator}`;
346
- if (message) errorMessage += `: ${message}`;
347
- errorMessage += `\n${highlightLocation(src, i, c).value}`;
348
- throw new _library.JPLSyntaxError(errorMessage, src, i);
349
- }
@@ -1,142 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.applyArray = applyArray;
7
- exports.applyCombinations = applyCombinations;
8
- exports.applyObject = applyObject;
9
- /**
10
- * Apply all changes immutably to the source object.
11
- *
12
- * @param {[key: string, value: any][]} changes The changes to be applied
13
- */
14
- function applyObject(source, changes) {
15
- let result = source;
16
- let unchanged = true;
17
- changes.forEach(entry => {
18
- const [key, value] = entry;
19
- if (entry.length === 1) {
20
- if (!Object.hasOwn(result, key)) return;
21
- if (unchanged) {
22
- let _;
23
- ({
24
- [key]: _,
25
- ...result
26
- } = result);
27
- unchanged = false;
28
- } else {
29
- delete result[key];
30
- }
31
- return;
32
- }
33
- if (Object.hasOwn(result, key) && result[key] === value) return;
34
- if (unchanged) {
35
- result = {
36
- ...result,
37
- [key]: value
38
- };
39
- unchanged = false;
40
- } else {
41
- result[key] = value;
42
- }
43
- });
44
- return result;
45
- }
46
-
47
- /**
48
- * Apply all changes immutably to the source array.
49
- * Indices can be negative to be applied from the end of the array.
50
- *
51
- * @param {[index: string, value: any][]} changes The changes to be applied
52
- * @param filler Value to be used as padding
53
- */
54
- function applyArray(source, changes, filler = null) {
55
- let result = source;
56
- let unchanged = true;
57
- changes.forEach(entry => {
58
- const [index, value] = entry;
59
- let i = index >= 0 ? index : result.length + index;
60
- if (i >= 0 && i < result.length && result[i] === value) return;
61
- if (index >= 0) {
62
- const suf = i + 1 - result.length;
63
- if (suf > 0) {
64
- result = [...result, ...new Array(suf).fill(filler)];
65
- unchanged = false;
66
- }
67
- } else {
68
- const pre = -i;
69
- if (pre > 0) {
70
- result = [...new Array(pre).fill(filler), ...result];
71
- unchanged = false;
72
- i = 0;
73
- }
74
- }
75
- if (unchanged) {
76
- result = [...result];
77
- unchanged = false;
78
- }
79
- result[i] = value;
80
- });
81
- return result;
82
- }
83
-
84
- /**
85
- * Create all possible combinations immutably based on the specified source array.
86
- * If the specified `combinations` array is empty, the resulting array contains a single empty array.
87
- * This function has essentially the same base functionality as the `mux` function, but uses a more performant approach for generating immutable arrays as it reduces the number of necessary array copies.
88
- *
89
- * `applyCombinations([], [[1, 2], [3, 4]])` for example produces:
90
- * - `[1, 3]`
91
- * - `[1, 4]`
92
- * - `[2, 3]`
93
- * - `[2, 4]`
94
- *
95
- * If the values of `source` are equal to the values of one of the combinations, it is used instead of a copy in the output array, e.g.:
96
- * `let i = [1, 2]; applyCombinations(i, [[1], [2]])[0] == i`
97
- * - `true`
98
- *
99
- * @param {any[][]} combinations The combinations
100
- */
101
- function applyCombinations(source, combinations) {
102
- const l = combinations.length;
103
- let total = 1;
104
- const indices = combinations.map(entry => {
105
- const count = entry.length;
106
- total *= count;
107
- return [count, 0, entry];
108
- });
109
- if (total === 0) return [];
110
- let s = source;
111
- const sl = source.length;
112
- if (sl !== l) s = sl > l ? s.slice(0, l) : [...s, ...new Array(l - sl)];
113
- const out = new Array(total);
114
- let c = 0;
115
- for (;;) {
116
- let result = s;
117
- let unchanged = true;
118
- indices.forEach(([, j, values], i) => {
119
- const v = values[j];
120
- if (result[i] === v) return;
121
- if (unchanged) {
122
- result = [...result];
123
- unchanged = false;
124
- }
125
- result[i] = v;
126
- });
127
- out[c] = result;
128
- c += 1;
129
- if (c >= total) break;
130
- for (let n = l - 1; n >= 0; n -= 1) {
131
- const i = indices[n];
132
- const [max, current] = i;
133
- const next = current + 1;
134
- if (next < max) {
135
- i[1] = next;
136
- break;
137
- }
138
- i[1] = 0;
139
- }
140
- }
141
- return out;
142
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.DEFINITION_VERSION_MINOR = exports.DEFINITION_VERSION_MAJOR = exports.DEFINITION_VERSION = void 0;
7
- const DEFINITION_VERSION_MAJOR = exports.DEFINITION_VERSION_MAJOR = 1;
8
- const DEFINITION_VERSION_MINOR = exports.DEFINITION_VERSION_MINOR = 0;
9
- const DEFINITION_VERSION = exports.DEFINITION_VERSION = `${DEFINITION_VERSION_MAJOR}.${DEFINITION_VERSION_MINOR}`;
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.adaptError = adaptError;
7
- exports.adaptErrorsAsync = adaptErrorsAsync;
8
- exports.default = void 0;
9
- var _error = _interopRequireDefault(require("./error"));
10
- var _execution = _interopRequireDefault(require("./execution"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- /** Wrap occuring errors in a JPLExecutionError if they are not already a JPLError */
13
- function adaptErrors(cb) {
14
- try {
15
- return cb();
16
- } catch (err) {
17
- throw adaptError(err);
18
- }
19
- }
20
- var _default = exports.default = adaptErrors;
21
- /** Wrap occuring errors in a JPLExecutionError if they are not already a JPLError */
22
- async function adaptErrorsAsync(cb) {
23
- try {
24
- return await cb();
25
- } catch (err) {
26
- throw adaptError(err);
27
- }
28
- }
29
-
30
- /** Wrap error in a JPLExecutionError if it is not already a JPLError */
31
- function adaptError(error) {
32
- if (!_error.default.is(error)) return new _execution.default(error.message);
33
- return error;
34
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _error = _interopRequireDefault(require("./error"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- /** JPL error type for wrapping errors that should be handled elsewhere */
10
- class JPLErrorEnclosure extends _error.default {
11
- constructor(inner) {
12
- super(inner, 'JPLErrorEnclosure');
13
- this.inner = inner;
14
- }
15
- }
16
- var _default = exports.default = JPLErrorEnclosure;
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- /** Generic JPL error type */
8
- class JPLError extends Error {
9
- /** Detect whether the provided value is an instance of this error or one of its subclasses */
10
- static is(value) {
11
- return value instanceof this;
12
- }
13
- constructor(message, name = 'JPLError') {
14
- super(message);
15
- this.name = name;
16
- }
17
- }
18
- var _default = exports.default = JPLError;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _error = _interopRequireDefault(require("./error"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- /**
10
- * JPL error type for execution errors.
11
- *
12
- * All error types that infer this type can be caught in a program.
13
- */
14
- class JPLExecutionError extends _error.default {
15
- constructor(message, name = 'JPLExecutionError') {
16
- super(message, name);
17
- this.value = typeof message === 'string' && message ? message : null;
18
- }
19
- }
20
- var _default = exports.default = JPLExecutionError;
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _error = _interopRequireDefault(require("./error"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- /* JPL error type used for unrecoverable errors */
10
- class JPLFatalError extends _error.default {
11
- constructor(error) {
12
- super(error, 'JPLFatalError');
13
- }
14
- }
15
- var _default = exports.default = JPLFatalError;