@jplorg/jpl 1.5.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. package/dist/esm/main.js +3474 -0
  2. package/dist/types/applyDefaults.d.ts +2 -0
  3. package/dist/types/builtins/funcContains.d.ts +3 -0
  4. package/dist/types/builtins/funcEndsWith.d.ts +3 -0
  5. package/dist/types/builtins/funcError.d.ts +3 -0
  6. package/dist/types/builtins/funcFromJSON.d.ts +3 -0
  7. package/dist/types/builtins/funcHas.d.ts +3 -0
  8. package/dist/types/builtins/funcIn.d.ts +3 -0
  9. package/dist/types/builtins/funcKeys.d.ts +3 -0
  10. package/dist/types/builtins/funcLength.d.ts +3 -0
  11. package/dist/types/builtins/funcNow.d.ts +3 -0
  12. package/dist/types/builtins/funcStartsWith.d.ts +3 -0
  13. package/dist/types/builtins/funcToJSON.d.ts +3 -0
  14. package/dist/types/builtins/funcToLowerCase.d.ts +3 -0
  15. package/dist/types/builtins/funcToNumber.d.ts +3 -0
  16. package/dist/types/builtins/funcToString.d.ts +3 -0
  17. package/dist/types/builtins/funcToUpperCase.d.ts +3 -0
  18. package/dist/types/builtins/funcTrim.d.ts +3 -0
  19. package/dist/types/builtins/funcTrimEnd.d.ts +3 -0
  20. package/dist/types/builtins/funcTrimStart.d.ts +3 -0
  21. package/dist/types/builtins/funcType.d.ts +3 -0
  22. package/dist/types/builtins/funcVoid.d.ts +3 -0
  23. package/dist/types/builtins/index.d.ts +2 -0
  24. package/dist/types/builtins/internals.d.ts +1 -0
  25. package/dist/types/builtins/math.d.ts +17 -0
  26. package/dist/types/createSingleton.d.ts +1 -0
  27. package/dist/types/interpreter/index.d.ts +21 -0
  28. package/dist/types/interpreter/parse.d.ts +194 -0
  29. package/{src/interpreter/parseFunction.js → dist/types/interpreter/parseFunction.d.ts} +2 -10
  30. package/dist/types/interpreter/system.d.ts +3 -0
  31. package/dist/types/interpreter/util.d.ts +89 -0
  32. package/dist/types/library/apply.d.ts +32 -0
  33. package/dist/types/library/definition.d.ts +79 -0
  34. package/dist/types/library/errors/adaptErrors.d.ts +6 -0
  35. package/dist/types/library/errors/enclosure.d.ts +6 -0
  36. package/dist/types/library/errors/error.d.ts +6 -0
  37. package/dist/types/library/errors/execution.d.ts +12 -0
  38. package/dist/types/library/errors/fatal.d.ts +4 -0
  39. package/dist/types/library/errors/runtime.d.ts +46 -0
  40. package/dist/types/library/errors/syntax.d.ts +7 -0
  41. package/{src/library/functions.js → dist/types/library/functions.d.ts} +9 -30
  42. package/dist/types/library/index.d.ts +18 -0
  43. package/dist/types/library/mux.d.ts +19 -0
  44. package/{src/library/ops/op.js → dist/types/library/ops/op.d.ts} +25 -49
  45. package/{src/library/ops/opa.js → dist/types/library/ops/opa.d.ts} +4 -7
  46. package/{src/library/ops/opc.js → dist/types/library/ops/opc.d.ts} +6 -11
  47. package/{src/library/ops/opm.js → dist/types/library/ops/opm.d.ts} +5 -9
  48. package/{src/library/ops/opu.js → dist/types/library/ops/opu.d.ts} +8 -15
  49. package/dist/types/library/runtimeScope.d.ts +23 -0
  50. package/dist/types/library/runtimeSignal.d.ts +25 -0
  51. package/dist/types/library/types.d.ts +97 -0
  52. package/dist/types/main.d.ts +19 -0
  53. package/dist/types/program/handler.d.ts +12 -0
  54. package/dist/types/program/index.d.ts +40 -0
  55. package/dist/types/program/ops/index.d.ts +5 -0
  56. package/dist/types/program/ops/opAccess/index.d.ts +11 -0
  57. package/dist/types/program/ops/opAccess/opaField.d.ts +11 -0
  58. package/dist/types/program/ops/opAccess/opaFunction.d.ts +11 -0
  59. package/dist/types/program/ops/opAccess/opaIter.d.ts +11 -0
  60. package/dist/types/program/ops/opAccess/opaSlice.d.ts +11 -0
  61. package/dist/types/program/ops/opAnd.d.ts +11 -0
  62. package/dist/types/program/ops/opArrayConstructor.d.ts +11 -0
  63. package/dist/types/program/ops/opAssignment/index.d.ts +11 -0
  64. package/dist/types/program/ops/opAssignment/opaAssignField.d.ts +11 -0
  65. package/dist/types/program/ops/opAssignment/opaAssignIter.d.ts +11 -0
  66. package/dist/types/program/ops/opAssignment/opaAssignSlice.d.ts +11 -0
  67. package/dist/types/program/ops/opAssignment/opuAddition.d.ts +11 -0
  68. package/dist/types/program/ops/opAssignment/opuDivision.d.ts +11 -0
  69. package/dist/types/program/ops/opAssignment/opuMultiplication.d.ts +11 -0
  70. package/dist/types/program/ops/opAssignment/opuNullCoalescence.d.ts +11 -0
  71. package/dist/types/program/ops/opAssignment/opuRemainder.d.ts +11 -0
  72. package/dist/types/program/ops/opAssignment/opuSet.d.ts +11 -0
  73. package/dist/types/program/ops/opAssignment/opuSubtraction.d.ts +11 -0
  74. package/dist/types/program/ops/opAssignment/opuUpdate.d.ts +11 -0
  75. package/dist/types/program/ops/opCalculation/index.d.ts +11 -0
  76. package/dist/types/program/ops/opCalculation/opmAddition.d.ts +11 -0
  77. package/dist/types/program/ops/opCalculation/opmDivision.d.ts +11 -0
  78. package/dist/types/program/ops/opCalculation/opmMultiplication.d.ts +11 -0
  79. package/dist/types/program/ops/opCalculation/opmRemainder.d.ts +11 -0
  80. package/dist/types/program/ops/opCalculation/opmSubtraction.d.ts +11 -0
  81. package/dist/types/program/ops/opComparison/index.d.ts +11 -0
  82. package/dist/types/program/ops/opComparison/opcEqual.d.ts +11 -0
  83. package/dist/types/program/ops/opComparison/opcGreater.d.ts +11 -0
  84. package/dist/types/program/ops/opComparison/opcGreaterEqual.d.ts +11 -0
  85. package/dist/types/program/ops/opComparison/opcLess.d.ts +11 -0
  86. package/dist/types/program/ops/opComparison/opcLessEqual.d.ts +11 -0
  87. package/dist/types/program/ops/opComparison/opcUnequal.d.ts +11 -0
  88. package/dist/types/program/ops/opConstant.d.ts +11 -0
  89. package/dist/types/program/ops/opConstantFalse.d.ts +11 -0
  90. package/dist/types/program/ops/opConstantNull.d.ts +11 -0
  91. package/dist/types/program/ops/opConstantTrue.d.ts +11 -0
  92. package/dist/types/program/ops/opFunctionDefinition.d.ts +11 -0
  93. package/dist/types/program/ops/opIf.d.ts +11 -0
  94. package/dist/types/program/ops/opInterpolatedString.d.ts +11 -0
  95. package/dist/types/program/ops/opNegation.d.ts +11 -0
  96. package/dist/types/program/ops/opNot.d.ts +11 -0
  97. package/dist/types/program/ops/opNullCoalescence.d.ts +11 -0
  98. package/dist/types/program/ops/opNumber.d.ts +11 -0
  99. package/dist/types/program/ops/opObjectConstructor.d.ts +11 -0
  100. package/dist/types/program/ops/opOr.d.ts +11 -0
  101. package/dist/types/program/ops/opOutputConcat.d.ts +11 -0
  102. package/dist/types/program/ops/opString.d.ts +11 -0
  103. package/dist/types/program/ops/opTry.d.ts +11 -0
  104. package/dist/types/program/ops/opVariable.d.ts +11 -0
  105. package/dist/types/program/ops/opVariableDefinition.d.ts +11 -0
  106. package/dist/types/program/ops/opVoid.d.ts +11 -0
  107. package/dist/types/program/ops/utils.d.ts +5 -0
  108. package/dist/types/program/params.d.ts +68 -0
  109. package/dist/types/runtime/index.d.ts +83 -0
  110. package/package.json +66 -49
  111. package/{repl.js → repl.ts} +85 -39
  112. package/lib/applyDefaults.js +0 -34
  113. package/lib/builtins/funcContains.js +0 -25
  114. package/lib/builtins/funcEndsWith.js +0 -21
  115. package/lib/builtins/funcError.js +0 -11
  116. package/lib/builtins/funcFromJSON.js +0 -26
  117. package/lib/builtins/funcHas.js +0 -24
  118. package/lib/builtins/funcIn.js +0 -24
  119. package/lib/builtins/funcKeys.js +0 -20
  120. package/lib/builtins/funcLength.js +0 -24
  121. package/lib/builtins/funcNow.js +0 -10
  122. package/lib/builtins/funcStartsWith.js +0 -21
  123. package/lib/builtins/funcToJSON.js +0 -10
  124. package/lib/builtins/funcToLowerCase.js +0 -17
  125. package/lib/builtins/funcToNumber.js +0 -26
  126. package/lib/builtins/funcToString.js +0 -10
  127. package/lib/builtins/funcToUpperCase.js +0 -17
  128. package/lib/builtins/funcTrim.js +0 -17
  129. package/lib/builtins/funcTrimEnd.js +0 -17
  130. package/lib/builtins/funcTrimStart.js +0 -17
  131. package/lib/builtins/funcType.js +0 -10
  132. package/lib/builtins/funcVoid.js +0 -10
  133. package/lib/builtins/index.js +0 -205
  134. package/lib/builtins/internals.js +0 -8
  135. package/lib/builtins/math.js +0 -40
  136. package/lib/builtins/native.js +0 -180
  137. package/lib/createSingleton.js +0 -14
  138. package/lib/index.js +0 -79
  139. package/lib/interpreter/index.js +0 -56
  140. package/lib/interpreter/parse.js +0 -2377
  141. package/lib/interpreter/parseFunction.js +0 -24
  142. package/lib/interpreter/system.js +0 -10
  143. package/lib/interpreter/util.js +0 -349
  144. package/lib/library/apply.js +0 -142
  145. package/lib/library/definition.js +0 -9
  146. package/lib/library/errors/adaptErrors.js +0 -34
  147. package/lib/library/errors/enclosure.js +0 -16
  148. package/lib/library/errors/error.js +0 -18
  149. package/lib/library/errors/execution.js +0 -20
  150. package/lib/library/errors/fatal.js +0 -15
  151. package/lib/library/errors/runtime.js +0 -78
  152. package/lib/library/errors/syntax.js +0 -17
  153. package/lib/library/functions.js +0 -82
  154. package/lib/library/index.js +0 -335
  155. package/lib/library/mux.js +0 -106
  156. package/lib/library/ops/index.js +0 -60
  157. package/lib/library/ops/op.js +0 -180
  158. package/lib/library/ops/opa.js +0 -41
  159. package/lib/library/ops/opc.js +0 -59
  160. package/lib/library/ops/opm.js +0 -50
  161. package/lib/library/ops/opu.js +0 -77
  162. package/lib/library/runtimeScope.js +0 -38
  163. package/lib/library/runtimeSignal.js +0 -72
  164. package/lib/library/types.js +0 -304
  165. package/lib/program/index.js +0 -101
  166. package/lib/program/ops/index.js +0 -61
  167. package/lib/program/ops/opAccess/index.js +0 -55
  168. package/lib/program/ops/opAccess/opaField.js +0 -50
  169. package/lib/program/ops/opAccess/opaFunction.js +0 -50
  170. package/lib/program/ops/opAccess/opaIter.js +0 -31
  171. package/lib/program/ops/opAccess/opaSlice.js +0 -44
  172. package/lib/program/ops/opAnd.js +0 -30
  173. package/lib/program/ops/opArrayConstructor.js +0 -20
  174. package/lib/program/ops/opAssignment/index.js +0 -90
  175. package/lib/program/ops/opAssignment/opaAssignField.js +0 -125
  176. package/lib/program/ops/opAssignment/opaAssignIter.js +0 -69
  177. package/lib/program/ops/opAssignment/opaAssignSlice.js +0 -99
  178. package/lib/program/ops/opAssignment/opuAddition.js +0 -31
  179. package/lib/program/ops/opAssignment/opuDivision.js +0 -31
  180. package/lib/program/ops/opAssignment/opuMultiplication.js +0 -31
  181. package/lib/program/ops/opAssignment/opuNullCoalescence.js +0 -25
  182. package/lib/program/ops/opAssignment/opuRemainder.js +0 -31
  183. package/lib/program/ops/opAssignment/opuSet.js +0 -19
  184. package/lib/program/ops/opAssignment/opuSubtraction.js +0 -31
  185. package/lib/program/ops/opAssignment/opuUpdate.js +0 -19
  186. package/lib/program/ops/opCalculation/index.js +0 -57
  187. package/lib/program/ops/opCalculation/opmAddition.js +0 -49
  188. package/lib/program/ops/opCalculation/opmDivision.js +0 -42
  189. package/lib/program/ops/opCalculation/opmMultiplication.js +0 -40
  190. package/lib/program/ops/opCalculation/opmRemainder.js +0 -34
  191. package/lib/program/ops/opCalculation/opmSubtraction.js +0 -53
  192. package/lib/program/ops/opComparison/index.js +0 -59
  193. package/lib/program/ops/opComparison/opcEqual.js +0 -19
  194. package/lib/program/ops/opComparison/opcGreater.js +0 -19
  195. package/lib/program/ops/opComparison/opcGreaterEqual.js +0 -19
  196. package/lib/program/ops/opComparison/opcLess.js +0 -19
  197. package/lib/program/ops/opComparison/opcLessEqual.js +0 -19
  198. package/lib/program/ops/opComparison/opcUnequal.js +0 -19
  199. package/lib/program/ops/opConstant.js +0 -18
  200. package/lib/program/ops/opConstantFalse.js +0 -16
  201. package/lib/program/ops/opConstantNull.js +0 -16
  202. package/lib/program/ops/opConstantTrue.js +0 -16
  203. package/lib/program/ops/opFunctionDefinition.js +0 -21
  204. package/lib/program/ops/opIf.js +0 -38
  205. package/lib/program/ops/opInterpolatedString.js +0 -24
  206. package/lib/program/ops/opNegation.js +0 -25
  207. package/lib/program/ops/opNot.js +0 -16
  208. package/lib/program/ops/opNullCoalescence.js +0 -34
  209. package/lib/program/ops/opNumber.js +0 -18
  210. package/lib/program/ops/opObjectConstructor.js +0 -37
  211. package/lib/program/ops/opOr.js +0 -30
  212. package/lib/program/ops/opOutputConcat.js +0 -19
  213. package/lib/program/ops/opString.js +0 -18
  214. package/lib/program/ops/opTry.js +0 -37
  215. package/lib/program/ops/opVariable.js +0 -20
  216. package/lib/program/ops/opVariableDefinition.js +0 -24
  217. package/lib/program/ops/opVoid.js +0 -16
  218. package/lib/program/ops/utils.js +0 -35
  219. package/lib/runtime/index.js +0 -258
  220. package/src/applyDefaults.js +0 -35
  221. package/src/builtins/funcContains.js +0 -27
  222. package/src/builtins/funcEndsWith.js +0 -21
  223. package/src/builtins/funcError.js +0 -7
  224. package/src/builtins/funcFromJSON.js +0 -24
  225. package/src/builtins/funcHas.js +0 -25
  226. package/src/builtins/funcIn.js +0 -25
  227. package/src/builtins/funcKeys.js +0 -20
  228. package/src/builtins/funcLength.js +0 -26
  229. package/src/builtins/funcNow.js +0 -5
  230. package/src/builtins/funcStartsWith.js +0 -21
  231. package/src/builtins/funcToJSON.js +0 -5
  232. package/src/builtins/funcToLowerCase.js +0 -20
  233. package/src/builtins/funcToNumber.js +0 -25
  234. package/src/builtins/funcToString.js +0 -5
  235. package/src/builtins/funcToUpperCase.js +0 -20
  236. package/src/builtins/funcTrim.js +0 -16
  237. package/src/builtins/funcTrimEnd.js +0 -16
  238. package/src/builtins/funcTrimStart.js +0 -16
  239. package/src/builtins/funcType.js +0 -5
  240. package/src/builtins/funcVoid.js +0 -5
  241. package/src/builtins/index.js +0 -193
  242. package/src/builtins/internals.js +0 -9
  243. package/src/builtins/math.js +0 -44
  244. package/src/createSingleton.js +0 -9
  245. package/src/index.js +0 -44
  246. package/src/interpreter/index.js +0 -48
  247. package/src/interpreter/parse.js +0 -1473
  248. package/src/interpreter/system.js +0 -5
  249. package/src/interpreter/util.js +0 -237
  250. package/src/library/apply.js +0 -135
  251. package/src/library/definition.js +0 -3
  252. package/src/library/errors/adaptErrors.js +0 -28
  253. package/src/library/errors/enclosure.js +0 -11
  254. package/src/library/errors/error.js +0 -14
  255. package/src/library/errors/execution.js +0 -15
  256. package/src/library/errors/fatal.js +0 -10
  257. package/src/library/errors/runtime.js +0 -71
  258. package/src/library/errors/syntax.js +0 -12
  259. package/src/library/index.js +0 -41
  260. package/src/library/mux.js +0 -98
  261. package/src/library/runtimeScope.js +0 -35
  262. package/src/library/runtimeSignal.js +0 -67
  263. package/src/library/types.js +0 -299
  264. package/src/program/index.js +0 -114
  265. package/src/program/ops/index.js +0 -82
  266. package/src/program/ops/opAccess/index.js +0 -55
  267. package/src/program/ops/opAccess/opaField.js +0 -58
  268. package/src/program/ops/opAccess/opaFunction.js +0 -52
  269. package/src/program/ops/opAccess/opaIter.js +0 -31
  270. package/src/program/ops/opAccess/opaSlice.js +0 -58
  271. package/src/program/ops/opAnd.js +0 -32
  272. package/src/program/ops/opArrayConstructor.js +0 -16
  273. package/src/program/ops/opAssignment/index.js +0 -102
  274. package/src/program/ops/opAssignment/opaAssignField.js +0 -156
  275. package/src/program/ops/opAssignment/opaAssignIter.js +0 -74
  276. package/src/program/ops/opAssignment/opaAssignSlice.js +0 -157
  277. package/src/program/ops/opAssignment/opuAddition.js +0 -29
  278. package/src/program/ops/opAssignment/opuDivision.js +0 -29
  279. package/src/program/ops/opAssignment/opuMultiplication.js +0 -29
  280. package/src/program/ops/opAssignment/opuNullCoalescence.js +0 -26
  281. package/src/program/ops/opAssignment/opuRemainder.js +0 -29
  282. package/src/program/ops/opAssignment/opuSet.js +0 -15
  283. package/src/program/ops/opAssignment/opuSubtraction.js +0 -29
  284. package/src/program/ops/opAssignment/opuUpdate.js +0 -15
  285. package/src/program/ops/opCalculation/index.js +0 -64
  286. package/src/program/ops/opCalculation/opmAddition.js +0 -63
  287. package/src/program/ops/opCalculation/opmDivision.js +0 -47
  288. package/src/program/ops/opCalculation/opmMultiplication.js +0 -52
  289. package/src/program/ops/opCalculation/opmRemainder.js +0 -49
  290. package/src/program/ops/opCalculation/opmSubtraction.js +0 -72
  291. package/src/program/ops/opComparison/index.js +0 -67
  292. package/src/program/ops/opComparison/opcEqual.js +0 -17
  293. package/src/program/ops/opComparison/opcGreater.js +0 -17
  294. package/src/program/ops/opComparison/opcGreaterEqual.js +0 -17
  295. package/src/program/ops/opComparison/opcLess.js +0 -17
  296. package/src/program/ops/opComparison/opcLessEqual.js +0 -17
  297. package/src/program/ops/opComparison/opcUnequal.js +0 -17
  298. package/src/program/ops/opConstant.js +0 -13
  299. package/src/program/ops/opConstantFalse.js +0 -11
  300. package/src/program/ops/opConstantNull.js +0 -11
  301. package/src/program/ops/opConstantTrue.js +0 -11
  302. package/src/program/ops/opFunctionDefinition.js +0 -17
  303. package/src/program/ops/opIf.js +0 -44
  304. package/src/program/ops/opInterpolatedString.js +0 -27
  305. package/src/program/ops/opNegation.js +0 -26
  306. package/src/program/ops/opNot.js +0 -11
  307. package/src/program/ops/opNullCoalescence.js +0 -36
  308. package/src/program/ops/opNumber.js +0 -13
  309. package/src/program/ops/opObjectConstructor.js +0 -40
  310. package/src/program/ops/opOr.js +0 -32
  311. package/src/program/ops/opOutputConcat.js +0 -17
  312. package/src/program/ops/opString.js +0 -13
  313. package/src/program/ops/opTry.js +0 -38
  314. package/src/program/ops/opVariable.js +0 -17
  315. package/src/program/ops/opVariableDefinition.js +0 -18
  316. package/src/program/ops/opVoid.js +0 -11
  317. package/src/program/ops/utils.js +0 -19
  318. package/src/runtime/index.js +0 -309
  319. /package/{src/builtins/native.js → dist/types/builtins/native.d.ts} +0 -0
  320. /package/{src/library/ops/index.js → dist/types/library/ops/index.d.ts} +0 -0
