@jplorg/jpl 2.0.0 → 2.1.1

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 +19 -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 +11 -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 +10 -0
  57. package/dist/types/program/ops/opAccess/opaField.d.ts +10 -0
  58. package/dist/types/program/ops/opAccess/opaFunction.d.ts +10 -0
  59. package/dist/types/program/ops/opAccess/opaIter.d.ts +10 -0
  60. package/dist/types/program/ops/opAccess/opaSlice.d.ts +10 -0
  61. package/dist/types/program/ops/opAnd.d.ts +10 -0
  62. package/dist/types/program/ops/opArrayConstructor.d.ts +10 -0
  63. package/dist/types/program/ops/opAssignment/index.d.ts +10 -0
  64. package/dist/types/program/ops/opAssignment/opaAssignField.d.ts +10 -0
  65. package/dist/types/program/ops/opAssignment/opaAssignIter.d.ts +10 -0
  66. package/dist/types/program/ops/opAssignment/opaAssignSlice.d.ts +10 -0
  67. package/dist/types/program/ops/opAssignment/opuAddition.d.ts +10 -0
  68. package/dist/types/program/ops/opAssignment/opuDivision.d.ts +10 -0
  69. package/dist/types/program/ops/opAssignment/opuMultiplication.d.ts +10 -0
  70. package/dist/types/program/ops/opAssignment/opuNullCoalescence.d.ts +10 -0
  71. package/dist/types/program/ops/opAssignment/opuRemainder.d.ts +10 -0
  72. package/dist/types/program/ops/opAssignment/opuSet.d.ts +10 -0
  73. package/dist/types/program/ops/opAssignment/opuSubtraction.d.ts +10 -0
  74. package/dist/types/program/ops/opAssignment/opuUpdate.d.ts +10 -0
  75. package/dist/types/program/ops/opCalculation/index.d.ts +10 -0
  76. package/dist/types/program/ops/opCalculation/opmAddition.d.ts +10 -0
  77. package/dist/types/program/ops/opCalculation/opmDivision.d.ts +10 -0
  78. package/dist/types/program/ops/opCalculation/opmMultiplication.d.ts +10 -0
  79. package/dist/types/program/ops/opCalculation/opmRemainder.d.ts +10 -0
  80. package/dist/types/program/ops/opCalculation/opmSubtraction.d.ts +10 -0
  81. package/dist/types/program/ops/opComparison/index.d.ts +10 -0
  82. package/dist/types/program/ops/opComparison/opcEqual.d.ts +10 -0
  83. package/dist/types/program/ops/opComparison/opcGreater.d.ts +10 -0
  84. package/dist/types/program/ops/opComparison/opcGreaterEqual.d.ts +10 -0
  85. package/dist/types/program/ops/opComparison/opcLess.d.ts +10 -0
  86. package/dist/types/program/ops/opComparison/opcLessEqual.d.ts +10 -0
  87. package/dist/types/program/ops/opComparison/opcUnequal.d.ts +10 -0
  88. package/dist/types/program/ops/opConstant.d.ts +10 -0
  89. package/dist/types/program/ops/opConstantFalse.d.ts +10 -0
  90. package/dist/types/program/ops/opConstantNull.d.ts +10 -0
  91. package/dist/types/program/ops/opConstantTrue.d.ts +10 -0
  92. package/dist/types/program/ops/opFunctionDefinition.d.ts +10 -0
  93. package/dist/types/program/ops/opIf.d.ts +10 -0
  94. package/dist/types/program/ops/opInterpolatedString.d.ts +10 -0
  95. package/dist/types/program/ops/opNegation.d.ts +10 -0
  96. package/dist/types/program/ops/opNot.d.ts +10 -0
  97. package/dist/types/program/ops/opNullCoalescence.d.ts +10 -0
  98. package/dist/types/program/ops/opNumber.d.ts +10 -0
  99. package/dist/types/program/ops/opObjectConstructor.d.ts +10 -0
  100. package/dist/types/program/ops/opOr.d.ts +10 -0
  101. package/dist/types/program/ops/opOutputConcat.d.ts +10 -0
  102. package/dist/types/program/ops/opString.d.ts +10 -0
  103. package/dist/types/program/ops/opTry.d.ts +10 -0
  104. package/dist/types/program/ops/opVariable.d.ts +10 -0
  105. package/dist/types/program/ops/opVariableDefinition.d.ts +10 -0
  106. package/dist/types/program/ops/opVoid.d.ts +10 -0
  107. package/dist/types/program/ops/utils.d.ts +5 -0
  108. package/dist/types/program/params.d.ts +67 -0
  109. package/dist/types/runtime/index.d.ts +82 -0
  110. package/package.json +59 -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,5 +0,0 @@
