@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,2377 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.opAnd = opAnd;
7
- exports.opArrayConstructor = opArrayConstructor;
8
- exports.opComparison = opComparison;
9
- exports.opConstant = opConstant;
10
- exports.opDifference = opDifference;
11
- exports.opEquality = opEquality;
12
- exports.opErrorSuppression = opErrorSuppression;
13
- exports.opFunctionDefinition = opFunctionDefinition;
14
- exports.opGroup = opGroup;
15
- exports.opIf = opIf;
16
- exports.opMultiplication = opMultiplication;
17
- exports.opNamedFunctionDefinition = opNamedFunctionDefinition;
18
- exports.opNegation = opNegation;
19
- exports.opNot = opNot;
20
- exports.opNullCoalescence = opNullCoalescence;
21
- exports.opNumber = opNumber;
22
- exports.opObjectConstructor = opObjectConstructor;
23
- exports.opOr = opOr;
24
- exports.opOutputConcat = opOutputConcat;
25
- exports.opPipe = opPipe;
26
- exports.opStringLiteral = opStringLiteral;
27
- exports.opSubPipe = opSubPipe;
28
- exports.opSubRoute = opSubRoute;
29
- exports.opTry = opTry;
30
- exports.opValueAccess = opValueAccess;
31
- exports.opVariableAccess = opVariableAccess;
32
- exports.parseAccess = parseAccess;
33
- exports.parseAssignment = parseAssignment;
34
- exports.parseEntrypoint = parseEntrypoint;
35
- exports.parseFunctionHeader = parseFunctionHeader;
36
- exports.parseNumber = parseNumber;
37
- exports.parseProgram = parseProgram;
38
- exports.parseString = parseString;
39
- var _library = require("../library");
40
- var _util = require("./util");
41
- /**
42
- * Parse a single program at i.
43
- * Throws an error if src contains additional content.
44
- */
45
- async function parseEntrypoint(src, i, c) {
46
- let n = i;
47
- const result = await parseProgram(src, n, c);
48
- ({
49
- i: n
50
- } = result);
51
- if (!(0, _util.eot)(src, n, c).is) return (0, _util.errorUnexpectedToken)(src, n, c, {
52
- operator: 'program',
53
- message: 'expected EOT'
54
- });
55
- return result;
56
- }
57
-
58
- /** Parse program at i */
59
- function parseProgram(src, i, c) {
60
- let n = i;
61
- ({
62
- i: n
63
- } = (0, _util.walkWhitespace)(src, n, c));
64
- return opPipe(src, n, c);
65
- }
66
-
67
- /** Parse function header at i */
68
- function parseFunctionHeader(src, i, c) {
69
- let n = i;
70
- let m = (0, _util.matchWord)(src, n, c, {
71
- phrase: '('
72
- });
73
- ({
74
- i: n
75
- } = m);
76
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
77
- operator: 'function definition',
78
- message: "expected '('"
79
- });
80
- const argNames = [];
81
- m = (0, _util.matchWord)(src, n, c, {
82
- phrase: ')'
83
- });
84
- if (m.is) ({
85
- i: n
86
- } = m);else for (;;) {
87
- const v = (0, _util.safeVariable)(src, n, c);
88
- if (!v.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
89
- operator: 'function definition',
90
- message: 'expected argument name'
91
- });
92
- let name;
93
- ({
94
- i: n,
95
- value: name
96
- } = v);
97
- argNames.push(name);
98
- m = (0, _util.matchWord)(src, n, c, {
99
- phrase: ')'
100
- });
101
- if (m.is) {
102
- ({
103
- i: n
104
- } = m);
105
- break;
106
- }
107
- m = (0, _util.matchWord)(src, n, c, {
108
- phrase: ','
109
- });
110
- ({
111
- i: n
112
- } = m);
113
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
114
- operator: 'function definition',
115
- message: "expected ',' or ')'"
116
- });
117
- }
118
- m = (0, _util.matchWord)(src, n, c, {
119
- phrase: ':'
120
- });
121
- ({
122
- i: n
123
- } = m);
124
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
125
- operator: 'function definition',
126
- message: "expected ':'"
127
- });
128
- return {
129
- i: n,
130
- argNames
131
- };
132
- }
133
-
134
- /** Parse access at i */
135
- async function parseAccess(src, i, c, {
136
- identity
137
- } = {}) {
138
- let n = i;
139
- const selectors = [];
140
- let canAssign = true;
141
- for (;;) {
142
- let m = (0, _util.matchWord)(src, n, c, {
143
- phrase: '.'
144
- });
145
- const isIdentity = identity && selectors.length === 0;
146
- if (!isIdentity && m.is) {
147
- ({
148
- i: n
149
- } = m);
150
- const v = (0, _util.safeVariable)(src, n, c);
151
- if (!v.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
152
- operator: 'field access operator',
153
- message: 'expected field name'
154
- });
155
- let name;
156
- ({
157
- i: n,
158
- value: name
159
- } = v);
160
- let optional;
161
- m = (0, _util.matchWord)(src, n, c, {
162
- phrase: '?',
163
- notBeforeSet: '?='
164
- });
165
- if (m.is) ({
166
- i: n,
167
- is: optional
168
- } = m);
169
- selectors.push({
170
- op: _library.OPA_FIELD,
171
- params: {
172
- pipe: [{
173
- op: _library.OP_STRING,
174
- params: {
175
- string: name
176
- }
177
- }],
178
- optional
179
- }
180
- });
181
- continue;
182
- }
183
- m = (0, _util.matchWord)(src, n, c, {
184
- phrase: '['
185
- });
186
- if (m.is) {
187
- ({
188
- i: n
189
- } = m);
190
- m = (0, _util.matchWord)(src, n, c, {
191
- phrase: ']'
192
- });
193
- if (m.is) {
194
- ({
195
- i: n
196
- } = m);
197
- let optional;
198
- m = (0, _util.matchWord)(src, n, c, {
199
- phrase: '?',
200
- notBeforeSet: '?='
201
- });
202
- if (m.is) ({
203
- i: n,
204
- is: optional
205
- } = m);
206
- selectors.push({
207
- op: _library.OPA_ITER,
208
- params: {
209
- optional
210
- }
211
- });
212
- continue;
213
- }
214
- m = (0, _util.matchWord)(src, n, c, {
215
- phrase: ':'
216
- });
217
- if (m.is) {
218
- ({
219
- i: n
220
- } = m);
221
- m = (0, _util.matchWord)(src, n, c, {
222
- phrase: ']'
223
- });
224
- if (m.is) {
225
- ({
226
- i: n
227
- } = m);
228
- let optional;
229
- m = (0, _util.matchWord)(src, n, c, {
230
- phrase: '?',
231
- notBeforeSet: '?='
232
- });
233
- if (m.is) ({
234
- i: n,
235
- is: optional
236
- } = m);
237
- selectors.push({
238
- op: _library.OPA_SLICE,
239
- params: {
240
- from: [{
241
- op: _library.OP_CONSTANT_NULL
242
- }],
243
- to: [{
244
- op: _library.OP_CONSTANT_NULL
245
- }],
246
- optional
247
- }
248
- });
249
- continue;
250
- }
251
- let opsRight;
252
- ({
253
- i: n,
254
- ops: opsRight
255
- } = await opPipe(src, n, c));
256
- m = (0, _util.matchWord)(src, n, c, {
257
- phrase: ']'
258
- });
259
- ({
260
- i: n
261
- } = m);
262
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
263
- operator: 'array slice operator',
264
- message: "expected ']'"
265
- });
266
- let optional;
267
- m = (0, _util.matchWord)(src, n, c, {
268
- phrase: '?',
269
- notBeforeSet: '?='
270
- });
271
- if (m.is) ({
272
- i: n,
273
- is: optional
274
- } = m);
275
- selectors.push({
276
- op: _library.OPA_SLICE,
277
- params: {
278
- from: [{
279
- op: _library.OP_CONSTANT_NULL
280
- }],
281
- to: opsRight,
282
- optional
283
- }
284
- });
285
- continue;
286
- }
287
- let opsLeft;
288
- ({
289
- i: n,
290
- ops: opsLeft
291
- } = await opPipe(src, n, c));
292
- m = (0, _util.matchWord)(src, n, c, {
293
- phrase: ']'
294
- });
295
- if (m.is) {
296
- ({
297
- i: n
298
- } = m);
299
- let optional;
300
- m = (0, _util.matchWord)(src, n, c, {
301
- phrase: '?',
302
- notBeforeSet: '?='
303
- });
304
- if (m.is) ({
305
- i: n,
306
- is: optional
307
- } = m);
308
- selectors.push({
309
- op: _library.OPA_FIELD,
310
- params: {
311
- pipe: opsLeft,
312
- optional
313
- }
314
- });
315
- continue;
316
- }
317
- m = (0, _util.matchWord)(src, n, c, {
318
- phrase: ':'
319
- });
320
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
321
- operator: 'variable access operator',
322
- message: "expected ':' or ']'"
323
- });
324
- ({
325
- i: n
326
- } = m);
327
- m = (0, _util.matchWord)(src, n, c, {
328
- phrase: ']'
329
- });
330
- if (m.is) {
331
- ({
332
- i: n
333
- } = m);
334
- let optional;
335
- m = (0, _util.matchWord)(src, n, c, {
336
- phrase: '?',
337
- notBeforeSet: '?='
338
- });
339
- if (m.is) ({
340
- i: n,
341
- is: optional
342
- } = m);
343
- selectors.push({
344
- op: _library.OPA_SLICE,
345
- params: {
346
- from: opsLeft,
347
- to: [{
348
- op: _library.OP_CONSTANT_NULL
349
- }],
350
- optional
351
- }
352
- });
353
- continue;
354
- }
355
- let opsRight;
356
- ({
357
- i: n,
358
- ops: opsRight
359
- } = await opPipe(src, n, c));
360
- m = (0, _util.matchWord)(src, n, c, {
361
- phrase: ']'
362
- });
363
- ({
364
- i: n
365
- } = m);
366
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
367
- operator: 'array slice operator',
368
- message: "expected ']'"
369
- });
370
- let optional;
371
- m = (0, _util.matchWord)(src, n, c, {
372
- phrase: '?',
373
- notBeforeSet: '?='
374
- });
375
- if (m.is) ({
376
- i: n,
377
- is: optional
378
- } = m);
379
- selectors.push({
380
- op: _library.OPA_SLICE,
381
- params: {
382
- from: opsLeft,
383
- to: opsRight,
384
- optional
385
- }
386
- });
387
- continue;
388
- }
389
- let bound;
390
- m = (0, _util.matchWord)(src, n, c, {
391
- phrase: '->'
392
- });
393
- if (m.is) ({
394
- i: n,
395
- is: bound
396
- } = m);
397
- m = (0, _util.matchWord)(src, n, c, {
398
- phrase: '('
399
- });
400
- if (!m.is && bound) {
401
- return (0, _util.errorUnexpectedToken)(src, n, c, {
402
- operator: 'bound function call',
403
- message: "expected '('"
404
- });
405
- }
406
- if (m.is) {
407
- ({
408
- i: n
409
- } = m);
410
- const args = [];
411
- m = (0, _util.matchWord)(src, n, c, {
412
- phrase: ')'
413
- });
414
- if (m.is) ({
415
- i: n
416
- } = m);else for (;;) {
417
- let opsArg;
418
- ({
419
- i: n,
420
- ops: opsArg
421
- } = await opSubPipe(src, n, c));
422
- args.push(opsArg);
423
- m = (0, _util.matchWord)(src, n, c, {
424
- phrase: ')'
425
- });
426
- if (m.is) {
427
- ({
428
- i: n
429
- } = m);
430
- break;
431
- }
432
- m = (0, _util.matchWord)(src, n, c, {
433
- phrase: ','
434
- });
435
- ({
436
- i: n
437
- } = m);
438
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
439
- operator: 'function call',
440
- message: "expected ',' or ')'"
441
- });
442
- }
443
- let optional;
444
- m = (0, _util.matchWord)(src, n, c, {
445
- phrase: '?',
446
- notBeforeSet: '?='
447
- });
448
- if (m.is) ({
449
- i: n,
450
- is: optional
451
- } = m);
452
- selectors.push({
453
- op: _library.OPA_FUNCTION,
454
- params: {
455
- args,
456
- bound,
457
- optional
458
- }
459
- });
460
- canAssign = false;
461
- continue;
462
- }
463
- break;
464
- }
465
- return {
466
- i: n,
467
- is: selectors.length > 0,
468
- selectors,
469
- canAssign
470
- };
471
- }
472
-
473
- /** Parse assignment at i */
474
- async function parseAssignment(src, i, c) {
475
- let n = i;
476
- let m = (0, _util.matchWord)(src, n, c, {
477
- phrase: '=',
478
- notBeforeSet: '='
479
- });
480
- if (m.is) {
481
- ({
482
- i: n
483
- } = m);
484
- let ops;
485
- ({
486
- i: n,
487
- ops
488
- } = await opSubRoute(src, n, c));
489
- return {
490
- i: n,
491
- is: true,
492
- assignment: {
493
- op: _library.OPU_SET,
494
- params: {
495
- pipe: ops
496
- }
497
- }
498
- };
499
- }
500
- m = (0, _util.matchWord)(src, n, c, {
501
- phrase: '|='
502
- });
503
- if (m.is) {
504
- ({
505
- i: n
506
- } = m);
507
- let ops;
508
- ({
509
- i: n,
510
- ops
511
- } = await opSubRoute(src, n, c));
512
- return {
513
- i: n,
514
- is: true,
515
- assignment: {
516
- op: _library.OPU_UPDATE,
517
- params: {
518
- pipe: ops
519
- }
520
- }
521
- };
522
- }
523
- m = (0, _util.matchWord)(src, n, c, {
524
- phrase: '+='
525
- });
526
- if (m.is) {
527
- ({
528
- i: n
529
- } = m);
530
- let ops;
531
- ({
532
- i: n,
533
- ops
534
- } = await opSubRoute(src, n, c));
535
- return {
536
- i: n,
537
- is: true,
538
- assignment: {
539
- op: _library.OPU_ADDITION,
540
- params: {
541
- pipe: ops
542
- }
543
- }
544
- };
545
- }
546
- m = (0, _util.matchWord)(src, n, c, {
547
- phrase: '-='
548
- });
549
- if (m.is) {
550
- ({
551
- i: n
552
- } = m);
553
- let ops;
554
- ({
555
- i: n,
556
- ops
557
- } = await opSubRoute(src, n, c));
558
- return {
559
- i: n,
560
- is: true,
561
- assignment: {
562
- op: _library.OPU_SUBTRACTION,
563
- params: {
564
- pipe: ops
565
- }
566
- }
567
- };
568
- }
569
- m = (0, _util.matchWord)(src, n, c, {
570
- phrase: '*='
571
- });
572
- if (m.is) {
573
- ({
574
- i: n
575
- } = m);
576
- let ops;
577
- ({
578
- i: n,
579
- ops
580
- } = await opSubRoute(src, n, c));
581
- return {
582
- i: n,
583
- is: true,
584
- assignment: {
585
- op: _library.OPU_MULTIPLICATION,
586
- params: {
587
- pipe: ops
588
- }
589
- }
590
- };
591
- }
592
- m = (0, _util.matchWord)(src, n, c, {
593
- phrase: '/='
594
- });
595
- if (m.is) {
596
- ({
597
- i: n
598
- } = m);
599
- let ops;
600
- ({
601
- i: n,
602
- ops
603
- } = await opSubRoute(src, n, c));
604
- return {
605
- i: n,
606
- is: true,
607
- assignment: {
608
- op: _library.OPU_DIVISION,
609
- params: {
610
- pipe: ops
611
- }
612
- }
613
- };
614
- }
615
- m = (0, _util.matchWord)(src, n, c, {
616
- phrase: '%='
617
- });
618
- if (m.is) {
619
- ({
620
- i: n
621
- } = m);
622
- let ops;
623
- ({
624
- i: n,
625
- ops
626
- } = await opSubRoute(src, n, c));
627
- return {
628
- i: n,
629
- is: true,
630
- assignment: {
631
- op: _library.OPU_REMAINDER,
632
- params: {
633
- pipe: ops
634
- }
635
- }
636
- };
637
- }
638
- m = (0, _util.matchWord)(src, n, c, {
639
- phrase: '?='
640
- });
641
- if (m.is) {
642
- ({
643
- i: n
644
- } = m);
645
- let ops;
646
- ({
647
- i: n,
648
- ops
649
- } = await opSubRoute(src, n, c));
650
- return {
651
- i: n,
652
- is: true,
653
- assignment: {
654
- op: _library.OPU_NULL_COALESCENCE,
655
- params: {
656
- pipe: ops
657
- }
658
- }
659
- };
660
- }
661
- return {
662
- i: n,
663
- is: false
664
- };
665
- }
666
-
667
- /** Parse number at i */
668
- function parseNumber(src, i, c) {
669
- let n = i;
670
- let is = false;
671
- let value = '';
672
- for (;;) {
673
- const set = (0, _util.matchSet)(src, n, c, {
674
- set: '0123456789'
675
- });
676
- if (!set.is) break;
677
- ({
678
- i: n
679
- } = set);
680
- is = true;
681
- value += set.value;
682
- }
683
- if (!is) return {
684
- i: n,
685
- is: false
686
- };
687
- const m = (0, _util.match)(src, n, c, {
688
- phrase: '.'
689
- });
690
- if (m.is) {
691
- ({
692
- i: n
693
- } = m);
694
- value += '.';
695
- for (;;) {
696
- const set = (0, _util.matchSet)(src, n, c, {
697
- set: '0123456789'
698
- });
699
- if (!set.is) break;
700
- ({
701
- i: n
702
- } = set);
703
- value += set.value;
704
- }
705
- }
706
- let set = (0, _util.matchSet)(src, n, c, {
707
- set: 'eE'
708
- });
709
- if (set.is) {
710
- ({
711
- i: n
712
- } = set);
713
- value += set.value;
714
- set = (0, _util.matchSet)(src, n, c, {
715
- set: '+-'
716
- });
717
- if (set.is) {
718
- ({
719
- i: n
720
- } = set);
721
- value += set.value;
722
- }
723
- let isE;
724
- for (;;) {
725
- set = (0, _util.matchSet)(src, n, c, {
726
- set: '0123456789'
727
- });
728
- if (!set.is) break;
729
- ({
730
- i: n
731
- } = set);
732
- isE = true;
733
- value += set.value;
734
- }
735
- if (!isE) return (0, _util.errorUnexpectedToken)(src, n, c, {
736
- operator: 'number',
737
- message: 'expected digit'
738
- });
739
- }
740
- const number = +value;
741
- if (!Number.isFinite(number)) {
742
- return (0, _util.errorGeneric)(src, n, c, {
743
- operator: 'number',
744
- message: `invalid number ${number}`
745
- });
746
- }
747
- ({
748
- i: n
749
- } = (0, _util.walkWhitespace)(src, n, c));
750
- return {
751
- i: n,
752
- is: true,
753
- ops: [{
754
- op: _library.OP_NUMBER,
755
- params: {
756
- number
757
- }
758
- }]
759
- };
760
- }
761
-
762
- /** Parse string at i */
763
- async function parseString(src, i, c) {
764
- let n = i;
765
- let value = '';
766
- const set = (0, _util.matchSet)(src, n, c, {
767
- set: '"\'`'
768
- });
769
- if (!set.is) return {
770
- i: n,
771
- is: false
772
- };
773
- let boundary;
774
- ({
775
- i: n,
776
- value: boundary
777
- } = set);
778
- const multilineString = boundary === '`';
779
- const interpolations = [];
780
- for (;;) {
781
- let m = (0, _util.match)(src, n, c, {
782
- phrase: boundary
783
- });
784
- if (m.is) {
785
- ({
786
- i: n
787
- } = m);
788
- break;
789
- }
790
- const end = (0, _util.eot)(src, n, c);
791
- if (end.is) {
792
- ({
793
- i: n
794
- } = end);
795
- return (0, _util.errorUnexpectedToken)(src, n, c, {
796
- operator: 'string',
797
- message: 'incomplete string literal'
798
- });
799
- }
800
- m = (0, _util.match)(src, n, c, {
801
- phrase: '\\'
802
- });
803
- if (m.is) {
804
- ({
805
- i: n
806
- } = m);
807
- m = (0, _util.matchWord)(src, n, c, {
808
- phrase: '('
809
- });
810
- if (m.is) {
811
- ({
812
- i: n
813
- } = m);
814
- let ops;
815
- ({
816
- i: n,
817
- ops
818
- } = await opPipe(src, n, c));
819
- m = (0, _util.match)(src, n, c, {
820
- phrase: ')'
821
- });
822
- ({
823
- i: n
824
- } = m);
825
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
826
- operator: 'string interpolation',
827
- message: "expected ')'"
828
- });
829
- interpolations.push({
830
- before: value,
831
- pipe: ops
832
- });
833
- value = '';
834
- continue;
835
- }
836
- if (multilineString) {
837
- switch (src[n]) {
838
- case '\n':
839
- n += 1;
840
- continue;
841
- case '\r':
842
- n += 1;
843
- if (!(0, _util.eot)(src, n, c).is && src[n] === '\n') n += 1;
844
- continue;
845
- default:
846
- }
847
- }
848
- switch (src[n]) {
849
- case '"':
850
- value += '"';
851
- n += 1;
852
- continue;
853
- case "'":
854
- value += "'";
855
- n += 1;
856
- continue;
857
- case '`':
858
- value += '`';
859
- n += 1;
860
- continue;
861
- case '\\':
862
- value += '\\';
863
- n += 1;
864
- continue;
865
- case '/':
866
- value += '/';
867
- n += 1;
868
- continue;
869
- case 'b':
870
- value += '\b';
871
- n += 1;
872
- continue;
873
- case 'f':
874
- value += '\f';
875
- n += 1;
876
- continue;
877
- case 'n':
878
- value += '\n';
879
- n += 1;
880
- continue;
881
- case 'r':
882
- value += '\r';
883
- n += 1;
884
- continue;
885
- case 't':
886
- value += '\t';
887
- n += 1;
888
- continue;
889
- case 'u':
890
- {
891
- n += 1;
892
- let hexVal = '';
893
- for (let j = 0; j < 4; j += 1) {
894
- m = (0, _util.hex)(src, n, c);
895
- ({
896
- i: n
897
- } = m);
898
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
899
- operator: 'string',
900
- message: 'incomplete unicode escape sequence: expected hex digit'
901
- });
902
- hexVal += m.value;
903
- }
904
- value += String.fromCodePoint(parseInt(hexVal, 16));
905
- continue;
906
- }
907
- default:
908
- return (0, _util.errorUnexpectedToken)(src, n, c, {
909
- operator: 'string',
910
- message: 'invalid escape sequence'
911
- });
912
- }
913
- }
914
- if (multilineString) {
915
- switch (src[n]) {
916
- case '\n':
917
- case '\r':
918
- case '\t':
919
- value += src[n];
920
- n += 1;
921
- continue;
922
- default:
923
- }
924
- }
925
- if (src.charCodeAt(n) < 0x20) return (0, _util.errorUnexpectedToken)(src, n, c, {
926
- operator: 'string'
927
- });
928
- value += src[n];
929
- n += 1;
930
- }
931
- ({
932
- i: n
933
- } = (0, _util.walkWhitespace)(src, n, c));
934
- if (interpolations.length === 0) return {
935
- i: n,
936
- is: true,
937
- ops: [{
938
- op: _library.OP_STRING,
939
- params: {
940
- string: value
941
- }
942
- }]
943
- };
944
- return {
945
- i: n,
946
- is: true,
947
- ops: [{
948
- op: _library.OP_INTERPOLATED_STRING,
949
- params: {
950
- interpolations,
951
- after: value
952
- }
953
- }]
954
- };
955
- }
956
-
957
- /** Parse pipe at i */
958
- async function opPipe(src, i, c) {
959
- // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
960
- await undefined;
961
- let n = i;
962
- const pipe = [];
963
- for (;;) {
964
- let ops;
965
- ({
966
- i: n,
967
- ops
968
- } = await opOutputConcat(src, n, c));
969
- pipe.push(...ops);
970
- const m = (0, _util.matchWord)(src, n, c, {
971
- phrase: '|',
972
- notBeforeSet: '='
973
- });
974
- if (!m.is) break;
975
- ({
976
- i: n
977
- } = m);
978
- }
979
- return {
980
- i: n,
981
- ops: pipe
982
- };
983
- }
984
-
985
- /** Parse subpipe at i */
986
- async function opSubPipe(src, i, c) {
987
- // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
988
- await undefined;
989
- let n = i;
990
- const pipe = [];
991
- for (;;) {
992
- let ops;
993
- ({
994
- i: n,
995
- ops
996
- } = await opTry(src, n, c));
997
- pipe.push(...ops);
998
- const m = (0, _util.matchWord)(src, n, c, {
999
- phrase: '|',
1000
- notBeforeSet: '='
1001
- });
1002
- if (!m.is) break;
1003
- ({
1004
- i: n
1005
- } = m);
1006
- }
1007
- return {
1008
- i: n,
1009
- ops: pipe
1010
- };
1011
- }
1012
-
1013
- /** Parse subroute at i */
1014
- async function opSubRoute(src, i, c) {
1015
- // Call stack decoupling - This is necessary as some browsers (i.e. Safari) have very limited call stack sizes which result in stack overflow exceptions in certain situations.
1016
- await undefined;
1017
- return opTry(src, i, c);
1018
- }
1019
-
1020
- /** Parse output concat at i */
1021
- async function opOutputConcat(src, i, c) {
1022
- let n = i;
1023
- const pipes = [];
1024
- for (;;) {
1025
- let ops;
1026
- ({
1027
- i: n,
1028
- ops
1029
- } = await opTry(src, n, c));
1030
- pipes.push(ops);
1031
- const m = (0, _util.matchWord)(src, n, c, {
1032
- phrase: ','
1033
- });
1034
- if (!m.is) break;
1035
- ({
1036
- i: n
1037
- } = m);
1038
- }
1039
- if (pipes.length === 1) return {
1040
- i: n,
1041
- ops: pipes[0]
1042
- };
1043
- return {
1044
- i: n,
1045
- ops: [{
1046
- op: _library.OP_OUTPUT_CONCAT,
1047
- params: {
1048
- pipes
1049
- }
1050
- }]
1051
- };
1052
- }
1053
-
1054
- /** Parse try at i */
1055
- async function opTry(src, i, c) {
1056
- let n = i;
1057
- let m = (0, _util.matchWord)(src, n, c, {
1058
- phrase: 'try',
1059
- spaceAfter: true
1060
- });
1061
- if (!m.is) return opOr(src, n, c);
1062
- ({
1063
- i: n
1064
- } = m);
1065
- let opsTry;
1066
- ({
1067
- i: n,
1068
- ops: opsTry
1069
- } = await opOr(src, n, c));
1070
- let opsCatch;
1071
- m = (0, _util.matchWord)(src, n, c, {
1072
- spaceBefore: true,
1073
- phrase: 'catch',
1074
- spaceAfter: true
1075
- });
1076
- if (m.is) {
1077
- ({
1078
- i: n
1079
- } = m);
1080
- ({
1081
- i: n,
1082
- ops: opsCatch
1083
- } = await opOr(src, n, c));
1084
- } else opsCatch = [{
1085
- op: _library.OP_VOID
1086
- }];
1087
- return {
1088
- i: n,
1089
- ops: [{
1090
- op: _library.OP_TRY,
1091
- params: {
1092
- try: opsTry,
1093
- catch: opsCatch
1094
- }
1095
- }]
1096
- };
1097
- }
1098
-
1099
- /** Parse or at i */
1100
- async function opOr(src, i, c) {
1101
- let n = i;
1102
- const pipes = [];
1103
- for (;;) {
1104
- let ops;
1105
- ({
1106
- i: n,
1107
- ops
1108
- } = await opAnd(src, n, c));
1109
- pipes.push(ops);
1110
- const m = (0, _util.matchWord)(src, n, c, {
1111
- spaceBefore: true,
1112
- phrase: 'or',
1113
- spaceAfter: true
1114
- });
1115
- if (!m.is) break;
1116
- ({
1117
- i: n
1118
- } = m);
1119
- }
1120
- if (pipes.length === 1) return {
1121
- i: n,
1122
- ops: pipes[0]
1123
- };
1124
- return {
1125
- i: n,
1126
- ops: [{
1127
- op: _library.OP_OR,
1128
- params: {
1129
- pipes
1130
- }
1131
- }]
1132
- };
1133
- }
1134
-
1135
- /** Parse and at i */
1136
- async function opAnd(src, i, c) {
1137
- let n = i;
1138
- const pipes = [];
1139
- for (;;) {
1140
- let ops;
1141
- ({
1142
- i: n,
1143
- ops
1144
- } = await opEquality(src, n, c));
1145
- pipes.push(ops);
1146
- const m = (0, _util.matchWord)(src, n, c, {
1147
- spaceBefore: true,
1148
- phrase: 'and',
1149
- spaceAfter: true
1150
- });
1151
- if (!m.is) break;
1152
- ({
1153
- i: n
1154
- } = m);
1155
- }
1156
- if (pipes.length === 1) return {
1157
- i: n,
1158
- ops: pipes[0]
1159
- };
1160
- return {
1161
- i: n,
1162
- ops: [{
1163
- op: _library.OP_AND,
1164
- params: {
1165
- pipes
1166
- }
1167
- }]
1168
- };
1169
- }
1170
-
1171
- /** Parse equality at i */
1172
- async function opEquality(src, i, c) {
1173
- let n = i;
1174
- let ops;
1175
- ({
1176
- i: n,
1177
- ops
1178
- } = await opComparison(src, n, c));
1179
- const comparisons = [];
1180
- for (;;) {
1181
- let m = (0, _util.matchWord)(src, n, c, {
1182
- phrase: '=='
1183
- });
1184
- if (m.is) {
1185
- ({
1186
- i: n
1187
- } = m);
1188
- let opsBy;
1189
- ({
1190
- i: n,
1191
- ops: opsBy
1192
- } = await opComparison(src, n, c));
1193
- comparisons.push({
1194
- op: _library.OPC_EQUAL,
1195
- params: {
1196
- by: opsBy
1197
- }
1198
- });
1199
- continue;
1200
- }
1201
- m = (0, _util.matchWord)(src, n, c, {
1202
- phrase: '!='
1203
- });
1204
- if (m.is) {
1205
- ({
1206
- i: n
1207
- } = m);
1208
- let opsBy;
1209
- ({
1210
- i: n,
1211
- ops: opsBy
1212
- } = await opComparison(src, n, c));
1213
- comparisons.push({
1214
- op: _library.OPC_UNEQUAL,
1215
- params: {
1216
- by: opsBy
1217
- }
1218
- });
1219
- continue;
1220
- }
1221
- break;
1222
- }
1223
- if (comparisons.length === 0) return {
1224
- i: n,
1225
- ops
1226
- };
1227
- return {
1228
- i: n,
1229
- ops: [{
1230
- op: _library.OP_COMPARISON,
1231
- params: {
1232
- pipe: ops,
1233
- comparisons
1234
- }
1235
- }]
1236
- };
1237
- }
1238
-
1239
- /** Parse comparison at i */
1240
- async function opComparison(src, i, c) {
1241
- let n = i;
1242
- let ops;
1243
- ({
1244
- i: n,
1245
- ops
1246
- } = await opNot(src, n, c));
1247
- const comparisons = [];
1248
- for (;;) {
1249
- let m = (0, _util.matchWord)(src, n, c, {
1250
- phrase: '<='
1251
- });
1252
- if (m.is) {
1253
- ({
1254
- i: n
1255
- } = m);
1256
- let opsBy;
1257
- ({
1258
- i: n,
1259
- ops: opsBy
1260
- } = await opNot(src, n, c));
1261
- comparisons.push({
1262
- op: _library.OPC_LESSEQUAL,
1263
- params: {
1264
- by: opsBy
1265
- }
1266
- });
1267
- continue;
1268
- }
1269
- m = (0, _util.matchWord)(src, n, c, {
1270
- phrase: '<'
1271
- });
1272
- if (m.is) {
1273
- ({
1274
- i: n
1275
- } = m);
1276
- let opsBy;
1277
- ({
1278
- i: n,
1279
- ops: opsBy
1280
- } = await opNot(src, n, c));
1281
- comparisons.push({
1282
- op: _library.OPC_LESS,
1283
- params: {
1284
- by: opsBy
1285
- }
1286
- });
1287
- continue;
1288
- }
1289
- m = (0, _util.matchWord)(src, n, c, {
1290
- phrase: '>='
1291
- });
1292
- if (m.is) {
1293
- ({
1294
- i: n
1295
- } = m);
1296
- let opsBy;
1297
- ({
1298
- i: n,
1299
- ops: opsBy
1300
- } = await opNot(src, n, c));
1301
- comparisons.push({
1302
- op: _library.OPC_GREATEREQUAL,
1303
- params: {
1304
- by: opsBy
1305
- }
1306
- });
1307
- continue;
1308
- }
1309
- m = (0, _util.matchWord)(src, n, c, {
1310
- phrase: '>'
1311
- });
1312
- if (m.is) {
1313
- ({
1314
- i: n
1315
- } = m);
1316
- let opsBy;
1317
- ({
1318
- i: n,
1319
- ops: opsBy
1320
- } = await opNot(src, n, c));
1321
- comparisons.push({
1322
- op: _library.OPC_GREATER,
1323
- params: {
1324
- by: opsBy
1325
- }
1326
- });
1327
- continue;
1328
- }
1329
- break;
1330
- }
1331
- if (comparisons.length === 0) return {
1332
- i: n,
1333
- ops
1334
- };
1335
- return {
1336
- i: n,
1337
- ops: [{
1338
- op: _library.OP_COMPARISON,
1339
- params: {
1340
- pipe: ops,
1341
- comparisons
1342
- }
1343
- }]
1344
- };
1345
- }
1346
-
1347
- /** Parse not at i */
1348
- async function opNot(src, i, c) {
1349
- let n = i;
1350
- const m = (0, _util.matchWord)(src, n, c, {
1351
- phrase: 'not',
1352
- spaceAfter: true
1353
- });
1354
- if (!m.is) return opErrorSuppression(src, n, c);
1355
- ({
1356
- i: n
1357
- } = m);
1358
- let ops;
1359
- ({
1360
- i: n,
1361
- ops
1362
- } = await opErrorSuppression(src, n, c));
1363
- return {
1364
- i: n,
1365
- ops: [...ops, {
1366
- op: _library.OP_NOT
1367
- }]
1368
- };
1369
- }
1370
-
1371
- /** Parse error suppression at i */
1372
- async function opErrorSuppression(src, i, c) {
1373
- let n = i;
1374
- const result = await opDifference(src, n, c);
1375
- ({
1376
- i: n
1377
- } = result);
1378
- const m = (0, _util.matchWord)(src, n, c, {
1379
- phrase: '?',
1380
- notBeforeSet: '?='
1381
- });
1382
- if (!m.is) return result;
1383
- ({
1384
- i: n
1385
- } = m);
1386
- return {
1387
- i: n,
1388
- ops: [{
1389
- op: _library.OP_TRY,
1390
- params: {
1391
- try: result.ops,
1392
- catch: [{
1393
- op: _library.OP_VOID
1394
- }]
1395
- }
1396
- }]
1397
- };
1398
- }
1399
-
1400
- /** Parse difference at i */
1401
- async function opDifference(src, i, c) {
1402
- let n = i;
1403
- let ops;
1404
- ({
1405
- i: n,
1406
- ops
1407
- } = await opMultiplication(src, n, c));
1408
- const operations = [];
1409
- for (;;) {
1410
- let m = (0, _util.matchWord)(src, n, c, {
1411
- phrase: '+',
1412
- notBeforeSet: '='
1413
- });
1414
- if (m.is) {
1415
- ({
1416
- i: n
1417
- } = m);
1418
- let opsBy;
1419
- ({
1420
- i: n,
1421
- ops: opsBy
1422
- } = await opMultiplication(src, n, c));
1423
- operations.push({
1424
- op: _library.OPM_ADDITION,
1425
- params: {
1426
- by: opsBy
1427
- }
1428
- });
1429
- continue;
1430
- }
1431
- m = (0, _util.matchWord)(src, n, c, {
1432
- phrase: '-',
1433
- notBeforeSet: '=>'
1434
- });
1435
- if (m.is) {
1436
- ({
1437
- i: n
1438
- } = m);
1439
- let opsBy;
1440
- ({
1441
- i: n,
1442
- ops: opsBy
1443
- } = await opMultiplication(src, n, c));
1444
- operations.push({
1445
- op: _library.OPM_SUBTRACTION,
1446
- params: {
1447
- by: opsBy
1448
- }
1449
- });
1450
- continue;
1451
- }
1452
- break;
1453
- }
1454
- if (operations.length === 0) return {
1455
- i: n,
1456
- ops
1457
- };
1458
- return {
1459
- i: n,
1460
- ops: [{
1461
- op: _library.OP_CALCULATION,
1462
- params: {
1463
- pipe: ops,
1464
- operations
1465
- }
1466
- }]
1467
- };
1468
- }
1469
-
1470
- /** Parse multiplication at i */
1471
- async function opMultiplication(src, i, c) {
1472
- let n = i;
1473
- let ops;
1474
- ({
1475
- i: n,
1476
- ops
1477
- } = await opNullCoalescence(src, n, c));
1478
- const operations = [];
1479
- for (;;) {
1480
- let m = (0, _util.matchWord)(src, n, c, {
1481
- phrase: '*',
1482
- notBeforeSet: '='
1483
- });
1484
- if (m.is) {
1485
- ({
1486
- i: n
1487
- } = m);
1488
- let opsBy;
1489
- ({
1490
- i: n,
1491
- ops: opsBy
1492
- } = await opNullCoalescence(src, n, c));
1493
- operations.push({
1494
- op: _library.OPM_MULTIPLICATION,
1495
- params: {
1496
- by: opsBy
1497
- }
1498
- });
1499
- continue;
1500
- }
1501
- m = (0, _util.matchWord)(src, n, c, {
1502
- phrase: '/',
1503
- notBeforeSet: '='
1504
- });
1505
- if (m.is) {
1506
- ({
1507
- i: n
1508
- } = m);
1509
- let opsBy;
1510
- ({
1511
- i: n,
1512
- ops: opsBy
1513
- } = await opNullCoalescence(src, n, c));
1514
- operations.push({
1515
- op: _library.OPM_DIVISION,
1516
- params: {
1517
- by: opsBy
1518
- }
1519
- });
1520
- continue;
1521
- }
1522
- m = (0, _util.matchWord)(src, n, c, {
1523
- phrase: '%',
1524
- notBeforeSet: '='
1525
- });
1526
- if (m.is) {
1527
- ({
1528
- i: n
1529
- } = m);
1530
- let opsBy;
1531
- ({
1532
- i: n,
1533
- ops: opsBy
1534
- } = await opNullCoalescence(src, n, c));
1535
- operations.push({
1536
- op: _library.OPM_REMAINDER,
1537
- params: {
1538
- by: opsBy
1539
- }
1540
- });
1541
- continue;
1542
- }
1543
- break;
1544
- }
1545
- if (operations.length === 0) return {
1546
- i: n,
1547
- ops
1548
- };
1549
- return {
1550
- i: n,
1551
- ops: [{
1552
- op: _library.OP_CALCULATION,
1553
- params: {
1554
- pipe: ops,
1555
- operations
1556
- }
1557
- }]
1558
- };
1559
- }
1560
-
1561
- /** Parse null coalescence at i */
1562
- async function opNullCoalescence(src, i, c) {
1563
- let n = i;
1564
- const pipes = [];
1565
- for (;;) {
1566
- let ops;
1567
- ({
1568
- i: n,
1569
- ops
1570
- } = await opNegation(src, n, c));
1571
- pipes.push(ops);
1572
- const m = (0, _util.matchWord)(src, n, c, {
1573
- phrase: '??'
1574
- });
1575
- if (!m.is) break;
1576
- ({
1577
- i: n
1578
- } = m);
1579
- }
1580
- if (pipes.length === 1) return {
1581
- i: n,
1582
- ops: pipes[0]
1583
- };
1584
- return {
1585
- i: n,
1586
- ops: [{
1587
- op: _library.OP_NULL_COALESCENCE,
1588
- params: {
1589
- pipes
1590
- }
1591
- }]
1592
- };
1593
- }
1594
-
1595
- /** Parse negation at i */
1596
- async function opNegation(src, i, c) {
1597
- let n = i;
1598
- const m = (0, _util.matchWord)(src, n, c, {
1599
- phrase: '-',
1600
- notBeforeSet: '=>'
1601
- });
1602
- if (!m.is) return opIf(src, n, c);
1603
- ({
1604
- i: n
1605
- } = m);
1606
- let ops;
1607
- ({
1608
- i: n,
1609
- ops
1610
- } = await opIf(src, n, c));
1611
- return {
1612
- i: n,
1613
- ops: [...ops, {
1614
- op: _library.OP_NEGATION
1615
- }]
1616
- };
1617
- }
1618
-
1619
- /** Parse if at i */
1620
- async function opIf(src, i, c) {
1621
- let n = i;
1622
- let m = (0, _util.matchWord)(src, n, c, {
1623
- phrase: 'if',
1624
- spaceAfter: true
1625
- });
1626
- if (!m.is) return opConstant(src, n, c);
1627
- ({
1628
- i: n
1629
- } = m);
1630
- const ifs = [];
1631
- for (;;) {
1632
- let opsIf;
1633
- ({
1634
- i: n,
1635
- ops: opsIf
1636
- } = await opPipe(src, n, c));
1637
- m = (0, _util.matchWord)(src, n, c, {
1638
- spaceBefore: true,
1639
- phrase: 'then',
1640
- spaceAfter: true
1641
- });
1642
- ({
1643
- i: n
1644
- } = m);
1645
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
1646
- operator: 'if statement',
1647
- message: "expected 'then'"
1648
- });
1649
- let opsThen;
1650
- ({
1651
- i: n,
1652
- ops: opsThen
1653
- } = await opPipe(src, n, c));
1654
- ifs.push({
1655
- if: opsIf,
1656
- then: opsThen
1657
- });
1658
- m = (0, _util.matchWord)(src, n, c, {
1659
- spaceBefore: true,
1660
- phrase: 'elif',
1661
- spaceAfter: true
1662
- });
1663
- if (!m.is) break;
1664
- ({
1665
- i: n
1666
- } = m);
1667
- }
1668
- let opsElse;
1669
- m = (0, _util.matchWord)(src, n, c, {
1670
- spaceBefore: true,
1671
- phrase: 'else',
1672
- spaceAfter: true
1673
- });
1674
- if (m.is) {
1675
- ({
1676
- i: n
1677
- } = m);
1678
- ({
1679
- i: n,
1680
- ops: opsElse
1681
- } = await opPipe(src, n, c));
1682
- } else opsElse = [];
1683
- m = (0, _util.matchWord)(src, n, c, {
1684
- spaceBefore: true,
1685
- phrase: 'end'
1686
- });
1687
- ({
1688
- i: n
1689
- } = m);
1690
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
1691
- operator: 'if statement',
1692
- message: "expected 'end'"
1693
- });
1694
- return {
1695
- i: n,
1696
- ops: [{
1697
- op: _library.OP_IF,
1698
- params: {
1699
- ifs,
1700
- else: opsElse
1701
- }
1702
- }]
1703
- };
1704
- }
1705
-
1706
- /** Parse constant at i */
1707
- function opConstant(src, i, c) {
1708
- let n = i;
1709
- let m = (0, _util.matchWord)(src, n, c, {
1710
- phrase: 'true',
1711
- spaceAfter: true
1712
- });
1713
- if (m.is) {
1714
- ({
1715
- i: n
1716
- } = m);
1717
- return {
1718
- i: n,
1719
- ops: [{
1720
- op: _library.OP_CONSTANT_TRUE
1721
- }]
1722
- };
1723
- }
1724
- m = (0, _util.matchWord)(src, n, c, {
1725
- phrase: 'false',
1726
- spaceAfter: true
1727
- });
1728
- if (m.is) {
1729
- ({
1730
- i: n
1731
- } = m);
1732
- return {
1733
- i: n,
1734
- ops: [{
1735
- op: _library.OP_CONSTANT_FALSE
1736
- }]
1737
- };
1738
- }
1739
- m = (0, _util.matchWord)(src, n, c, {
1740
- phrase: 'null',
1741
- spaceAfter: true
1742
- });
1743
- if (m.is) {
1744
- ({
1745
- i: n
1746
- } = m);
1747
- return {
1748
- i: n,
1749
- ops: [{
1750
- op: _library.OP_CONSTANT_NULL
1751
- }]
1752
- };
1753
- }
1754
- return opNumber(src, n, c);
1755
- }
1756
-
1757
- /** Parse number at i */
1758
- async function opNumber(src, i, c) {
1759
- let n = i;
1760
- const result = await parseNumber(src, n, c);
1761
- if (!result.is) return opNamedFunctionDefinition(src, n, c);
1762
- ({
1763
- i: n
1764
- } = result);
1765
- return {
1766
- i: n,
1767
- ops: result.ops
1768
- };
1769
- }
1770
-
1771
- /** Parse named function definition at i */
1772
- async function opNamedFunctionDefinition(src, i, c) {
1773
- let n = i;
1774
- const m = (0, _util.matchWord)(src, n, c, {
1775
- phrase: 'func',
1776
- spaceAfter: true
1777
- });
1778
- if (!m.is) return opFunctionDefinition(src, n, c);
1779
- ({
1780
- i: n
1781
- } = m);
1782
- const v = (0, _util.safeVariable)(src, n, c);
1783
- if (!v.is) return opFunctionDefinition(src, i, c);
1784
- let name;
1785
- ({
1786
- i: n,
1787
- value: name
1788
- } = v);
1789
- let argNames;
1790
- ({
1791
- i: n,
1792
- argNames
1793
- } = await parseFunctionHeader(src, n, c));
1794
- let ops;
1795
- ({
1796
- i: n,
1797
- ops
1798
- } = await opSubRoute(src, n, c));
1799
- return {
1800
- i: n,
1801
- ops: [{
1802
- op: _library.OP_VARIABLE_DEFINITION,
1803
- params: {
1804
- name,
1805
- pipe: [{
1806
- op: _library.OP_FUNCTION_DEFINITION,
1807
- params: {
1808
- argNames,
1809
- pipe: ops
1810
- }
1811
- }]
1812
- }
1813
- }]
1814
- };
1815
- }
1816
-
1817
- /** Parse function definition at i */
1818
- async function opFunctionDefinition(src, i, c) {
1819
- let n = i;
1820
- const m = (0, _util.matchWord)(src, n, c, {
1821
- phrase: 'func',
1822
- spaceAfter: true
1823
- });
1824
- if (!m.is) return opVariableAccess(src, n, c);
1825
- ({
1826
- i: n
1827
- } = m);
1828
- let argNames;
1829
- ({
1830
- i: n,
1831
- argNames
1832
- } = await parseFunctionHeader(src, n, c));
1833
- let ops;
1834
- ({
1835
- i: n,
1836
- ops
1837
- } = await opSubRoute(src, n, c));
1838
- return {
1839
- i: n,
1840
- ops: [{
1841
- op: _library.OP_FUNCTION_DEFINITION,
1842
- params: {
1843
- argNames,
1844
- pipe: ops
1845
- }
1846
- }]
1847
- };
1848
- }
1849
-
1850
- /** Parse variable definition at i */
1851
- async function opVariableAccess(src, i, c) {
1852
- let n = i;
1853
- const v = (0, _util.safeVariable)(src, n, c);
1854
- if (!v.is) return opValueAccess(src, n, c);
1855
- let name;
1856
- ({
1857
- i: n,
1858
- value: name
1859
- } = v);
1860
- let selectors;
1861
- let canAssign;
1862
- const ac = await parseAccess(src, n, c);
1863
- if (ac.is) ({
1864
- i: n,
1865
- selectors,
1866
- canAssign
1867
- } = ac);else {
1868
- selectors = [];
1869
- canAssign = true;
1870
- }
1871
- if (!canAssign) {
1872
- const ops = [{
1873
- op: _library.OP_VARIABLE,
1874
- params: {
1875
- name
1876
- }
1877
- }];
1878
- if (selectors.length === 0) return {
1879
- i: n,
1880
- ops
1881
- };
1882
- return {
1883
- i: n,
1884
- ops: [{
1885
- op: _library.OP_ACCESS,
1886
- params: {
1887
- pipe: ops,
1888
- selectors
1889
- }
1890
- }]
1891
- };
1892
- }
1893
- const as = await parseAssignment(src, n, c);
1894
- if (!as.is) {
1895
- const ops = [{
1896
- op: _library.OP_VARIABLE,
1897
- params: {
1898
- name
1899
- }
1900
- }];
1901
- if (selectors.length === 0) return {
1902
- i: n,
1903
- ops
1904
- };
1905
- return {
1906
- i: n,
1907
- ops: [{
1908
- op: _library.OP_ACCESS,
1909
- params: {
1910
- pipe: ops,
1911
- selectors
1912
- }
1913
- }]
1914
- };
1915
- }
1916
- let opAssignment;
1917
- ({
1918
- i: n,
1919
- assignment: opAssignment
1920
- } = as);
1921
- if (selectors.length === 0 && opAssignment.op === _library.OPU_SET) {
1922
- return {
1923
- i: n,
1924
- ops: [{
1925
- op: _library.OP_VARIABLE_DEFINITION,
1926
- params: {
1927
- name,
1928
- pipe: opAssignment.params.pipe
1929
- }
1930
- }]
1931
- };
1932
- }
1933
- return {
1934
- i: n,
1935
- ops: [{
1936
- op: _library.OP_VARIABLE_DEFINITION,
1937
- params: {
1938
- name,
1939
- pipe: [{
1940
- op: _library.OP_ASSIGNMENT,
1941
- params: {
1942
- pipe: [{
1943
- op: _library.OP_VARIABLE,
1944
- params: {
1945
- name
1946
- }
1947
- }],
1948
- selectors,
1949
- assignment: opAssignment
1950
- }
1951
- }]
1952
- }
1953
- }]
1954
- };
1955
- }
1956
-
1957
- /** Parse variable access at i */
1958
- async function opValueAccess(src, i, c) {
1959
- let n = i;
1960
- const selectors = [];
1961
- let ops;
1962
- let m = (0, _util.matchWord)(src, n, c, {
1963
- phrase: '.'
1964
- });
1965
- if (!m.is) ({
1966
- i: n,
1967
- ops
1968
- } = await opObjectConstructor(src, n, c));else {
1969
- ({
1970
- i: n
1971
- } = m);
1972
- ops = [];
1973
- const v = (0, _util.safeVariable)(src, n, c);
1974
- if (v.is) {
1975
- let name;
1976
- ({
1977
- i: n,
1978
- value: name
1979
- } = v);
1980
- let optional;
1981
- m = (0, _util.matchWord)(src, n, c, {
1982
- phrase: '?',
1983
- notBeforeSet: '?='
1984
- });
1985
- if (m.is) ({
1986
- i: n,
1987
- is: optional
1988
- } = m);
1989
- selectors.push({
1990
- op: _library.OPA_FIELD,
1991
- params: {
1992
- pipe: [{
1993
- op: _library.OP_STRING,
1994
- params: {
1995
- string: name
1996
- }
1997
- }],
1998
- optional
1999
- }
2000
- });
2001
- }
2002
- }
2003
- const ac = await parseAccess(src, n, c, {
2004
- identity: ops.length === 0 && selectors.length === 0
2005
- });
2006
- let canAssign;
2007
- if (ac.is) {
2008
- ({
2009
- i: n,
2010
- canAssign
2011
- } = ac);
2012
- selectors.push(...ac.selectors);
2013
- } else canAssign = selectors.length > 0;
2014
- if (selectors.length === 0) return {
2015
- i: n,
2016
- ops
2017
- };
2018
- if (!canAssign) return {
2019
- i: n,
2020
- ops: [{
2021
- op: _library.OP_ACCESS,
2022
- params: {
2023
- pipe: ops,
2024
- selectors
2025
- }
2026
- }]
2027
- };
2028
- const as = await parseAssignment(src, n, c);
2029
- if (!as.is) return {
2030
- i: n,
2031
- ops: [{
2032
- op: _library.OP_ACCESS,
2033
- params: {
2034
- pipe: ops,
2035
- selectors
2036
- }
2037
- }]
2038
- };
2039
- let opAssignment;
2040
- ({
2041
- i: n,
2042
- assignment: opAssignment
2043
- } = as);
2044
- return {
2045
- i: n,
2046
- ops: [{
2047
- op: _library.OP_ASSIGNMENT,
2048
- params: {
2049
- pipe: ops,
2050
- selectors,
2051
- assignment: opAssignment
2052
- }
2053
- }]
2054
- };
2055
- }
2056
-
2057
- /** Parse object constructor at i */
2058
- async function opObjectConstructor(src, i, c) {
2059
- let n = i;
2060
- let m = (0, _util.matchWord)(src, n, c, {
2061
- phrase: '{'
2062
- });
2063
- if (!m.is) return opArrayConstructor(src, n, c);
2064
- ({
2065
- i: n
2066
- } = m);
2067
- const fields = [];
2068
- m = (0, _util.matchWord)(src, n, c, {
2069
- phrase: '}'
2070
- });
2071
- if (m.is) ({
2072
- i: n
2073
- } = m);else for (;;) {
2074
- m = (0, _util.matchWord)(src, n, c, {
2075
- phrase: '('
2076
- });
2077
- if (m.is) {
2078
- ({
2079
- i: n
2080
- } = m);
2081
- let opsKey;
2082
- ({
2083
- i: n,
2084
- ops: opsKey
2085
- } = await opPipe(src, n, c));
2086
- m = (0, _util.matchWord)(src, n, c, {
2087
- phrase: ')'
2088
- });
2089
- ({
2090
- i: n
2091
- } = m);
2092
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
2093
- operator: 'object',
2094
- message: "expected ')'"
2095
- });
2096
- let optional;
2097
- ({
2098
- i: n,
2099
- is: optional
2100
- } = (0, _util.matchWord)(src, n, c, {
2101
- phrase: '?'
2102
- }));
2103
- m = (0, _util.matchWord)(src, n, c, {
2104
- phrase: ':'
2105
- });
2106
- ({
2107
- i: n
2108
- } = m);
2109
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
2110
- operator: 'object',
2111
- message: "expected ':'"
2112
- });
2113
- let opsValue;
2114
- ({
2115
- i: n,
2116
- ops: opsValue
2117
- } = await opSubPipe(src, n, c));
2118
- fields.push({
2119
- key: opsKey,
2120
- value: opsValue,
2121
- optional
2122
- });
2123
- m = (0, _util.matchWord)(src, n, c, {
2124
- phrase: '}'
2125
- });
2126
- if (m.is) {
2127
- ({
2128
- i: n
2129
- } = m);
2130
- break;
2131
- }
2132
- m = (0, _util.matchWord)(src, n, c, {
2133
- phrase: ','
2134
- });
2135
- ({
2136
- i: n
2137
- } = m);
2138
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
2139
- operator: 'object',
2140
- message: "expected ',' or '}'"
2141
- });
2142
- continue;
2143
- }
2144
- const s = await parseString(src, n, c);
2145
- if (s.is) {
2146
- let opsKey;
2147
- ({
2148
- i: n,
2149
- ops: opsKey
2150
- } = s);
2151
- m = (0, _util.matchWord)(src, n, c, {
2152
- phrase: ':'
2153
- });
2154
- ({
2155
- i: n
2156
- } = m);
2157
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
2158
- operator: 'object',
2159
- message: "expected ':'"
2160
- });
2161
- let opsValue;
2162
- ({
2163
- i: n,
2164
- ops: opsValue
2165
- } = await opSubPipe(src, n, c));
2166
- fields.push({
2167
- key: opsKey,
2168
- value: opsValue,
2169
- optional: false
2170
- });
2171
- m = (0, _util.matchWord)(src, n, c, {
2172
- phrase: '}'
2173
- });
2174
- if (m.is) {
2175
- ({
2176
- i: n
2177
- } = m);
2178
- break;
2179
- }
2180
- m = (0, _util.matchWord)(src, n, c, {
2181
- phrase: ','
2182
- });
2183
- ({
2184
- i: n
2185
- } = m);
2186
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
2187
- operator: 'object',
2188
- message: "expected ',' or '}'"
2189
- });
2190
- continue;
2191
- }
2192
- const v = (0, _util.safeVariable)(src, n, c);
2193
- if (v.is) {
2194
- let name;
2195
- ({
2196
- i: n,
2197
- value: name
2198
- } = v);
2199
- let opsValue;
2200
- m = (0, _util.matchWord)(src, n, c, {
2201
- phrase: ':'
2202
- });
2203
- if (m.is) {
2204
- ({
2205
- i: n
2206
- } = m);
2207
- ({
2208
- i: n,
2209
- ops: opsValue
2210
- } = await opSubPipe(src, n, c));
2211
- } else {
2212
- let optional;
2213
- ({
2214
- i: n,
2215
- is: optional
2216
- } = (0, _util.matchWord)(src, n, c, {
2217
- phrase: '?'
2218
- }));
2219
- opsValue = optional ? [{
2220
- op: _library.OP_TRY,
2221
- params: {
2222
- try: [{
2223
- op: _library.OP_VARIABLE,
2224
- params: {
2225
- name
2226
- }
2227
- }],
2228
- catch: [{
2229
- op: _library.OP_VOID
2230
- }]
2231
- }
2232
- }] : [{
2233
- op: _library.OP_VARIABLE,
2234
- params: {
2235
- name
2236
- }
2237
- }];
2238
- }
2239
- fields.push({
2240
- key: [{
2241
- op: _library.OP_STRING,
2242
- params: {
2243
- string: name
2244
- }
2245
- }],
2246
- value: opsValue,
2247
- optional: false
2248
- });
2249
- m = (0, _util.matchWord)(src, n, c, {
2250
- phrase: '}'
2251
- });
2252
- if (m.is) {
2253
- ({
2254
- i: n
2255
- } = m);
2256
- break;
2257
- }
2258
- m = (0, _util.matchWord)(src, n, c, {
2259
- phrase: ','
2260
- });
2261
- ({
2262
- i: n
2263
- } = m);
2264
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
2265
- operator: 'object',
2266
- message: "expected ',' or '}'"
2267
- });
2268
- continue;
2269
- }
2270
- return (0, _util.errorUnexpectedToken)(src, n, c, {
2271
- operator: 'object',
2272
- message: 'expected field declaration'
2273
- });
2274
- }
2275
- return {
2276
- i: n,
2277
- ops: [{
2278
- op: _library.OP_OBJECT_CONSTRUCTOR,
2279
- params: {
2280
- fields
2281
- }
2282
- }]
2283
- };
2284
- }
2285
-
2286
- /** Parse array constructor at i */
2287
- async function opArrayConstructor(src, i, c) {
2288
- let n = i;
2289
- let m = (0, _util.matchWord)(src, n, c, {
2290
- phrase: '['
2291
- });
2292
- ({
2293
- i: n
2294
- } = m);
2295
- if (!m.is) return opStringLiteral(src, n, c);
2296
- let ops;
2297
- m = (0, _util.matchWord)(src, n, c, {
2298
- phrase: ']'
2299
- });
2300
- if (m.is) {
2301
- ({
2302
- i: n
2303
- } = m);
2304
- ops = [{
2305
- op: _library.OP_VOID
2306
- }];
2307
- } else {
2308
- ({
2309
- i: n,
2310
- ops
2311
- } = await opPipe(src, n, c));
2312
- m = (0, _util.matchWord)(src, n, c, {
2313
- phrase: ']'
2314
- });
2315
- ({
2316
- i: n
2317
- } = m);
2318
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
2319
- operator: 'array',
2320
- message: "expected ']'"
2321
- });
2322
- }
2323
- return {
2324
- i: n,
2325
- ops: [{
2326
- op: _library.OP_ARRAY_CONSTRUCTOR,
2327
- params: {
2328
- pipe: ops
2329
- }
2330
- }]
2331
- };
2332
- }
2333
-
2334
- /** Parse string literal at i */
2335
- async function opStringLiteral(src, i, c) {
2336
- let n = i;
2337
- const s = await parseString(src, n, c);
2338
- if (!s.is) return opGroup(src, n, c);
2339
- ({
2340
- i: n
2341
- } = s);
2342
- return {
2343
- i: n,
2344
- ops: s.ops
2345
- };
2346
- }
2347
-
2348
- /** Parse group at i */
2349
- async function opGroup(src, i, c) {
2350
- let n = i;
2351
- let m = (0, _util.matchWord)(src, n, c, {
2352
- phrase: '('
2353
- });
2354
- ({
2355
- i: n
2356
- } = m);
2357
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c);
2358
- let ops;
2359
- ({
2360
- i: n,
2361
- ops
2362
- } = await opPipe(src, n, c));
2363
- m = (0, _util.matchWord)(src, n, c, {
2364
- phrase: ')'
2365
- });
2366
- ({
2367
- i: n
2368
- } = m);
2369
- if (!m.is) return (0, _util.errorUnexpectedToken)(src, n, c, {
2370
- operator: 'group',
2371
- message: "expected ')'"
2372
- });
2373
- return {
2374
- i: n,
2375
- ops
2376
- };
2377
- }