@@ -1,21 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fs = require('fs');
4
- const os = require('os');
5
- const path = require('path');
6
- const readline = require('readline');
7
- const { default: jpl } = require('@jplorg/jpl');
8
- const pkg = require('@jplorg/jpl/package.json');
3
+ import * as jpl from '@jplorg/jpl';
4
+ import pkg from '@jplorg/jpl/package.json' with { type: 'json' };
5
+ import fs from 'fs';
6
+ import os from 'os';
7
+ import path from 'path';
8
+ import readline from 'readline';
9
9
 
10
10
  const replKeys = [':', '!'];
11
11
  const defaultReplKey = replKeys[0];
12
12
  const defaultPrompt = '> ';
13
13
  const multilinePrompt = '… ';
14
14
 
15
- let multilineInput;
15
+ let multilineInput: string | null;
16
16
 
17
17
  const homeDir = os.homedir();
18
- const historyFile = homeDir ? path.join(homeDir, '.jpl_repl_history') : undefined;
18
+ const historyFile = homeDir
19
+ ? path.join(homeDir, '.jpl_repl_history')
20
+ : undefined;
19
21
 
20
22
  const muted = !process.stdin.isTTY;
21
23
 
@@ -45,9 +47,13 @@ function readHistory() {
45
47
  if (historyFile) {
46
48
  rl.on('history', (history) => {
47
49
  try {
48
- fs.writeFileSync(historyFile, history.filter(Boolean).reverse().join('\n') + '\n', {
49
- mode: 0o600,
50
- });
50
+ fs.writeFileSync(
51
+ historyFile,
52
+ history.filter(Boolean).reverse().join('\n') + '\n',
53
+ {
54
+ mode: 0o600,
55
+ },
56
+ );
51
57
  } catch {
52
58
  // ignore
53
59
  }
@@ -61,25 +67,29 @@ rl.on('close', () => {
61
67
  rl.on('SIGINT', () => {
62
68
  if (multilineInput != null) {
63
69
  multilineInput = null;
64
- rl.clearLine();
70
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
+ (rl as any).clearLine?.();
65
72
  rl.setPrompt(defaultPrompt);
66
73
  rl.prompt();
67
74
  return undefined;
68
75
  }
69
76
  if (rl.cursor === 0) return process.exit(0);
70
- process.stdout.write(`\nTo exit, press Ctrl+C again or type ${defaultReplKey}e`);
71
- rl.clearLine();
77
+ process.stdout.write(
78
+ `\nTo exit, press Ctrl+C again or type ${defaultReplKey}e`,
79
+ );
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ (rl as any).clearLine?.();
72
82
  rl.prompt();
73
83
  return undefined;
74
84
  });
75
85
 
76
- let keep;
77
- let inputs;
78
- let measureTime;
86
+ let keep: boolean;
87
+ let inputs: unknown[];
88
+ let measureTime: boolean;
79
89
 
80
90
  main();
81
91
 
82
- async function main() {
92
+ async function main(): Promise<void> {
83
93
  if (!muted) {
84
94
  console.log(`Welcome to JPL v${pkg.version}.`);
85
95
  console.log(`Type "${defaultReplKey}h" for more information.\n`);
@@ -103,7 +113,7 @@ async function main() {
103
113
  }
104
114
  }
105
115
 
106
- async function handle(input) {
116
+ async function handle(input: string): Promise<void> {
107
117
  if (!keep || inputs.length === 0) inputs = [null];
108
118
 
109
119
  const fullLine = (multilineInput ?? '') + input;
@@ -149,15 +159,22 @@ async function handle(input) {
149
159
  const program = await jpl.parse(line);
150
160
  console.log(JSON.stringify(program.definition, null, 2));
151
161
  } catch (err) {
152
- if (jpl.JPLSyntaxError.is(err) && err.at >= err.src.length) {
162
+ if (
163
+ jpl.JPLSyntaxError.is(err) &&
164
+ (err as jpl.JPLSyntaxError).at >=
165
+ (err as jpl.JPLSyntaxError).src.length
166
+ ) {
153
167
  // program is incomplete -> request additional input
154
168
  multilineInput = fullLine + '\n';
155
169
  rl.setPrompt(multilinePrompt);
156
170
  rl.prompt();
157
171
  return undefined;
158
172
  }
159
- if (jpl.JPLSyntaxError.is(err)) console.log(`${err.name ?? 'JPLError'}: ${err.message}`);
160
- else console.log(err.stack);
173
+ if (jpl.JPLSyntaxError.is(err))
174
+ console.log(
175
+ `${(err as jpl.JPLSyntaxError).name ?? 'JPLError'}: ${(err as jpl.JPLSyntaxError).message}`,
176
+ );
177
+ else console.log((err as Error).stack);
161
178
  }
162
179
  break;
163
180
 
@@ -167,7 +184,9 @@ async function handle(input) {
167
184
  break;
168
185
 
169
186
  default:
170
- console.log(`Error: unrecognized REPL command ${defaultReplKey}${command}\n`);
187
+ console.log(
188
+ `Error: unrecognized REPL command ${defaultReplKey}${command}\n`,
189
+ );
171
190
  printHelp();
172
191
  }
173
192
  } else {
@@ -176,15 +195,20 @@ async function handle(input) {
176
195
  rl.setPrompt(defaultPrompt);
177
196
  try {
178
197
  const program = await jpl.parse(line);
179
- let before;
180
- let diff;
198
+ let before: number;
199
+ let diff: number;
181
200
  if (measureTime) before = Date.now();
182
201
  inputs = await program.run(inputs);
183
- if (measureTime) diff = Date.now() - before;
184
- console.log(inputs.map((output) => JSON.stringify(output, null, 2)).join(', '));
185
- if (measureTime) console.log(` -> took ${diff / 1000}s`);
202
+ if (measureTime) diff = Date.now() - before!;
203
+ console.log(
204
+ inputs.map((output) => JSON.stringify(output, null, 2)).join(', '),
205
+ );
206
+ if (measureTime) console.log(` -> took ${diff! / 1000}s`);
186
207
  } catch (err) {
187
- if (jpl.JPLSyntaxError.is(err) && err.at >= err.src.length) {
208
+ if (
209
+ jpl.JPLSyntaxError.is(err) &&
210
+ (err as jpl.JPLSyntaxError).at >= (err as jpl.JPLSyntaxError).src.length
211
+ ) {
188
212
  // program is incomplete -> request additional input
189
213
  multilineInput = fullLine + '\n';
190
214
  rl.setPrompt(multilinePrompt);
@@ -192,8 +216,10 @@ async function handle(input) {
192
216
  return undefined;
193
217
  }
194
218
  if (jpl.JPLSyntaxError.is(err) || jpl.JPLExecutionError.is(err))
195
- console.log(`${err.name ?? 'JPLError'}: ${err.message}`);
196
- else console.log(err.stack);
219
+ console.log(
220
+ `${(err as jpl.JPLSyntaxError).name ?? 'JPLError'}: ${(err as jpl.JPLSyntaxError).message}`,
221
+ );
222
+ else console.log((err as Error).stack);
197
223
  }
198
224
  }
199
225
 
@@ -201,12 +227,24 @@ async function handle(input) {
201
227
  return undefined;
202
228
  }
203
229
 
204
- function parseBool(input, defaultValue, label) {
230
+ function parseBool(
231
+ input: string,
232
+ defaultValue: boolean,
233
+ label: string,
234
+ ): boolean | null {
205
235
  const b = input.trim().toLowerCase();
206
236
  let v;
207
237
  if (b.length === 0) v = defaultValue;
208
- else if (b === 'on' || ['true', 'yes', 'enabled'].some((e) => e.startsWith(b))) v = true;
209
- else if (b === 'off' || ['false', 'no', 'disabled'].some((e) => e.startsWith(b))) v = false;
238
+ else if (
239
+ b === 'on' ||
240
+ ['true', 'yes', 'enabled'].some((e) => e.startsWith(b))
241
+ )
242
+ v = true;
243
+ else if (
244
+ b === 'off' ||
245
+ ['false', 'no', 'disabled'].some((e) => e.startsWith(b))
246
+ )
247
+ v = false;
210
248
  if (typeof v === 'boolean') {
211
249
  console.log(` -> ${label} ${v ? 'on' : 'off'}`);
212
250
  return v;
@@ -215,11 +253,11 @@ function parseBool(input, defaultValue, label) {
215
253
  return null;
216
254
  }
217
255
 
218
- function printBool(value) {
256
+ function printBool(value: boolean): string {
219
257
  return `boolean (${value ? 'on' : 'off'})`;
220
258
  }
221
259
 
222
- function printHelp() {
260
+ function printHelp(): void {
223
261
  const commands = [
224
262
  ['c', '', 'Clear the console screen'],
225
263
  ['e', '', 'Exit the REPL'],
@@ -230,7 +268,11 @@ function printHelp() {
230
268
  printBool(keep),
231
269
  'Set whether program output should be kept as input for the next program',
232
270
  ],
233
- ['t', printBool(measureTime), 'Set whether execution time should be measured'],
271
+ [
272
+ 't',
273
+ printBool(measureTime),
274
+ 'Set whether execution time should be measured',
275
+ ],
234
276
  ['q', '', 'Exit the REPL'],
235
277
  ];
236
278
  const aLen = commands.reduce((sum, [, a]) => Math.max(sum, a.length), 0);
@@ -241,8 +283,12 @@ function printHelp() {
241
283
  );
242
284
 
243
285
  commands.forEach(([c, a, d]) =>
244
- console.log(`${defaultReplKey}${c} ${a}${' '.repeat(aLen - a.length + 3)}${d}`),
286
+ console.log(
287
+ `${defaultReplKey}${c} ${a}${' '.repeat(aLen - a.length + 3)}${d}`,
288
+ ),
245
289
  );
246
290
 
247
- console.log('\nPress Ctrl+C to abort current expression, Ctrl+D to exit the REPL');
291
+ console.log(
292
+ '\nPress Ctrl+C to abort current expression, Ctrl+D to exit the REPL',
293
+ );
248
294
  }
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- /** Apply the specified defaults to the config */
8
- function applyDefaults(config, defaults, ...strictPaths) {
9
- const iter = (c, d, s) => {
10
- if (Array.isArray(c)) return c;
11
- if (typeof c === 'object') {
12
- if (c === null || Array.isArray(d) || typeof d !== 'object' || d === null) return c;
13
- const result = {
14
- ...c
15
- };
16
- const isStrict = s.some(entry => entry.length === 0);
17
- Object.keys({
18
- ...c,
19
- ...d
20
- }).forEach(key => {
21
- if (isStrict) {
22
- if (!Object.hasOwn(result, key)) result[key] = d[key];
23
- } else {
24
- result[key] = iter(result[key], d[key], s.filter(entry => entry[0] === key).map(entry => entry.slice(1)));
25
- }
26
- if (result[key] === undefined) delete result[key];
27
- });
28
- return result;
29
- }
30
- return c === undefined ? d : c;
31
- };
32
- return iter(config, defaults, strictPaths.map(path => typeof path === 'string' ? path.split('.') : path));
33
- }
34
- var _default = exports.default = applyDefaults;
@@ -1,25 +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
- function builtin(runtime, signal, next, input, arg0) {
9
- const value = runtime.unwrapValue(input);
10
- const t = runtime.type(value);
11
- const token = runtime.unwrapValue(arg0 ?? null);
12
- const tt = runtime.type(token);
13
- switch (t) {
14
- case 'array':
15
- return next(value.some(item => runtime.equals(item, token)));
16
- case 'string':
17
- if (tt === 'string') return next(value.includes(token));
18
- break;
19
- case 'object':
20
- return next(Object.values(value).some(item => runtime.equals(item, token)));
21
- default:
22
- }
23
- throw new _library.JPLTypeError('%s (%*<100v) cannot contain %s (%*<100v)', t, value, tt, token);
24
- }
25
- var _default = exports.default = builtin;
@@ -1,21 +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
- function builtin(runtime, signal, next, input, arg0) {
9
- const value = runtime.unwrapValue(input);
10
- const t = runtime.type(value);
11
- const token = runtime.unwrapValue(arg0 ?? null);
12
- const tt = runtime.type(token);
13
- switch (t) {
14
- case 'string':
15
- if (tt === 'string') return next(value.endsWith(token));
16
- break;
17
- default:
18
- }
19
- throw new _library.JPLTypeError('%s (%*<100v) cannot end with %s (%*<100v)', t, value, tt, token);
20
- }
21
- var _default = exports.default = builtin;
@@ -1,11 +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
- function builtin(runtime, signal, next, input) {
9
- throw new _library.JPLRuntimeError(input);
10
- }
11
- var _default = exports.default = builtin;
@@ -1,26 +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
- function builtin(runtime, signal, next, input) {
9
- const value = runtime.unwrapValue(input);
10
- const t = runtime.type(value);
11
- switch (t) {
12
- case 'string':
13
- {
14
- let result;
15
- try {
16
- result = JSON.parse(value);
17
- } catch (err) {
18
- throw new _library.JPLRuntimeError(err.message);
19
- }
20
- return next(result);
21
- }
22
- default:
23
- }
24
- throw new _library.JPLTypeError('%s (%*<100v) cannot be parsed as JSON', t, value);
25
- }
26
- var _default = exports.default = builtin;
@@ -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
- function builtin(runtime, signal, next, input, arg0) {
9
- const value = runtime.unwrapValue(input);
10
- const tv = runtime.type(value);
11
- const key = runtime.unwrapValue(arg0 ?? null);
12
- const tk = runtime.type(key);
13
- switch (tv) {
14
- case 'array':
15
- if (tk === 'number') return next(key >= 0 && key < value.length);
16
- break;
17
- case 'object':
18
- if (tk === 'string') return next(Object.hasOwn(value, key));
19
- break;
20
- default:
21
- }
22
- throw new _library.JPLTypeError('%s (%*<100v) cannot have %s (%*<100v) as key', tv, value, tk, key);
23
- }
24
- var _default = exports.default = builtin;
@@ -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
- function builtin(runtime, signal, next, input, arg0) {
9
- const key = runtime.unwrapValue(input);
10
- const tk = runtime.type(key);
11
- const value = runtime.unwrapValue(arg0 ?? null);
12
- const tv = runtime.type(value);
13
- switch (tv) {
14
- case 'array':
15
- if (tk === 'number') return next(key >= 0 && key < value.length);
16
- break;
17
- case 'object':
18
- if (tk === 'string') return next(Object.hasOwn(value, key));
19
- break;
20
- default:
21
- }
22
- throw new _library.JPLTypeError('%s (%*<100v) cannot have %s (%*<100v) as key', tv, value, tk, key);
23
- }
24
- var _default = exports.default = builtin;
@@ -1,20 +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
- function builtin(runtime, signal, next, input) {
9
- const value = runtime.unwrapValue(input);
10
- const t = runtime.type(value);
11
- switch (t) {
12
- case 'array':
13
- return next(value.map((_, i) => i));
14
- case 'object':
15
- return next(Object.keys(value));
16
- default:
17
- }
18
- throw new _library.JPLTypeError('%s (%*<100v) has no keys', t, value);
19
- }
20
- var _default = exports.default = builtin;
@@ -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
- function builtin(runtime, signal, next, input) {
9
- const value = runtime.unwrapValue(input);
10
- const t = runtime.type(value);
11
- switch (t) {
12
- case 'null':
13
- return next(0);
14
- case 'array':
15
- return next(value.length);
16
- case 'string':
17
- return next([...value].length);
18
- case 'object':
19
- return next(Object.keys(value).length);
20
- default:
21
- }
22
- throw new _library.JPLTypeError('%s (%*<100v) has no length', t, value);
23
- }
24
- var _default = exports.default = builtin;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- function builtin(runtime, signal, next) {
8
- return next(Date.now());
9
- }
10
- var _default = exports.default = builtin;
@@ -1,21 +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
- function builtin(runtime, signal, next, input, arg0) {
9
- const value = runtime.unwrapValue(input);
10
- const t = runtime.type(value);
11
- const token = runtime.unwrapValue(arg0 ?? null);
12
- const tt = runtime.type(token);
13
- switch (t) {
14
- case 'string':
15
- if (tt === 'string') return next(value.startsWith(token));
16
- break;
17
- default:
18
- }
19
- throw new _library.JPLTypeError('%s (%*<100v) cannot start with %s (%*<100v)', t, value, tt, token);
20
- }
21
- var _default = exports.default = builtin;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- function builtin(runtime, signal, next, input) {
8
- return next(runtime.stringifyJSON(input, false));
9
- }
10
- var _default = exports.default = builtin;
@@ -1,17 +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
- async function builtin(runtime, signal, next, input) {
9
- const t = runtime.type(input);
10
- switch (t) {
11
- case 'string':
12
- return next(await runtime.alterValue(input, value => value.toLowerCase()));
13
- default:
14
- }
15
- throw new _library.JPLTypeError('%s (%*<100v) cannot be converted to lower case', t, runtime.unwrapValue(input));
16
- }
17
- var _default = exports.default = builtin;
@@ -1,26 +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
- function builtin(runtime, signal, next, input) {
9
- const value = runtime.unwrapValue(input);
10
- const t = runtime.type(value);
11
- switch (t) {
12
- case 'number':
13
- return next(value);
14
- case 'string':
15
- {
16
- const result = runtime.normalizeValue(+value);
17
- if (value === '' || runtime.type(result) !== 'number') {
18
- throw new _library.JPLTypeConversionError('%s (%*<100v) does not contain a valid number', t, value);
19
- }
20
- return next(result);
21
- }
22
- default:
23
- }
24
- throw new _library.JPLTypeError('%s (%*<100v) cannot be parsed as a number', t, value);
25
- }
26
- var _default = exports.default = builtin;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- function builtin(runtime, signal, next, input) {
8
- return next(runtime.stringifyJSON(input, true));
9
- }
10
- var _default = exports.default = builtin;
@@ -1,17 +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
- async function builtin(runtime, signal, next, input) {
9
- const t = runtime.type(input);
10
- switch (t) {
11
- case 'string':
12
- return next(await runtime.alterValue(input, value => value.toUpperCase()));
13
- default:
14
- }
15
- throw new _library.JPLTypeError('%s (%*<100v) cannot be converted to upper case', t, runtime.unwrapValue(input));
16
- }
17
- var _default = exports.default = builtin;
@@ -1,17 +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
- async function builtin(runtime, signal, next, input) {
9
- const t = runtime.type(input);
10
- switch (t) {
11
- case 'string':
12
- return next(await runtime.alterValue(input, value => value.trim()));
13
- default:
14
- }
15
- throw new _library.JPLTypeError('%s (%*<100v) cannot be trimmed', t, runtime.unwrapValue(input));
16
- }
17
- var _default = exports.default = builtin;
@@ -1,17 +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
- async function builtin(runtime, signal, next, input) {
9
- const t = runtime.type(input);
10
- switch (t) {
11
- case 'string':
12
- return next(await runtime.alterValue(input, value => value.trimEnd()));
13
- default:
14
- }
15
- throw new _library.JPLTypeError('%s (%*<100v) cannot be trimmed', t, runtime.unwrapValue(input));
16
- }
17
- var _default = exports.default = builtin;
@@ -1,17 +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
- async function builtin(runtime, signal, next, input) {
9
- const t = runtime.type(input);
10
- switch (t) {
11
- case 'string':
12
- return next(await runtime.alterValue(input, value => value.trimStart()));
13
- default:
14
- }
15
- throw new _library.JPLTypeError('%s (%*<100v) cannot be trimmed', t, runtime.unwrapValue(input));
16
- }
17
- var _default = exports.default = builtin;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- function builtin(runtime, signal, next, input) {
8
- return next(runtime.type(input));
9
- }
10
- var _default = exports.default = builtin;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- function builtin() {
8
- return [];
9
- }
10
- var _default = exports.default = builtin;