1
- import JPLInterpreter from '.';
2
-
3
- const systemInterpreter = new JPLInterpreter();
4
-
5
- export default systemInterpreter;
@@ -1,237 +0,0 @@
1
- import { JPLSyntaxError } from '../library';
2
-
3
- const setAZ = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
4
- const setDigit = '0123456789';
5
- const setVarFirst = `${setAZ}_$`;
6
- const setVarRest = `${setVarFirst}${setDigit}`;
7
- const setVarAll = setVarRest;
8
- const setWhitespace = ' \xa0\r\n\t';
9
- const setHex = `${setDigit}abcdefABCDEF`;
10
-
11
- /** Walk whitespace at i */
12
- export function walkWhitespace(src, i, c) {
13
- let n = i;
14
- let is = false;
15
-
16
- for (;;) {
17
- let m = match(src, n, c, { phrase: '#' });
18
- if (m.is) {
19
- ({ i: n } = m);
20
- for (;;) {
21
- const set = matchSet(src, n, c, { set: '\r\n' });
22
- if (set.is) {
23
- ({ i: n } = set);
24
- break;
25
- }
26
-
27
- const end = eot(src, n, c);
28
- if (end.is) {
29
- ({ i: n } = end);
30
- break;
31
- }
32
-
33
- n += 1;
34
- }
35
- is = true;
36
- continue;
37
- }
38
-
39
- m = match(src, n, c, { phrase: '/*' });
40
- if (m.is) {
41
- ({ i: n } = m);
42
- for (;;) {
43
- m = match(src, n, c, { phrase: '*/' });
44
- if (m.is) {
45
- ({ i: n } = m);
46
- break;
47
- }
48
-
49
- const end = eot(src, n, c);
50
- if (end.is) {
51
- ({ i: n } = end);
52
- return errorUnexpectedToken(src, n, c, {
53
- operator: 'comment',
54
- message: 'incomplete comment',
55
- });
56
- }
57
-
58
- n += 1;
59
- }
60
- is = true;
61
- continue;
62
- }
63
-
64
- const set = matchSet(src, n, c, { set: setWhitespace });
65
- ({ i: n } = set);
66
- if (!set.is) break;
67
- is = true;
68
- }
69
-
70
- return { i: n, is };
71
- }
72
-
73
- /**
74
- * Check if src matches phrase at i.
75
- * 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.
76
- * 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).
77
- * 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).
78
- * The returned index is positioned directly after the phrase or at the first unmatched character, even if spaceAfter is true.
79
- * Space is defined as anything that cannot occur in a variable name.
80
- */
81
- export function match(src, i, c, { phrase, notBeforeSet, spaceBefore, spaceAfter }) {
82
- let n = i;
83
-
84
- if (spaceBefore && i > 0) {
85
- if (!matchSet(src, n - 1, c, { set: setVarAll, exclusive: true }).is)
86
- return { i: n, is: false };
87
- }
88
-
89
- for (let j = 0; j < phrase.length; j += 1, n += 1) {
90
- const end = eot(src, n, c);
91
- if (end.is || src[n] !== phrase[j]) return { i: end.i, is: false };
92
- }
93
-
94
- if (!eot(src, n, c).is) {
95
- if (notBeforeSet && matchSet(src, n, c, { set: notBeforeSet }).is) return { i: n, is: false };
96
-
97
- if (spaceAfter && !matchSet(src, n, c, { set: setVarAll, exclusive: true }).is)
98
- return { i: n, is: false };
99
- }
100
-
101
- return { i: n, is: true };
102
- }
103
-
104
- /** The same as match, but also walk whitespace after the match if present */
105
- export function matchWord(src, i, c, { phrase, notBeforeSet, spaceBefore, spaceAfter }) {
106
- let n = i;
107
-
108
- const m = match(src, n, c, { phrase, notBeforeSet, spaceBefore, spaceAfter });
109
- if (!m.is) return { i: m.i, is: false };
110
- ({ i: n } = m);
111
-
112
- ({ i: n } = walkWhitespace(src, n, c));
113
-
114
- return { i: n, is: true };
115
- }
116
-
117
- /** Check if i is a hexadecimal value */
118
- export function hex(src, i, c) {
119
- return matchSet(src, i, c, { set: setHex });
120
- }
121
-
122
- /**
123
- * Check if i is one of the chars in set.
124
- * If exclusive is true, i must not be one of the chars in set for the check to succeed.
125
- */
126
- export function matchSet(src, i, c, { set, exclusive }) {
127
- const end = eot(src, i, c);
128
- if (end.is) return { i: end.i, is: false };
129
-
130
- const char = src[i];
131
- if (set.includes(char) === !exclusive) return { i: i + 1, is: true, value: char };
132
-
133
- return { i, is: false, value: '' };
134
- }
135
-
136
- /** Parse variable selector at i */
137
- export function variable(src, i, c) {
138
- let n = i;
139
- let is = false;
140
- let value = '';
141
-
142
- for (;;) {
143
- const set = matchSet(src, n, c, { set: !is ? setVarFirst : setVarRest });
144
- ({ i: n } = set);
145
- if (!set.is) break;
146
- is = true;
147
- value += set.value;
148
- }
149
-
150
- if (is) ({ i: n } = walkWhitespace(src, n, c));
151
-
152
- return { i: n, is, value };
153
- }
154
-
155
- /** The same as variable, but also check that the result is not a reserved term */
156
- export function safeVariable(src, i, c) {
157
- const v = variable(src, i, c);
158
-
159
- if (!v.is) return v;
160
-
161
- switch (v.value) {
162
- case 'and':
163
- case 'catch':
164
- case 'func':
165
- case 'elif':
166
- case 'else':
167
- case 'end':
168
- case 'false':
169
- case 'if':
170
- case 'not':
171
- case 'null':
172
- case 'or':
173
- case 'then':
174
- case 'true':
175
- case 'try':
176
- return { i, is: false, value: v.value, reserved: true };
177
-
178
- default:
179
- return v;
180
- }
181
- }
182
-
183
- /** Check if i is at the end of src */
184
- export function eot(src, i) {
185
- if (i >= src.length) return { i: src.length, is: true };
186
- return { i, is: false };
187
- }
188
-
189
- /** Get (zero based) line and column for i */
190
- export function whereIs(src, i) {
191
- const lines = src.substring(0, i).split(/\r?\n|\r/);
192
- const line = lines[lines.length - 1];
193
- return { i, line: lines.length - 1, column: line.length };
194
- }
195
-
196
- /** Get a descriptive text highlighting i */
197
- export function highlightLocation(src, i, c, { area = 25 } = {}) {
198
- const s = Math.max(Math.min(i, src.length - 1 - area), area) - area;
199
- const e = Math.min(s + area + 1 + area, src.length);
200
- const view = src
201
- .substring(s, e)
202
- .replaceAll(/\r?\n|\r/g, '⏎')
203
- .replaceAll('\t', '→');
204
-
205
- let prefix = ' > ';
206
- if (s > 0) prefix += '…';
207
-
208
- let suffix = '';
209
- if (e < src.length) suffix = '…';
210
-
211
- const description = `${prefix}${view}${suffix}\n${' '.repeat(prefix.length + (i - s))}^ here`;
212
-
213
- return { i, value: description };
214
- }
215
-
216
- /** Throw an error caused by an unexpected token at i */
217
- export function errorUnexpectedToken(src, i, c, { operator, message } = {}) {
218
- let errorMessage;
219
- if (eot(src, i, c).is) errorMessage = 'unexpected EOT';
220
- else {
221
- const { line, column } = whereIs(src, i, c);
222
- errorMessage = `unexpected token '${src[i]}' at line ${line + 1}, column ${column + 1}`;
223
- }
224
- if (operator) errorMessage += ` while parsing ${operator}`;
225
- if (message) errorMessage += `: ${message}`;
226
- errorMessage += `\n${highlightLocation(src, i, c).value}`;
227
- throw new JPLSyntaxError(errorMessage, src, i);
228
- }
229
-
230
- /** Throw an error caused by a generic parser error at i */
231
- export function errorGeneric(src, i, c, { operator, message } = {}) {
232
- let errorMessage = 'error';
233
- if (operator) errorMessage += ` while parsing ${operator}`;
234
- if (message) errorMessage += `: ${message}`;
235
- errorMessage += `\n${highlightLocation(src, i, c).value}`;
236
- throw new JPLSyntaxError(errorMessage, src, i);
237
- }
@@ -1,135 +0,0 @@
1
- /**
2
- * Apply all changes immutably to the source object.
3
- *
4
- * @param {[key: string, value: any][]} changes The changes to be applied
5
- */
6
- export function applyObject(source, changes) {
7
- let result = source;
8
- let unchanged = true;
9
-
10
- changes.forEach((entry) => {
11
- const [key, value] = entry;
12
-
13
- if (entry.length === 1) {
14
- if (!Object.hasOwn(result, key)) return;
15
- if (unchanged) {
16
- let _;
17
- ({ [key]: _, ...result } = result);
18
- unchanged = false;
19
- } else {
20
- delete result[key];
21
- }
22
- return;
23
- }
24
-
25
- if (Object.hasOwn(result, key) && result[key] === value) return;
26
- if (unchanged) {
27
- result = { ...result, [key]: value };
28
- unchanged = false;
29
- } else {
30
- result[key] = value;
31
- }
32
- });
33
-
34
- return result;
35
- }
36
-
37
- /**
38
- * Apply all changes immutably to the source array.
39
- * Indices can be negative to be applied from the end of the array.
40
- *
41
- * @param {[index: string, value: any][]} changes The changes to be applied
42
- * @param filler Value to be used as padding
43
- */
44
- export function applyArray(source, changes, filler = null) {
45
- let result = source;
46
- let unchanged = true;
47
-
48
- changes.forEach((entry) => {
49
- const [index, value] = entry;
50
- let i = index >= 0 ? index : result.length + index;
51
-
52
- if (i >= 0 && i < result.length && result[i] === value) return;
53
- if (index >= 0) {
54
- const suf = i + 1 - result.length;
55
- if (suf > 0) {
56
- result = [...result, ...new Array(suf).fill(filler)];
57
- unchanged = false;
58
- }
59
- } else {
60
- const pre = -i;
61
- if (pre > 0) {
62
- result = [...new Array(pre).fill(filler), ...result];
63
- unchanged = false;
64
- i = 0;
65
- }
66
- }
67
- if (unchanged) {
68
- result = [...result];
69
- unchanged = false;
70
- }
71
- result[i] = value;
72
- });
73
-
74
- return result;
75
- }
76
-
77
- /**
78
- * Create all possible combinations immutably based on the specified source array.
79
- * If the specified `combinations` array is empty, the resulting array contains a single empty array.
80
- * 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.
81
- *
82
- * `applyCombinations([], [[1, 2], [3, 4]])` for example produces:
83
- * - `[1, 3]`
84
- * - `[1, 4]`
85
- * - `[2, 3]`
86
- * - `[2, 4]`
87
- *
88
- * 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.:
89
- * `let i = [1, 2]; applyCombinations(i, [[1], [2]])[0] == i`
90
- * - `true`
91
- *
92
- * @param {any[][]} combinations The combinations
93
- */
94
- export function applyCombinations(source, combinations) {
95
- const l = combinations.length;
96
- let total = 1;
97
- const indices = combinations.map((entry) => {
98
- const count = entry.length;
99
- total *= count;
100
- return [count, 0, entry];
101
- });
102
- if (total === 0) return [];
103
- let s = source;
104
- const sl = source.length;
105
- if (sl !== l) s = sl > l ? s.slice(0, l) : [...s, ...new Array(l - sl)];
106
- const out = new Array(total);
107
- let c = 0;
108
- for (;;) {
109
- let result = s;
110
- let unchanged = true;
111
- indices.forEach(([, j, values], i) => {
112
- const v = values[j];
113
- if (result[i] === v) return;
114
- if (unchanged) {
115
- result = [...result];
116
- unchanged = false;
117
- }
118
- result[i] = v;
119
- });
120
- out[c] = result;
121
- c += 1;
122
- if (c >= total) break;
123
- for (let n = l - 1; n >= 0; n -= 1) {
124
- const i = indices[n];
125
- const [max, current] = i;
126
- const next = current + 1;
127
- if (next < max) {
128
- i[1] = next;
129
- break;
130
- }
131
- i[1] = 0;
132
- }
133
- }
134
- return out;
135
- }
@@ -1,3 +0,0 @@
1
- export const DEFINITION_VERSION_MAJOR = 1;
2
- export const DEFINITION_VERSION_MINOR = 0;
3
- export const DEFINITION_VERSION = `${DEFINITION_VERSION_MAJOR}.${DEFINITION_VERSION_MINOR}`;
@@ -1,28 +0,0 @@
1
- import JPLError from './error';
2
- import JPLExecutionError from './execution';
3
-
4
- /** Wrap occuring errors in a JPLExecutionError if they are not already a JPLError */
5
- function adaptErrors(cb) {
6
- try {
7
- return cb();
8
- } catch (err) {
9
- throw adaptError(err);
10
- }
11
- }
12
-
13
- export default adaptErrors;
14
-
15
- /** Wrap occuring errors in a JPLExecutionError if they are not already a JPLError */
16
- export async function adaptErrorsAsync(cb) {
17
- try {
18
- return await cb();
19
- } catch (err) {
20
- throw adaptError(err);
21
- }
22
- }
23
-
24
- /** Wrap error in a JPLExecutionError if it is not already a JPLError */
25
- export function adaptError(error) {
26
- if (!JPLError.is(error)) return new JPLExecutionError(error.message);
27
- return error;
28
- }
@@ -1,11 +0,0 @@
1
- import JPLError from './error';
2
-
3
- /** JPL error type for wrapping errors that should be handled elsewhere */
4
- class JPLErrorEnclosure extends JPLError {
5
- constructor(inner) {
6
- super(inner, 'JPLErrorEnclosure');
7
- this.inner = inner;
8
- }
9
- }
10
-
11
- export default JPLErrorEnclosure;
@@ -1,14 +0,0 @@
1
- /** Generic JPL error type */
2
- class JPLError extends Error {
3
- /** Detect whether the provided value is an instance of this error or one of its subclasses */
4
- static is(value) {
5
- return value instanceof this;
6
- }
7
-
8
- constructor(message, name = 'JPLError') {
9
- super(message);
10
- this.name = name;
11
- }
12
- }
13
-
14
- export default JPLError;
@@ -1,15 +0,0 @@
1
- import JPLError from './error';
2
-
3
- /**
4
- * JPL error type for execution errors.
5
- *
6
- * All error types that infer this type can be caught in a program.
7
- */
8
- class JPLExecutionError extends JPLError {
9
- constructor(message, name = 'JPLExecutionError') {
10
- super(message, name);
11
- this.value = typeof message === 'string' && message ? message : null;
12
- }
13
- }
14
-
15
- export default JPLExecutionError;
@@ -1,10 +0,0 @@
1
- import JPLError from './error';
2
-
3
- /* JPL error type used for unrecoverable errors */
4
- class JPLFatalError extends JPLError {
5
- constructor(error) {
6
- super(error, 'JPLFatalError');
7
- }
8
- }
9
-
10
- export default JPLFatalError;
@@ -1,71 +0,0 @@
1
- import { displayValue, normalize, template } from '../types';
2
- import JPLExecutionError from './execution';
3
-
4
- function format(value, replacements) {
5
- return replacements.length > 0 ? template(value, ...replacements) : displayValue(value);
6
- }
7
-
8
- /**
9
- * JPL error type for generic runtime errors.
10
- *
11
- * `value` can by of any type.
12
- * If at least one replacement is specified, the value is formatted as a template.
13
- */
14
- class JPLRuntimeError extends JPLExecutionError {
15
- constructor(value, ...replacements) {
16
- const message = format(value, replacements);
17
-
18
- super(message, 'JPLRuntimeError');
19
- this.value = replacements.length > 0 ? message : normalize(value);
20
- }
21
- }
22
-
23
- export default JPLRuntimeError;
24
-
25
- /**
26
- * JPL runtime error type for type errors.
27
- *
28
- * `value` can by of any type.
29
- * If at least one replacement is specified, the value is formatted as a template.
30
- */
31
- export class JPLTypeError extends JPLRuntimeError {
32
- constructor(value, ...replacements) {
33
- super(`TypeError - ${format(value, replacements)}`);
34
- }
35
- }
36
-
37
- /**
38
- * JPL runtime error type for reference errors.
39
- *
40
- * `value` can by of any type.
41
- * If at least one replacement is specified, the value is formatted as a template.
42
- */
43
- export class JPLReferenceError extends JPLRuntimeError {
44
- constructor(value, ...replacements) {
45
- super(`ReferenceError - ${format(value, replacements)}`);
46
- }
47
- }
48
-
49
- /**
50
- * JPL runtime error type for zero division errors.
51
- *
52
- * `value` can by of any type.
53
- * If at least one replacement is specified, the value is formatted as a template.
54
- */
55
- export class JPLZeroDivisionError extends JPLRuntimeError {
56
- constructor(value, ...replacements) {
57
- super(`ZeroDivisionError - ${format(value, replacements)}`);
58
- }
59
- }
60
-
61
- /**
62
- * JPL runtime error type for type conversion errors.
63
- *
64
- * `value` can by of any type.
65
- * If at least one replacement is specified, the value is formatted as a template.
66
- */
67
- export class JPLTypeConversionError extends JPLRuntimeError {
68
- constructor(value, ...replacements) {
69
- super(`TypeConversionError - ${format(value, replacements)}`);
70
- }
71
- }
@@ -1,12 +0,0 @@
1
- import JPLError from './error';
2
-
3
- /** JPL error type for syntax errors */
4
- class JPLSyntaxError extends JPLError {
5
- constructor(message, src = '', at = 0) {
6
- super(message, 'JPLSyntaxError');
7
- this.src = src;
8
- this.at = at;
9
- }
10
- }
11
-
12
- export default JPLSyntaxError;
@@ -1,41 +0,0 @@
1
- export { applyArray, applyCombinations, applyObject } from './apply';
2
- export {
3
- DEFINITION_VERSION,
4
- DEFINITION_VERSION_MAJOR,
5
- DEFINITION_VERSION_MINOR,
6
- } from './definition';
7
- export { adaptError, default as adaptErrors, adaptErrorsAsync } from './errors/adaptErrors';
8
- export { default as JPLErrorEnclosure } from './errors/enclosure';
9
- export { default as JPLError } from './errors/error';
10
- export { default as JPLExecutionError } from './errors/execution';
11
- export { default as JPLFatalError } from './errors/fatal';
12
- export {
13
- JPLReferenceError,
14
- default as JPLRuntimeError,
15
- JPLTypeConversionError,
16
- JPLTypeError,
17
- JPLZeroDivisionError,
18
- } from './errors/runtime';
19
- export { default as JPLSyntaxError } from './errors/syntax';
20
- export { nativeFunction, orphanFunction, scopedFunction } from './functions';
21
- export { default as mux, muxAll, muxAsync, muxOne } from './mux';
22
- export * from './ops';
23
- export { default as JPLRuntimeScope } from './runtimeScope';
24
- export {
25
- JPLType,
26
- assertType,
27
- displayValue,
28
- jplJSONStripper,
29
- jplStripper,
30
- jplTypedStripper,
31
- jsonStripper,
32
- normalize,
33
- rawStripper,
34
- strictDisplayValue,
35
- stringify,
36
- strip,
37
- template,
38
- typeOf,
39
- typeOrder,
40
- unwrap,
41
- } from './types';
@@ -1,98 +0,0 @@
1
- /**
2
- * Multiplex the specified array of arguments by calling cb for all possible combinations of arguments.
3
- * If the specified `args` array is empty, `cb` is called once without any arguments.
4
- *
5
- * `mux([[1, 2], [3, 4]], cb)` for example calls:
6
- * - `cb(1, 3)`
7
- * - `cb(1, 4)`
8
- * - `cb(2, 3)`
9
- * - `cb(2, 4)`
10
- */
11
- function mux(args, cb) {
12
- const argCount = args.length;
13
- if (argCount === 1) {
14
- args[0].forEach((arg) => cb(arg));
15
- return;
16
- }
17
- let execCount = 1;
18
- const indices = args.map((arg) => {
19
- const argLength = arg?.length ?? 0;
20
- execCount *= argLength;
21
- return [argLength, 0, arg];
22
- });
23
- if (execCount === 0) return;
24
- const buffer = args.map(([v]) => v);
25
- let execIndex = 0;
26
- for (;;) {
27
- cb(...buffer);
28
- execIndex += 1;
29
- if (execIndex >= execCount) break;
30
- // determine next combination
31
- for (let argIndex = argCount - 1; argIndex >= 0; argIndex -= 1) {
32
- const arg = indices[argIndex];
33
- const [max, current, values] = arg;
34
- const next = current + 1;
35
- if (next < max) {
36
- arg[1] = next;
37
- buffer[argIndex] = values[next];
38
- break;
39
- }
40
- arg[1] = 0;
41
- [buffer[argIndex]] = values;
42
- }
43
- }
44
- }
45
-
46
- export default mux;
47
-
48
- /** Multiplex the specified array of arguments and return the results produced by the callbacks */
49
- export function muxOne(args, cb) {
50
- const argCount = args.length;
51
- if (argCount === 1) return args[0].map((arg) => cb(arg));
52
- let execCount = 1;
53
- const indices = args.map((arg) => {
54
- const argLength = arg?.length ?? 0;
55
- execCount *= argLength;
56
- return [argLength, 0, arg];
57
- });
58
- if (execCount === 0) return [];
59
- const outputs = new Array(execCount);
60
- const buffer = args.map(([v]) => v);
61
- let execIndex = 0;
62
- for (;;) {
63
- outputs[execIndex] = cb(...buffer);
64
- execIndex += 1;
65
- if (execIndex >= execCount) break;
66
- // determine next combination
67
- for (let argIndex = argCount - 1; argIndex >= 0; argIndex -= 1) {
68
- const arg = indices[argIndex];
69
- const [max, current, values] = arg;
70
- const next = current + 1;
71
- if (next < max) {
72
- arg[1] = next;
73
- buffer[argIndex] = values[next];
74
- break;
75
- }
76
- arg[1] = 0;
77
- [buffer[argIndex]] = values;
78
- }
79
- }
80
- return outputs;
81
- }
82
-
83
- /** Multiplex the specified array of arguments asynchronously and return the results produced by the callbacks */
84
- export function muxAsync(args, cb) {
85
- return Promise.all(muxOne(args, cb));
86
- }
87
-
88
- /** Multiplex the specified array of arguments asynchronously and return a single array of all merged result arrays produced by the callbacks */
89
- export async function muxAll(args, cb) {
90
- return mergeSegments(await muxAsync(args, cb));
91
- }
92
-
93
- /** Create a single array from the specified array segments */
94
- export function mergeSegments(segments) {
95
- if (segments.length === 0) return segments;
96
- if (segments.length === 1) return segments[0];
97
- return segments.flat(1);
98
- }