@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,7 +0,0 @@
1
- import { JPLRuntimeError } from '../library';
2
-
3
- function builtin(runtime, signal, next, input) {
4
- throw new JPLRuntimeError(input);
5
- }
6
-
7
- export default builtin;
@@ -1,24 +0,0 @@
1
- import { JPLRuntimeError, JPLTypeError } from '../library';
2
-
3
- function builtin(runtime, signal, next, input) {
4
- const value = runtime.unwrapValue(input);
5
- const t = runtime.type(value);
6
-
7
- switch (t) {
8
- case 'string': {
9
- let result;
10
- try {
11
- result = JSON.parse(value);
12
- } catch (err) {
13
- throw new JPLRuntimeError(err.message);
14
- }
15
- return next(result);
16
- }
17
-
18
- default:
19
- }
20
-
21
- throw new JPLTypeError('%s (%*<100v) cannot be parsed as JSON', t, value);
22
- }
23
-
24
- export default builtin;
@@ -1,25 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- function builtin(runtime, signal, next, input, arg0) {
4
- const value = runtime.unwrapValue(input);
5
- const tv = runtime.type(value);
6
-
7
- const key = runtime.unwrapValue(arg0 ?? null);
8
- const tk = runtime.type(key);
9
-
10
- switch (tv) {
11
- case 'array':
12
- if (tk === 'number') return next(key >= 0 && key < value.length);
13
- break;
14
-
15
- case 'object':
16
- if (tk === 'string') return next(Object.hasOwn(value, key));
17
- break;
18
-
19
- default:
20
- }
21
-
22
- throw new JPLTypeError('%s (%*<100v) cannot have %s (%*<100v) as key', tv, value, tk, key);
23
- }
24
-
25
- export default builtin;
@@ -1,25 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- function builtin(runtime, signal, next, input, arg0) {
4
- const key = runtime.unwrapValue(input);
5
- const tk = runtime.type(key);
6
-
7
- const value = runtime.unwrapValue(arg0 ?? null);
8
- const tv = runtime.type(value);
9
-
10
- switch (tv) {
11
- case 'array':
12
- if (tk === 'number') return next(key >= 0 && key < value.length);
13
- break;
14
-
15
- case 'object':
16
- if (tk === 'string') return next(Object.hasOwn(value, key));
17
- break;
18
-
19
- default:
20
- }
21
-
22
- throw new JPLTypeError('%s (%*<100v) cannot have %s (%*<100v) as key', tv, value, tk, key);
23
- }
24
-
25
- export default builtin;
@@ -1,20 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- function builtin(runtime, signal, next, input) {
4
- const value = runtime.unwrapValue(input);
5
- const t = runtime.type(value);
6
-
7
- switch (t) {
8
- case 'array':
9
- return next(value.map((_, i) => i));
10
-
11
- case 'object':
12
- return next(Object.keys(value));
13
-
14
- default:
15
- }
16
-
17
- throw new JPLTypeError('%s (%*<100v) has no keys', t, value);
18
- }
19
-
20
- export default builtin;
@@ -1,26 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- function builtin(runtime, signal, next, input) {
4
- const value = runtime.unwrapValue(input);
5
- const t = runtime.type(value);
6
-
7
- switch (t) {
8
- case 'null':
9
- return next(0);
10
-
11
- case 'array':
12
- return next(value.length);
13
-
14
- case 'string':
15
- return next([...value].length);
16
-
17
- case 'object':
18
- return next(Object.keys(value).length);
19
-
20
- default:
21
- }
22
-
23
- throw new JPLTypeError('%s (%*<100v) has no length', t, value);
24
- }
25
-
26
- export default builtin;
@@ -1,5 +0,0 @@
1
- function builtin(runtime, signal, next) {
2
- return next(Date.now());
3
- }
4
-
5
- export default builtin;
@@ -1,21 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- function builtin(runtime, signal, next, input, arg0) {
4
- const value = runtime.unwrapValue(input);
5
- const t = runtime.type(value);
6
-
7
- const token = runtime.unwrapValue(arg0 ?? null);
8
- const tt = runtime.type(token);
9
-
10
- switch (t) {
11
- case 'string':
12
- if (tt === 'string') return next(value.startsWith(token));
13
- break;
14
-
15
- default:
16
- }
17
-
18
- throw new JPLTypeError('%s (%*<100v) cannot start with %s (%*<100v)', t, value, tt, token);
19
- }
20
-
21
- export default builtin;
@@ -1,5 +0,0 @@
1
- function builtin(runtime, signal, next, input) {
2
- return next(runtime.stringifyJSON(input, false));
3
- }
4
-
5
- export default builtin;
@@ -1,20 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- async function builtin(runtime, signal, next, input) {
4
- const t = runtime.type(input);
5
-
6
- switch (t) {
7
- case 'string':
8
- return next(await runtime.alterValue(input, (value) => value.toLowerCase()));
9
-
10
- default:
11
- }
12
-
13
- throw new JPLTypeError(
14
- '%s (%*<100v) cannot be converted to lower case',
15
- t,
16
- runtime.unwrapValue(input),
17
- );
18
- }
19
-
20
- export default builtin;
@@ -1,25 +0,0 @@
1
- import { JPLTypeConversionError, JPLTypeError } from '../library';
2
-
3
- function builtin(runtime, signal, next, input) {
4
- const value = runtime.unwrapValue(input);
5
- const t = runtime.type(value);
6
-
7
- switch (t) {
8
- case 'number':
9
- return next(value);
10
-
11
- case 'string': {
12
- const result = runtime.normalizeValue(+value);
13
- if (value === '' || runtime.type(result) !== 'number') {
14
- throw new JPLTypeConversionError('%s (%*<100v) does not contain a valid number', t, value);
15
- }
16
- return next(result);
17
- }
18
-
19
- default:
20
- }
21
-
22
- throw new JPLTypeError('%s (%*<100v) cannot be parsed as a number', t, value);
23
- }
24
-
25
- export default builtin;
@@ -1,5 +0,0 @@
1
- function builtin(runtime, signal, next, input) {
2
- return next(runtime.stringifyJSON(input, true));
3
- }
4
-
5
- export default builtin;
@@ -1,20 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- async function builtin(runtime, signal, next, input) {
4
- const t = runtime.type(input);
5
-
6
- switch (t) {
7
- case 'string':
8
- return next(await runtime.alterValue(input, (value) => value.toUpperCase()));
9
-
10
- default:
11
- }
12
-
13
- throw new JPLTypeError(
14
- '%s (%*<100v) cannot be converted to upper case',
15
- t,
16
- runtime.unwrapValue(input),
17
- );
18
- }
19
-
20
- export default builtin;
@@ -1,16 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- async function builtin(runtime, signal, next, input) {
4
- const t = runtime.type(input);
5
-
6
- switch (t) {
7
- case 'string':
8
- return next(await runtime.alterValue(input, (value) => value.trim()));
9
-
10
- default:
11
- }
12
-
13
- throw new JPLTypeError('%s (%*<100v) cannot be trimmed', t, runtime.unwrapValue(input));
14
- }
15
-
16
- export default builtin;
@@ -1,16 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- async function builtin(runtime, signal, next, input) {
4
- const t = runtime.type(input);
5
-
6
- switch (t) {
7
- case 'string':
8
- return next(await runtime.alterValue(input, (value) => value.trimEnd()));
9
-
10
- default:
11
- }
12
-
13
- throw new JPLTypeError('%s (%*<100v) cannot be trimmed', t, runtime.unwrapValue(input));
14
- }
15
-
16
- export default builtin;
@@ -1,16 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- async function builtin(runtime, signal, next, input) {
4
- const t = runtime.type(input);
5
-
6
- switch (t) {
7
- case 'string':
8
- return next(await runtime.alterValue(input, (value) => value.trimStart()));
9
-
10
- default:
11
- }
12
-
13
- throw new JPLTypeError('%s (%*<100v) cannot be trimmed', t, runtime.unwrapValue(input));
14
- }
15
-
16
- export default builtin;
@@ -1,5 +0,0 @@
1
- function builtin(runtime, signal, next, input) {
2
- return next(runtime.type(input));
3
- }
4
-
5
- export default builtin;
@@ -1,5 +0,0 @@
1
- function builtin() {
2
- return [];
3
- }
4
-
5
- export default builtin;
@@ -1,193 +0,0 @@
1
- import createSingleton from '../createSingleton';
2
- import systemInterpreter from '../interpreter/system';
3
- import { applyObject } from '../library';
4
- import * as internals from './internals';
5
- import * as native from './native';
6
-
7
- const builtins = `
8
- # There are additional builtins that are implemented directly in the corresponding languages.
9
- # Also the functions in the "internals" namespace are not exposed to the public and are only to be used by the builtins below.
10
-
11
- func map(f): ([.[] | f()])
12
- | func mapValues(f): (.[] |= f())
13
- | func select(f): (if f() then . else void() end)
14
- | func reduce(f, s): (
15
- l = length()
16
- | func i(i, n, c): (if n < l then i(i, n + 1, f->(.[n], c, n)) else c end)
17
- | i(i, 0, s)
18
- )
19
- | func while(cond, f): (
20
- func i(i): (if cond() then ., i->(f(), i) else void() end)
21
- | i(i)
22
- )
23
- | func until(cond, f): (
24
- func i(i): (if cond() then . else i->(f(), i) end)
25
- | i(i)
26
- )
27
- | func range(from, to, step): (
28
- t = type->(from) | if t != "number" then error->("cannot use \\(t) as a number") end
29
- | t = type->(to) | if t != "number" then error->("cannot use \\(t) as a number") end
30
- | s = (step | if . != 0 and . != null then abs() else 1 end)
31
- | while->(
32
- from,
33
- if from <= to then func (): (. < to) else func (): (. > to) end,
34
- if from <= to then func (): (. + s) else func (): (. - s) end
35
- )
36
- )
37
-
38
-
39
- # type selectors:
40
- | func isArray(): (type() == "array")
41
- | func arrays(): (select(isArray))
42
- | func isObject(): (type() == "object")
43
- | func objects(): (select(isObject))
44
- | func isIterable(): (contains->(["array", "object"], type()))
45
- | func iterables(): (select(isIterable))
46
- | func isScalar(): (not contains->(["array", "object"], type()))
47
- | func scalars(): (select(isScalar))
48
- | func isBoolean(): (type() == "boolean")
49
- | func booleans(): (select(isBoolean))
50
- | func isNumber(): (type() == "number")
51
- | func numbers(): (select(isNumber))
52
- | func isString(): (type() == "string")
53
- | func strings(): (select(isString))
54
- | func isNull(): (type() == "null")
55
- | func nulls(): (select(isNull))
56
- | func isFunction(): (type() == "function")
57
- | func functions(): (select(isFunction))
58
- | func isNullLike(): (contains->(["null", "function"], type()))
59
- | func nullLikes(): (select(isNullLike))
60
- | func isValue(): (not contains->(["null", "function"], type()))
61
- | func values(): (select(isValue))
62
- | func isContent(): (isValue() and not contains->([[], {}, ""], .))
63
- | func contents(): (select(isContent))
64
-
65
-
66
- | func toEntries(): (o = . | keys() | map(func (): ({ key: ., value: o[.] })))
67
- | func fromEntries(): (
68
- reduce(
69
- func (s): (s + { (.key ?? .Key ?? .name ?? .Name): if has("value") then .value else .Value end }),
70
- {}
71
- )
72
- )
73
- | func withEntries(f): (toEntries() | map(f) | fromEntries())
74
-
75
- | func add(): (reduce(func (sum): (sum + .)))
76
- | func join(sep): (
77
- reduce(
78
- func (sum): (
79
- if sum == null then "" else sum + sep end
80
- + (. | toString())
81
- )
82
- ) ?? ""
83
- )
84
- | func sortBy(f): ([.[] | [[f()], .]] | internals.sortEntries() | [.[][1]])
85
- | func sort(): (sortBy(func (): (.)))
86
- | func groupBy(f): (
87
- key = 0 | value = 1
88
- | [.[] | [[f()], [.]]] | internals.sortEntries()
89
- | if . == []
90
- then .
91
- else
92
- reduce->(
93
- .[1:],
94
- func (sum): (if sum[-1][key] == .[key] then (sum)[-1][value] += .[value] else sum + [.] end),
95
- .[:1]
96
- )
97
- | [.[][value]]
98
- end
99
- )
100
- | func group(): (groupBy(func (): (.)))
101
- | func uniqueBy(f): (groupBy(f) | map(func (): (.[0])))
102
- | func unique(): (group() | map(func (): (.[0])))
103
- | func recurseBy(f, cond): (
104
- c = cond ?? func (): (. != null)
105
- | func r(r): (., (f() | select(c) | r(r)))
106
- | r(r)
107
- )
108
- | func recurse(cond): (recurseBy(func (): ((arrays(), objects()) | .[]), cond))
109
- | func reverse(): ([.[length() - 1 - range(0, length())]])
110
- | func minBy(f): (
111
- key = 0 | value = 1
112
- | [.[] | [[f()], .]]
113
- | reduce->(.[1:], func (sum): (if .[key] < sum[key] then . else sum end), .[0])
114
- | .[value]
115
- )
116
- | func min(): (reduce->(.[1:], func (sum): (if . < sum then . else sum end), .[0]))
117
- | func maxBy(f): (
118
- key = 0 | value = 1
119
- | [.[] | [[f()], .]]
120
- | reduce->(.[1:], func (sum): (if .[key] > sum[key] then . else sum end), .[0])
121
- | .[value]
122
- )
123
- | func max(): (reduce->(.[1:], func (sum): (if . > sum then . else sum end), .[0]))
124
- | func first(f): ([f()][0])
125
- | func nth(which, f): (
126
- [f()]
127
- | .[if which | type() == "number" then which else length() | which() end]
128
- )
129
- | func last(f): ([f()][-1])
130
- | func isEmpty(f): (first(func (): ((f() | false), true)))
131
- | func allBy(f, cond): (isEmpty(func (): (f() | cond() and void())))
132
- | func all(cond): (allBy(func (): (.[]), cond))
133
- | func anyBy(f, cond): (not isEmpty(func (): (f() | cond() or void())))
134
- | func any(cond): (anyBy(func (): (.[]), cond))
135
-
136
- | func getPath(path): (
137
- fields = (path | if type() == 'string' then . / '.' end)
138
- | reduce->(fields, func (sum): sum[if type->(sum) == 'array' then toNumber() else toString() end], .)
139
- )
140
- | func updatePath(path, update): (
141
- fields = (path | if type() == 'string' then (. / '.')[] |= (v = . | try toNumber() catch v) end)
142
- | reduce->(
143
- reverse->(fields),
144
- func (sum): (
145
- field = .
146
- | func (): (
147
- if type() == 'array'
148
- then (
149
- input = .
150
- | try toNumber->(field) catch toString->(field)
151
- | if type() == 'number'
152
- then input[.] |= sum()
153
- else {}[.] |= sum()
154
- end
155
- ) elif type() == 'object'
156
- then (
157
- .[toString->(field)] |= sum()
158
- ) elif type->(field) == 'number'
159
- then (
160
- [][field] |= sum()
161
- ) else (
162
- {}[toString->(field)] |= sum()
163
- )
164
- end
165
- )
166
- ),
167
- update
168
- )->(.)
169
- )
170
- | func setPath(path, value): (
171
- updatePath(path, func (): value)
172
- )
173
- `;
174
-
175
- const getBuiltins = createSingleton(async () => {
176
- await undefined;
177
-
178
- let result = { ...native };
179
- const program = await systemInterpreter.parse(builtins, {
180
- runtime: {
181
- vars: { internals, ...native },
182
- adjustResult: (value, scope) => {
183
- const { internals: _, ...vars } = scope.vars;
184
- result = applyObject(result, Object.entries(vars));
185
- return [];
186
- },
187
- },
188
- });
189
- await program.run([null]);
190
- return result;
191
- });
192
-
193
- export default getBuiltins;
@@ -1,9 +0,0 @@
1
- import { nativeFunction } from '../library';
2
-
3
- export const sortEntries = nativeFunction(async (runtime, input) => [
4
- await runtime.alterValue(input, (value) =>
5
- [...value].sort((a, b) =>
6
- runtime.compareArrays(runtime.unwrapValue(a)[0], runtime.unwrapValue(b)[0]),
7
- ),
8
- ),
9
- ]);
@@ -1,44 +0,0 @@
1
- import { JPLTypeError } from '../library';
2
-
3
- function unwrapNumber(runtime, v) {
4
- const t = runtime.type(v);
5
- const u = runtime.unwrapValue(v);
6
- if (t !== 'number') {
7
- throw new JPLTypeError('%s (%*<100v) cannot be used for mathematical operations', t, u);
8
- }
9
- return u;
10
- }
11
-
12
- function funcMath(alter) {
13
- return async function builtin(runtime, signal, next, input, ...args) {
14
- const t = runtime.type(input);
15
- if (t !== 'number') {
16
- throw new JPLTypeError(
17
- '%s (%*<100v) cannot be used for mathematical operations',
18
- t,
19
- runtime.unwrapValue(input),
20
- );
21
- }
22
- return next(await runtime.alterValue(input, (value) => alter(runtime, value, ...args)));
23
- };
24
- }
25
-
26
- export const pow = funcMath((runtime, value, arg0) => value ** unwrapNumber(runtime, arg0 ?? null));
27
- export const sqrt = funcMath((runtime, value) => Math.sqrt(value));
28
- export const exp = funcMath((runtime, value) => Math.exp(value));
29
- export const log = funcMath((runtime, value) => Math.log(value));
30
- export const log10 = funcMath((runtime, value) => Math.log10(value));
31
-
32
- export const sin = funcMath((runtime, value) => Math.sin(value));
33
- export const cos = funcMath((runtime, value) => Math.cos(value));
34
- export const tan = funcMath((runtime, value) => Math.tan(value));
35
- export const asin = funcMath((runtime, value) => Math.asin(value));
36
- export const acos = funcMath((runtime, value) => Math.acos(value));
37
- export const atan = funcMath((runtime, value) => Math.atan(value));
38
-
39
- export const ceil = funcMath((runtime, value) => Math.ceil(value));
40
- export const floor = funcMath((runtime, value) => Math.floor(value));
41
- export const round = funcMath((runtime, value) => Math.round(value));
42
- export const trunc = funcMath((runtime, value) => Math.trunc(value));
43
-
44
- export const abs = funcMath((runtime, value) => Math.abs(value));
@@ -1,9 +0,0 @@
1
- function createSingleton(generatorFn) {
2
- let result;
3
- return () => {
4
- if (result == null) result = generatorFn();
5
- return result;
6
- };
7
- }
8
-
9
- export default createSingleton;
package/src/index.js DELETED
@@ -1,44 +0,0 @@
1
- import getBuiltins from './builtins';
2
- import createSingleton from './createSingleton';
3
- import JPLInterpreter, { applyInterpreterDefaults } from './interpreter';
4
- import parseFunction from './interpreter/parseFunction';
5
- import * as library from './library';
6
- import { applyProgramDefaults } from './program';
7
- import { applyRuntimeDefaults } from './runtime';
8
-
9
- const getGlobalOptions = createSingleton(async () => ({
10
- interpreter: {},
11
-
12
- program: {},
13
-
14
- runtime: {
15
- vars: { ...(await getBuiltins()) },
16
- },
17
- }));
18
-
19
- const parse = async (source, options) => {
20
- const globalOptions = await getGlobalOptions();
21
- const interpreter = new JPLInterpreter({
22
- interpreter: applyInterpreterDefaults(options?.interpreter, globalOptions.interpreter),
23
- program: applyProgramDefaults(options?.program, globalOptions.program),
24
- runtime: applyRuntimeDefaults(options?.runtime, globalOptions.runtime),
25
- });
26
- return interpreter.parse(source);
27
- };
28
-
29
- const run = async (source, inputs, options) => {
30
- const program = await parse(source, options);
31
- return program.run(inputs);
32
- };
33
-
34
- export default {
35
- ...library,
36
- run,
37
- parse,
38
- parseFunction,
39
- getBuiltins,
40
- getOptions: getGlobalOptions,
41
- };
42
-
43
- export * from './library';
44
- export { getBuiltins, getGlobalOptions as getOptions, parse, parseFunction, run };
@@ -1,48 +0,0 @@
1
- import applyDefaults from '../applyDefaults';
2
- import { DEFINITION_VERSION } from '../library';
3
- import JPLProgram, { applyProgramDefaults } from '../program';
4
- import { applyRuntimeDefaults } from '../runtime';
5
- import { parseEntrypoint } from './parse';
6
-
7
- const defaultOptions = {};
8
-
9
- export function applyInterpreterDefaults(options = {}, defaults = {}) {
10
- return applyDefaults(options, defaults);
11
- }
12
-
13
- /** JPL interpreter */
14
- class JPLInterpreter {
15
- constructor(options) {
16
- this._options = applyInterpreterDefaults(options?.interpreter, defaultOptions);
17
- this._programOptions = options?.program;
18
- this._runtimeOptions = options?.runtime;
19
- }
20
-
21
- /** Return the interpreter's options */
22
- get options() {
23
- return this._options;
24
- }
25
-
26
- /** Parse the specified source program string into a reusable JPLProgram instance */
27
- parse = async (source, options) => {
28
- const instructions = await this.parseInstructions(source);
29
-
30
- const programDefinition = {
31
- version: DEFINITION_VERSION,
32
- instructions,
33
- };
34
-
35
- return new JPLProgram(programDefinition, {
36
- program: applyProgramDefaults(options?.program, this._programOptions),
37
- runtime: applyRuntimeDefaults(options?.runtime, this._runtimeOptions),
38
- });
39
- };
40
-
41
- /** Parse the specified source program string */
42
- parseInstructions = async (source) => {
43
- const { ops: instructions } = await parseEntrypoint(source, 0, { interpreter: this });
44
- return instructions;
45
- };
46
- }
47
-
48
- export default JPLInterpreter;