@ricsam/formula-engine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (569) hide show
  1. package/README.md +100 -0
  2. package/dist/cjs/core/ast-traverser.cjs +124 -0
  3. package/dist/cjs/core/ast-traverser.cjs.map +10 -0
  4. package/dist/cjs/core/autofill-utils.cjs +304 -0
  5. package/dist/cjs/core/autofill-utils.cjs.map +10 -0
  6. package/dist/cjs/core/engine.cjs +390 -0
  7. package/dist/cjs/core/engine.cjs.map +10 -0
  8. package/dist/cjs/core/managers/cache-manager.cjs +58 -0
  9. package/dist/cjs/core/managers/cache-manager.cjs.map +10 -0
  10. package/dist/cjs/core/managers/dependency-manager.cjs +620 -0
  11. package/dist/cjs/core/managers/dependency-manager.cjs.map +10 -0
  12. package/dist/cjs/core/managers/dependency-node.cjs +24 -0
  13. package/dist/cjs/core/managers/dependency-node.cjs.map +9 -0
  14. package/dist/cjs/core/managers/evaluation-manager.cjs +433 -0
  15. package/dist/cjs/core/managers/evaluation-manager.cjs.map +10 -0
  16. package/dist/cjs/core/managers/event-manager.cjs +49 -0
  17. package/dist/cjs/core/managers/event-manager.cjs.map +10 -0
  18. package/dist/cjs/core/managers/frontier-dependency-manager.cjs +181 -0
  19. package/dist/cjs/core/managers/frontier-dependency-manager.cjs.map +10 -0
  20. package/dist/cjs/core/managers/index.cjs +49 -0
  21. package/dist/cjs/core/managers/index.cjs.map +10 -0
  22. package/dist/cjs/core/managers/isDependencyNode.cjs +44 -0
  23. package/dist/cjs/core/managers/isDependencyNode.cjs.map +10 -0
  24. package/dist/cjs/core/managers/named-expression-manager.cjs +379 -0
  25. package/dist/cjs/core/managers/named-expression-manager.cjs.map +10 -0
  26. package/dist/cjs/core/managers/range-eval-order-builder.cjs +644 -0
  27. package/dist/cjs/core/managers/range-eval-order-builder.cjs.map +10 -0
  28. package/dist/cjs/core/managers/table-manager.cjs +254 -0
  29. package/dist/cjs/core/managers/table-manager.cjs.map +10 -0
  30. package/dist/cjs/core/managers/workbook-manager.cjs +474 -0
  31. package/dist/cjs/core/managers/workbook-manager.cjs.map +10 -0
  32. package/dist/cjs/core/map-serializer.cjs +69 -0
  33. package/dist/cjs/core/map-serializer.cjs.map +10 -0
  34. package/dist/cjs/core/named-expression-renamer.cjs +88 -0
  35. package/dist/cjs/core/named-expression-renamer.cjs.map +10 -0
  36. package/dist/cjs/core/sheet-renamer.cjs +89 -0
  37. package/dist/cjs/core/sheet-renamer.cjs.map +10 -0
  38. package/dist/cjs/core/sheet-utils.cjs +39 -0
  39. package/dist/cjs/core/sheet-utils.cjs.map +10 -0
  40. package/dist/cjs/core/table-renamer.cjs +88 -0
  41. package/dist/cjs/core/table-renamer.cjs.map +10 -0
  42. package/dist/cjs/core/types.cjs +48 -0
  43. package/dist/cjs/core/types.cjs.map +10 -0
  44. package/dist/cjs/core/utils/range-serializer.cjs +65 -0
  45. package/dist/cjs/core/utils/range-serializer.cjs.map +10 -0
  46. package/dist/cjs/core/utils/spreadsheet-visualizer.cjs +142 -0
  47. package/dist/cjs/core/utils/spreadsheet-visualizer.cjs.map +10 -0
  48. package/dist/cjs/core/utils.cjs +434 -0
  49. package/dist/cjs/core/utils.cjs.map +10 -0
  50. package/dist/cjs/core/workbook-renamer.cjs +106 -0
  51. package/dist/cjs/core/workbook-renamer.cjs.map +10 -0
  52. package/dist/cjs/debug/flags.cjs +47 -0
  53. package/dist/cjs/debug/flags.cjs.map +10 -0
  54. package/dist/cjs/evaluator/arithmetic/add/add.cjs +82 -0
  55. package/dist/cjs/evaluator/arithmetic/add/add.cjs.map +10 -0
  56. package/dist/cjs/evaluator/arithmetic/divide/divide.cjs +107 -0
  57. package/dist/cjs/evaluator/arithmetic/divide/divide.cjs.map +10 -0
  58. package/dist/cjs/evaluator/arithmetic/multiply/multiply.cjs +93 -0
  59. package/dist/cjs/evaluator/arithmetic/multiply/multiply.cjs.map +10 -0
  60. package/dist/cjs/evaluator/arithmetic/power/power.cjs +125 -0
  61. package/dist/cjs/evaluator/arithmetic/power/power.cjs.map +10 -0
  62. package/dist/cjs/evaluator/arithmetic/subtract/subtract.cjs +84 -0
  63. package/dist/cjs/evaluator/arithmetic/subtract/subtract.cjs.map +10 -0
  64. package/dist/cjs/evaluator/comparison/equals.cjs +64 -0
  65. package/dist/cjs/evaluator/comparison/equals.cjs.map +10 -0
  66. package/dist/cjs/evaluator/comparison/greater-than-or-equal.cjs +61 -0
  67. package/dist/cjs/evaluator/comparison/greater-than-or-equal.cjs.map +10 -0
  68. package/dist/cjs/evaluator/comparison/greater-than.cjs +61 -0
  69. package/dist/cjs/evaluator/comparison/greater-than.cjs.map +10 -0
  70. package/dist/cjs/evaluator/comparison/less-than-or-equal.cjs +69 -0
  71. package/dist/cjs/evaluator/comparison/less-than-or-equal.cjs.map +10 -0
  72. package/dist/cjs/evaluator/comparison/less-than.cjs +68 -0
  73. package/dist/cjs/evaluator/comparison/less-than.cjs.map +10 -0
  74. package/dist/cjs/evaluator/comparison/not-equals.cjs +53 -0
  75. package/dist/cjs/evaluator/comparison/not-equals.cjs.map +10 -0
  76. package/dist/cjs/evaluator/concatenation/concatenate.cjs +72 -0
  77. package/dist/cjs/evaluator/concatenation/concatenate.cjs.map +10 -0
  78. package/dist/cjs/evaluator/dependency-nodes/ast-evaluation-node.cjs +58 -0
  79. package/dist/cjs/evaluator/dependency-nodes/ast-evaluation-node.cjs.map +10 -0
  80. package/dist/cjs/evaluator/dependency-nodes/base-eval-node.cjs +112 -0
  81. package/dist/cjs/evaluator/dependency-nodes/base-eval-node.cjs.map +10 -0
  82. package/dist/cjs/evaluator/dependency-nodes/cell-value-node.cjs +54 -0
  83. package/dist/cjs/evaluator/dependency-nodes/cell-value-node.cjs.map +10 -0
  84. package/dist/cjs/evaluator/dependency-nodes/empty-cell-evaluation-node.cjs +108 -0
  85. package/dist/cjs/evaluator/dependency-nodes/empty-cell-evaluation-node.cjs.map +10 -0
  86. package/dist/cjs/evaluator/dependency-nodes/spill-meta-node.cjs +50 -0
  87. package/dist/cjs/evaluator/dependency-nodes/spill-meta-node.cjs.map +10 -0
  88. package/dist/cjs/evaluator/evaluate-scalar-operator.cjs +254 -0
  89. package/dist/cjs/evaluator/evaluate-scalar-operator.cjs.map +10 -0
  90. package/dist/cjs/evaluator/evaluation-context.cjs +154 -0
  91. package/dist/cjs/evaluator/evaluation-context.cjs.map +10 -0
  92. package/dist/cjs/evaluator/evaluation-error.cjs +75 -0
  93. package/dist/cjs/evaluator/evaluation-error.cjs.map +10 -0
  94. package/dist/cjs/evaluator/formula-evaluator.cjs +797 -0
  95. package/dist/cjs/evaluator/formula-evaluator.cjs.map +10 -0
  96. package/dist/cjs/evaluator/range-evaluation-node.cjs +88 -0
  97. package/dist/cjs/evaluator/range-evaluation-node.cjs.map +10 -0
  98. package/dist/cjs/functions/_template/template.cjs +42 -0
  99. package/dist/cjs/functions/_template/template.cjs.map +10 -0
  100. package/dist/cjs/functions/array/sequence/sequence.cjs +315 -0
  101. package/dist/cjs/functions/array/sequence/sequence.cjs.map +10 -0
  102. package/dist/cjs/functions/criteria-parser.cjs +217 -0
  103. package/dist/cjs/functions/criteria-parser.cjs.map +10 -0
  104. package/dist/cjs/functions/criteria-utils.cjs +291 -0
  105. package/dist/cjs/functions/criteria-utils.cjs.map +10 -0
  106. package/dist/cjs/functions/function-utils.cjs +63 -0
  107. package/dist/cjs/functions/function-utils.cjs.map +10 -0
  108. package/dist/cjs/functions/index.cjs +125 -0
  109. package/dist/cjs/functions/index.cjs.map +10 -0
  110. package/dist/cjs/functions/information/cell/cell.cjs +196 -0
  111. package/dist/cjs/functions/information/cell/cell.cjs.map +10 -0
  112. package/dist/cjs/functions/information/column/column.cjs +144 -0
  113. package/dist/cjs/functions/information/column/column.cjs.map +10 -0
  114. package/dist/cjs/functions/information/row/row.cjs +150 -0
  115. package/dist/cjs/functions/information/row/row.cjs.map +10 -0
  116. package/dist/cjs/functions/logical/and/and.cjs +112 -0
  117. package/dist/cjs/functions/logical/and/and.cjs.map +10 -0
  118. package/dist/cjs/functions/logical/if/if.cjs +195 -0
  119. package/dist/cjs/functions/logical/if/if.cjs.map +10 -0
  120. package/dist/cjs/functions/logical/iferror/iferror.cjs +126 -0
  121. package/dist/cjs/functions/logical/iferror/iferror.cjs.map +10 -0
  122. package/dist/cjs/functions/logical/or/or.cjs +112 -0
  123. package/dist/cjs/functions/logical/or/or.cjs.map +10 -0
  124. package/dist/cjs/functions/lookup/count/count-utils.cjs +65 -0
  125. package/dist/cjs/functions/lookup/count/count-utils.cjs.map +10 -0
  126. package/dist/cjs/functions/lookup/count/count.cjs +48 -0
  127. package/dist/cjs/functions/lookup/count/count.cjs.map +10 -0
  128. package/dist/cjs/functions/lookup/count/countif.cjs +94 -0
  129. package/dist/cjs/functions/lookup/count/countif.cjs.map +10 -0
  130. package/dist/cjs/functions/lookup/count/countifs.cjs +63 -0
  131. package/dist/cjs/functions/lookup/count/countifs.cjs.map +10 -0
  132. package/dist/cjs/functions/lookup/index-lookup/index-lookup.cjs +187 -0
  133. package/dist/cjs/functions/lookup/index-lookup/index-lookup.cjs.map +10 -0
  134. package/dist/cjs/functions/lookup/match/match.cjs +168 -0
  135. package/dist/cjs/functions/lookup/match/match.cjs.map +10 -0
  136. package/dist/cjs/functions/lookup/xlookup/xlookup.cjs +410 -0
  137. package/dist/cjs/functions/lookup/xlookup/xlookup.cjs.map +10 -0
  138. package/dist/cjs/functions/math/average/average-utils.cjs +72 -0
  139. package/dist/cjs/functions/math/average/average-utils.cjs.map +10 -0
  140. package/dist/cjs/functions/math/average/average.cjs +48 -0
  141. package/dist/cjs/functions/math/average/average.cjs.map +10 -0
  142. package/dist/cjs/functions/math/average/averageif.cjs +83 -0
  143. package/dist/cjs/functions/math/average/averageif.cjs.map +10 -0
  144. package/dist/cjs/functions/math/average/averageifs.cjs +61 -0
  145. package/dist/cjs/functions/math/average/averageifs.cjs.map +10 -0
  146. package/dist/cjs/functions/math/ceiling/ceiling.cjs +219 -0
  147. package/dist/cjs/functions/math/ceiling/ceiling.cjs.map +10 -0
  148. package/dist/cjs/functions/math/max/max-utils.cjs +71 -0
  149. package/dist/cjs/functions/math/max/max-utils.cjs.map +10 -0
  150. package/dist/cjs/functions/math/max/max.cjs +48 -0
  151. package/dist/cjs/functions/math/max/max.cjs.map +10 -0
  152. package/dist/cjs/functions/math/max/maxif.cjs +83 -0
  153. package/dist/cjs/functions/math/max/maxif.cjs.map +10 -0
  154. package/dist/cjs/functions/math/max/maxifs.cjs +61 -0
  155. package/dist/cjs/functions/math/max/maxifs.cjs.map +10 -0
  156. package/dist/cjs/functions/math/min/min-utils.cjs +71 -0
  157. package/dist/cjs/functions/math/min/min-utils.cjs.map +10 -0
  158. package/dist/cjs/functions/math/min/min.cjs +48 -0
  159. package/dist/cjs/functions/math/min/min.cjs.map +10 -0
  160. package/dist/cjs/functions/math/min/minif.cjs +83 -0
  161. package/dist/cjs/functions/math/min/minif.cjs.map +10 -0
  162. package/dist/cjs/functions/math/min/minifs.cjs +61 -0
  163. package/dist/cjs/functions/math/min/minifs.cjs.map +10 -0
  164. package/dist/cjs/functions/math/sum/sum.cjs +48 -0
  165. package/dist/cjs/functions/math/sum/sum.cjs.map +10 -0
  166. package/dist/cjs/functions/math/sum/sumif.cjs +83 -0
  167. package/dist/cjs/functions/math/sum/sumif.cjs.map +10 -0
  168. package/dist/cjs/functions/math/sum/sumifs.cjs +60 -0
  169. package/dist/cjs/functions/math/sum/sumifs.cjs.map +10 -0
  170. package/dist/cjs/functions/math/sum/summation-utils.cjs +57 -0
  171. package/dist/cjs/functions/math/sum/summation-utils.cjs.map +10 -0
  172. package/dist/cjs/functions/reference/address/address.cjs +163 -0
  173. package/dist/cjs/functions/reference/address/address.cjs.map +10 -0
  174. package/dist/cjs/functions/reference/indirect/indirect.cjs +102 -0
  175. package/dist/cjs/functions/reference/indirect/indirect.cjs.map +10 -0
  176. package/dist/cjs/functions/reference/offset/offset.cjs +233 -0
  177. package/dist/cjs/functions/reference/offset/offset.cjs.map +10 -0
  178. package/dist/cjs/functions/text/concatenate/concatenate.cjs +167 -0
  179. package/dist/cjs/functions/text/concatenate/concatenate.cjs.map +10 -0
  180. package/dist/cjs/functions/text/exact/exact.cjs +171 -0
  181. package/dist/cjs/functions/text/exact/exact.cjs.map +10 -0
  182. package/dist/cjs/functions/text/find/find.cjs +397 -0
  183. package/dist/cjs/functions/text/find/find.cjs.map +10 -0
  184. package/dist/cjs/functions/text/left/left.cjs +109 -0
  185. package/dist/cjs/functions/text/left/left.cjs.map +10 -0
  186. package/dist/cjs/functions/text/len/len.cjs +119 -0
  187. package/dist/cjs/functions/text/len/len.cjs.map +10 -0
  188. package/dist/cjs/functions/text/mid/mid.cjs +103 -0
  189. package/dist/cjs/functions/text/mid/mid.cjs.map +10 -0
  190. package/dist/cjs/functions/text/right/right.cjs +167 -0
  191. package/dist/cjs/functions/text/right/right.cjs.map +10 -0
  192. package/dist/cjs/functions/text/text-helpers.cjs +179 -0
  193. package/dist/cjs/functions/text/text-helpers.cjs.map +10 -0
  194. package/dist/cjs/functions/text/textjoin/textjoin.cjs +173 -0
  195. package/dist/cjs/functions/text/textjoin/textjoin.cjs.map +10 -0
  196. package/dist/cjs/package.json +5 -0
  197. package/dist/cjs/parser/ast.cjs +175 -0
  198. package/dist/cjs/parser/ast.cjs.map +10 -0
  199. package/dist/cjs/parser/formatter.cjs +319 -0
  200. package/dist/cjs/parser/formatter.cjs.map +10 -0
  201. package/dist/cjs/parser/grammar.cjs +375 -0
  202. package/dist/cjs/parser/grammar.cjs.map +10 -0
  203. package/dist/cjs/parser/lexer.cjs +443 -0
  204. package/dist/cjs/parser/lexer.cjs.map +10 -0
  205. package/dist/cjs/parser/parser.cjs +1700 -0
  206. package/dist/cjs/parser/parser.cjs.map +10 -0
  207. package/dist/cjs/react/hooks.cjs +59 -0
  208. package/dist/cjs/react/hooks.cjs.map +10 -0
  209. package/dist/mjs/core/ast-traverser.mjs +94 -0
  210. package/dist/mjs/core/ast-traverser.mjs.map +10 -0
  211. package/dist/mjs/core/autofill-utils.mjs +274 -0
  212. package/dist/mjs/core/autofill-utils.mjs.map +10 -0
  213. package/dist/mjs/core/engine.mjs +366 -0
  214. package/dist/mjs/core/engine.mjs.map +10 -0
  215. package/dist/mjs/core/managers/cache-manager.mjs +27 -0
  216. package/dist/mjs/core/managers/cache-manager.mjs.map +10 -0
  217. package/dist/mjs/core/managers/dependency-manager.mjs +593 -0
  218. package/dist/mjs/core/managers/dependency-manager.mjs.map +10 -0
  219. package/dist/mjs/core/managers/dependency-node.mjs +2 -0
  220. package/dist/mjs/core/managers/dependency-node.mjs.map +9 -0
  221. package/dist/mjs/core/managers/evaluation-manager.mjs +415 -0
  222. package/dist/mjs/core/managers/evaluation-manager.mjs.map +10 -0
  223. package/dist/mjs/core/managers/event-manager.mjs +18 -0
  224. package/dist/mjs/core/managers/event-manager.mjs.map +10 -0
  225. package/dist/mjs/core/managers/frontier-dependency-manager.mjs +151 -0
  226. package/dist/mjs/core/managers/frontier-dependency-manager.mjs.map +10 -0
  227. package/dist/mjs/core/managers/index.mjs +21 -0
  228. package/dist/mjs/core/managers/index.mjs.map +10 -0
  229. package/dist/mjs/core/managers/isDependencyNode.mjs +14 -0
  230. package/dist/mjs/core/managers/isDependencyNode.mjs.map +10 -0
  231. package/dist/mjs/core/managers/named-expression-manager.mjs +348 -0
  232. package/dist/mjs/core/managers/named-expression-manager.mjs.map +10 -0
  233. package/dist/mjs/core/managers/range-eval-order-builder.mjs +618 -0
  234. package/dist/mjs/core/managers/range-eval-order-builder.mjs.map +10 -0
  235. package/dist/mjs/core/managers/table-manager.mjs +224 -0
  236. package/dist/mjs/core/managers/table-manager.mjs.map +10 -0
  237. package/dist/mjs/core/managers/workbook-manager.mjs +447 -0
  238. package/dist/mjs/core/managers/workbook-manager.mjs.map +10 -0
  239. package/dist/mjs/core/map-serializer.mjs +39 -0
  240. package/dist/mjs/core/map-serializer.mjs.map +10 -0
  241. package/dist/mjs/core/named-expression-renamer.mjs +58 -0
  242. package/dist/mjs/core/named-expression-renamer.mjs.map +10 -0
  243. package/dist/mjs/core/sheet-renamer.mjs +59 -0
  244. package/dist/mjs/core/sheet-renamer.mjs.map +10 -0
  245. package/dist/mjs/core/sheet-utils.mjs +8 -0
  246. package/dist/mjs/core/sheet-utils.mjs.map +10 -0
  247. package/dist/mjs/core/table-renamer.mjs +58 -0
  248. package/dist/mjs/core/table-renamer.mjs.map +10 -0
  249. package/dist/mjs/core/types.mjs +18 -0
  250. package/dist/mjs/core/types.mjs.map +10 -0
  251. package/dist/mjs/core/utils/range-serializer.mjs +35 -0
  252. package/dist/mjs/core/utils/range-serializer.mjs.map +10 -0
  253. package/dist/mjs/core/utils/spreadsheet-visualizer.mjs +112 -0
  254. package/dist/mjs/core/utils/spreadsheet-visualizer.mjs.map +10 -0
  255. package/dist/mjs/core/utils.mjs +409 -0
  256. package/dist/mjs/core/utils.mjs.map +10 -0
  257. package/dist/mjs/core/workbook-renamer.mjs +76 -0
  258. package/dist/mjs/core/workbook-renamer.mjs.map +10 -0
  259. package/dist/mjs/debug/flags.mjs +17 -0
  260. package/dist/mjs/debug/flags.mjs.map +10 -0
  261. package/dist/mjs/evaluator/arithmetic/add/add.mjs +52 -0
  262. package/dist/mjs/evaluator/arithmetic/add/add.mjs.map +10 -0
  263. package/dist/mjs/evaluator/arithmetic/divide/divide.mjs +77 -0
  264. package/dist/mjs/evaluator/arithmetic/divide/divide.mjs.map +10 -0
  265. package/dist/mjs/evaluator/arithmetic/multiply/multiply.mjs +63 -0
  266. package/dist/mjs/evaluator/arithmetic/multiply/multiply.mjs.map +10 -0
  267. package/dist/mjs/evaluator/arithmetic/power/power.mjs +95 -0
  268. package/dist/mjs/evaluator/arithmetic/power/power.mjs.map +10 -0
  269. package/dist/mjs/evaluator/arithmetic/subtract/subtract.mjs +54 -0
  270. package/dist/mjs/evaluator/arithmetic/subtract/subtract.mjs.map +10 -0
  271. package/dist/mjs/evaluator/comparison/equals.mjs +34 -0
  272. package/dist/mjs/evaluator/comparison/equals.mjs.map +10 -0
  273. package/dist/mjs/evaluator/comparison/greater-than-or-equal.mjs +31 -0
  274. package/dist/mjs/evaluator/comparison/greater-than-or-equal.mjs.map +10 -0
  275. package/dist/mjs/evaluator/comparison/greater-than.mjs +31 -0
  276. package/dist/mjs/evaluator/comparison/greater-than.mjs.map +10 -0
  277. package/dist/mjs/evaluator/comparison/less-than-or-equal.mjs +39 -0
  278. package/dist/mjs/evaluator/comparison/less-than-or-equal.mjs.map +10 -0
  279. package/dist/mjs/evaluator/comparison/less-than.mjs +38 -0
  280. package/dist/mjs/evaluator/comparison/less-than.mjs.map +10 -0
  281. package/dist/mjs/evaluator/comparison/not-equals.mjs +23 -0
  282. package/dist/mjs/evaluator/comparison/not-equals.mjs.map +10 -0
  283. package/dist/mjs/evaluator/concatenation/concatenate.mjs +42 -0
  284. package/dist/mjs/evaluator/concatenation/concatenate.mjs.map +10 -0
  285. package/dist/mjs/evaluator/dependency-nodes/ast-evaluation-node.mjs +28 -0
  286. package/dist/mjs/evaluator/dependency-nodes/ast-evaluation-node.mjs.map +10 -0
  287. package/dist/mjs/evaluator/dependency-nodes/base-eval-node.mjs +81 -0
  288. package/dist/mjs/evaluator/dependency-nodes/base-eval-node.mjs.map +10 -0
  289. package/dist/mjs/evaluator/dependency-nodes/cell-value-node.mjs +24 -0
  290. package/dist/mjs/evaluator/dependency-nodes/cell-value-node.mjs.map +10 -0
  291. package/dist/mjs/evaluator/dependency-nodes/empty-cell-evaluation-node.mjs +78 -0
  292. package/dist/mjs/evaluator/dependency-nodes/empty-cell-evaluation-node.mjs.map +10 -0
  293. package/dist/mjs/evaluator/dependency-nodes/spill-meta-node.mjs +20 -0
  294. package/dist/mjs/evaluator/dependency-nodes/spill-meta-node.mjs.map +10 -0
  295. package/dist/mjs/evaluator/evaluate-scalar-operator.mjs +226 -0
  296. package/dist/mjs/evaluator/evaluate-scalar-operator.mjs.map +10 -0
  297. package/dist/mjs/evaluator/evaluation-context.mjs +123 -0
  298. package/dist/mjs/evaluator/evaluation-context.mjs.map +10 -0
  299. package/dist/mjs/evaluator/evaluation-error.mjs +44 -0
  300. package/dist/mjs/evaluator/evaluation-error.mjs.map +10 -0
  301. package/dist/mjs/evaluator/formula-evaluator.mjs +780 -0
  302. package/dist/mjs/evaluator/formula-evaluator.mjs.map +10 -0
  303. package/dist/mjs/evaluator/range-evaluation-node.mjs +58 -0
  304. package/dist/mjs/evaluator/range-evaluation-node.mjs.map +10 -0
  305. package/dist/mjs/functions/_template/template.mjs +12 -0
  306. package/dist/mjs/functions/_template/template.mjs.map +10 -0
  307. package/dist/mjs/functions/array/sequence/sequence.mjs +287 -0
  308. package/dist/mjs/functions/array/sequence/sequence.mjs.map +10 -0
  309. package/dist/mjs/functions/criteria-parser.mjs +187 -0
  310. package/dist/mjs/functions/criteria-parser.mjs.map +10 -0
  311. package/dist/mjs/functions/criteria-utils.mjs +268 -0
  312. package/dist/mjs/functions/criteria-utils.mjs.map +10 -0
  313. package/dist/mjs/functions/function-utils.mjs +33 -0
  314. package/dist/mjs/functions/function-utils.mjs.map +10 -0
  315. package/dist/mjs/functions/index.mjs +95 -0
  316. package/dist/mjs/functions/index.mjs.map +10 -0
  317. package/dist/mjs/functions/information/cell/cell.mjs +168 -0
  318. package/dist/mjs/functions/information/cell/cell.mjs.map +10 -0
  319. package/dist/mjs/functions/information/column/column.mjs +120 -0
  320. package/dist/mjs/functions/information/column/column.mjs.map +10 -0
  321. package/dist/mjs/functions/information/row/row.mjs +126 -0
  322. package/dist/mjs/functions/information/row/row.mjs.map +10 -0
  323. package/dist/mjs/functions/logical/and/and.mjs +84 -0
  324. package/dist/mjs/functions/logical/and/and.mjs.map +10 -0
  325. package/dist/mjs/functions/logical/if/if.mjs +167 -0
  326. package/dist/mjs/functions/logical/if/if.mjs.map +10 -0
  327. package/dist/mjs/functions/logical/iferror/iferror.mjs +98 -0
  328. package/dist/mjs/functions/logical/iferror/iferror.mjs.map +10 -0
  329. package/dist/mjs/functions/logical/or/or.mjs +84 -0
  330. package/dist/mjs/functions/logical/or/or.mjs.map +10 -0
  331. package/dist/mjs/functions/lookup/count/count-utils.mjs +35 -0
  332. package/dist/mjs/functions/lookup/count/count-utils.mjs.map +10 -0
  333. package/dist/mjs/functions/lookup/count/count.mjs +18 -0
  334. package/dist/mjs/functions/lookup/count/count.mjs.map +10 -0
  335. package/dist/mjs/functions/lookup/count/countif.mjs +68 -0
  336. package/dist/mjs/functions/lookup/count/countif.mjs.map +10 -0
  337. package/dist/mjs/functions/lookup/count/countifs.mjs +37 -0
  338. package/dist/mjs/functions/lookup/count/countifs.mjs.map +10 -0
  339. package/dist/mjs/functions/lookup/index-lookup/index-lookup.mjs +159 -0
  340. package/dist/mjs/functions/lookup/index-lookup/index-lookup.mjs.map +10 -0
  341. package/dist/mjs/functions/lookup/match/match.mjs +140 -0
  342. package/dist/mjs/functions/lookup/match/match.mjs.map +10 -0
  343. package/dist/mjs/functions/lookup/xlookup/xlookup.mjs +382 -0
  344. package/dist/mjs/functions/lookup/xlookup/xlookup.mjs.map +10 -0
  345. package/dist/mjs/functions/math/average/average-utils.mjs +44 -0
  346. package/dist/mjs/functions/math/average/average-utils.mjs.map +10 -0
  347. package/dist/mjs/functions/math/average/average.mjs +18 -0
  348. package/dist/mjs/functions/math/average/average.mjs.map +10 -0
  349. package/dist/mjs/functions/math/average/averageif.mjs +58 -0
  350. package/dist/mjs/functions/math/average/averageif.mjs.map +10 -0
  351. package/dist/mjs/functions/math/average/averageifs.mjs +35 -0
  352. package/dist/mjs/functions/math/average/averageifs.mjs.map +10 -0
  353. package/dist/mjs/functions/math/ceiling/ceiling.mjs +191 -0
  354. package/dist/mjs/functions/math/ceiling/ceiling.mjs.map +10 -0
  355. package/dist/mjs/functions/math/max/max-utils.mjs +43 -0
  356. package/dist/mjs/functions/math/max/max-utils.mjs.map +10 -0
  357. package/dist/mjs/functions/math/max/max.mjs +18 -0
  358. package/dist/mjs/functions/math/max/max.mjs.map +10 -0
  359. package/dist/mjs/functions/math/max/maxif.mjs +58 -0
  360. package/dist/mjs/functions/math/max/maxif.mjs.map +10 -0
  361. package/dist/mjs/functions/math/max/maxifs.mjs +35 -0
  362. package/dist/mjs/functions/math/max/maxifs.mjs.map +10 -0
  363. package/dist/mjs/functions/math/min/min-utils.mjs +43 -0
  364. package/dist/mjs/functions/math/min/min-utils.mjs.map +10 -0
  365. package/dist/mjs/functions/math/min/min.mjs +18 -0
  366. package/dist/mjs/functions/math/min/min.mjs.map +10 -0
  367. package/dist/mjs/functions/math/min/minif.mjs +58 -0
  368. package/dist/mjs/functions/math/min/minif.mjs.map +10 -0
  369. package/dist/mjs/functions/math/min/minifs.mjs +35 -0
  370. package/dist/mjs/functions/math/min/minifs.mjs.map +10 -0
  371. package/dist/mjs/functions/math/sum/sum.mjs +18 -0
  372. package/dist/mjs/functions/math/sum/sum.mjs.map +10 -0
  373. package/dist/mjs/functions/math/sum/sumif.mjs +58 -0
  374. package/dist/mjs/functions/math/sum/sumif.mjs.map +10 -0
  375. package/dist/mjs/functions/math/sum/sumifs.mjs +34 -0
  376. package/dist/mjs/functions/math/sum/sumifs.mjs.map +10 -0
  377. package/dist/mjs/functions/math/sum/summation-utils.mjs +27 -0
  378. package/dist/mjs/functions/math/sum/summation-utils.mjs.map +10 -0
  379. package/dist/mjs/functions/reference/address/address.mjs +135 -0
  380. package/dist/mjs/functions/reference/address/address.mjs.map +10 -0
  381. package/dist/mjs/functions/reference/indirect/indirect.mjs +74 -0
  382. package/dist/mjs/functions/reference/indirect/indirect.mjs.map +10 -0
  383. package/dist/mjs/functions/reference/offset/offset.mjs +205 -0
  384. package/dist/mjs/functions/reference/offset/offset.mjs.map +10 -0
  385. package/dist/mjs/functions/text/concatenate/concatenate.mjs +139 -0
  386. package/dist/mjs/functions/text/concatenate/concatenate.mjs.map +10 -0
  387. package/dist/mjs/functions/text/exact/exact.mjs +143 -0
  388. package/dist/mjs/functions/text/exact/exact.mjs.map +10 -0
  389. package/dist/mjs/functions/text/find/find.mjs +369 -0
  390. package/dist/mjs/functions/text/find/find.mjs.map +10 -0
  391. package/dist/mjs/functions/text/left/left.mjs +81 -0
  392. package/dist/mjs/functions/text/left/left.mjs.map +10 -0
  393. package/dist/mjs/functions/text/len/len.mjs +91 -0
  394. package/dist/mjs/functions/text/len/len.mjs.map +10 -0
  395. package/dist/mjs/functions/text/mid/mid.mjs +75 -0
  396. package/dist/mjs/functions/text/mid/mid.mjs.map +10 -0
  397. package/dist/mjs/functions/text/right/right.mjs +143 -0
  398. package/dist/mjs/functions/text/right/right.mjs.map +10 -0
  399. package/dist/mjs/functions/text/text-helpers.mjs +151 -0
  400. package/dist/mjs/functions/text/text-helpers.mjs.map +10 -0
  401. package/dist/mjs/functions/text/textjoin/textjoin.mjs +145 -0
  402. package/dist/mjs/functions/text/textjoin/textjoin.mjs.map +10 -0
  403. package/dist/mjs/package.json +5 -0
  404. package/dist/mjs/parser/ast.mjs +145 -0
  405. package/dist/mjs/parser/ast.mjs.map +10 -0
  406. package/dist/mjs/parser/formatter.mjs +289 -0
  407. package/dist/mjs/parser/formatter.mjs.map +10 -0
  408. package/dist/mjs/parser/grammar.mjs +345 -0
  409. package/dist/mjs/parser/grammar.mjs.map +10 -0
  410. package/dist/mjs/parser/lexer.mjs +412 -0
  411. package/dist/mjs/parser/lexer.mjs.map +10 -0
  412. package/dist/mjs/parser/parser.mjs +1692 -0
  413. package/dist/mjs/parser/parser.mjs.map +10 -0
  414. package/dist/mjs/react/hooks.mjs +16 -0
  415. package/dist/mjs/react/hooks.mjs.map +10 -0
  416. package/dist/types/core/ast-traverser.d.ts +28 -0
  417. package/dist/types/core/autofill-utils.d.ts +32 -0
  418. package/dist/types/core/engine.d.ts +184 -0
  419. package/dist/types/core/managers/cache-manager.d.ts +14 -0
  420. package/dist/types/core/managers/dependency-manager.d.ts +147 -0
  421. package/dist/types/core/managers/dependency-node.d.ts +13 -0
  422. package/dist/types/core/managers/evaluation-manager.d.ts +30 -0
  423. package/dist/types/core/managers/event-manager.d.ts +8 -0
  424. package/dist/types/core/managers/frontier-dependency-manager.d.ts +69 -0
  425. package/dist/types/core/managers/index.d.ts +7 -0
  426. package/dist/types/core/managers/isDependencyNode.d.ts +2 -0
  427. package/dist/types/core/managers/named-expression-manager.d.ts +101 -0
  428. package/dist/types/core/managers/range-eval-order-builder.d.ts +33 -0
  429. package/dist/types/core/managers/table-manager.d.ts +84 -0
  430. package/dist/types/core/managers/workbook-manager.d.ts +136 -0
  431. package/dist/types/core/map-serializer.d.ts +4 -0
  432. package/dist/types/core/named-expression-renamer.d.ts +21 -0
  433. package/dist/types/core/sheet-renamer.d.ts +28 -0
  434. package/dist/types/core/sheet-utils.d.ts +2 -0
  435. package/dist/types/core/table-renamer.d.ts +21 -0
  436. package/dist/types/core/types.d.ts +272 -0
  437. package/dist/types/core/utils/cell-address-parsing.test.d.ts +1 -0
  438. package/dist/types/core/utils/range-serializer.d.ts +22 -0
  439. package/dist/types/core/utils/range-serializer.test.d.ts +1 -0
  440. package/dist/types/core/utils/spreadsheet-visualizer.d.ts +30 -0
  441. package/dist/types/core/utils.d.ts +48 -0
  442. package/dist/types/core/workbook-renamer.d.ts +28 -0
  443. package/dist/types/debug/flags.d.ts +11 -0
  444. package/dist/types/evaluator/arithmetic/add/add.d.ts +2 -0
  445. package/dist/types/evaluator/arithmetic/add/add.test.d.ts +1 -0
  446. package/dist/types/evaluator/arithmetic/divide/divide.d.ts +2 -0
  447. package/dist/types/evaluator/arithmetic/divide/divide.test.d.ts +1 -0
  448. package/dist/types/evaluator/arithmetic/multiply/multiply.d.ts +2 -0
  449. package/dist/types/evaluator/arithmetic/multiply/multiply.test.d.ts +1 -0
  450. package/dist/types/evaluator/arithmetic/power/power.d.ts +2 -0
  451. package/dist/types/evaluator/arithmetic/power/power.test.d.ts +1 -0
  452. package/dist/types/evaluator/arithmetic/subtract/subtract.d.ts +2 -0
  453. package/dist/types/evaluator/arithmetic/subtract/subtract.test.d.ts +1 -0
  454. package/dist/types/evaluator/comparison/comparison-operators.test.d.ts +1 -0
  455. package/dist/types/evaluator/comparison/equals.d.ts +6 -0
  456. package/dist/types/evaluator/comparison/greater-than-or-equal.d.ts +6 -0
  457. package/dist/types/evaluator/comparison/greater-than.d.ts +6 -0
  458. package/dist/types/evaluator/comparison/less-than-or-equal.d.ts +6 -0
  459. package/dist/types/evaluator/comparison/less-than.d.ts +6 -0
  460. package/dist/types/evaluator/comparison/not-equals.d.ts +6 -0
  461. package/dist/types/evaluator/concatenation/concatenate.d.ts +6 -0
  462. package/dist/types/evaluator/concatenation/concatenate.test.d.ts +1 -0
  463. package/dist/types/evaluator/dependency-nodes/ast-evaluation-node.d.ts +12 -0
  464. package/dist/types/evaluator/dependency-nodes/base-eval-node.d.ts +31 -0
  465. package/dist/types/evaluator/dependency-nodes/cell-value-node.d.ts +10 -0
  466. package/dist/types/evaluator/dependency-nodes/empty-cell-evaluation-node.d.ts +17 -0
  467. package/dist/types/evaluator/dependency-nodes/spill-meta-node.d.ts +7 -0
  468. package/dist/types/evaluator/evaluate-scalar-operator.d.ts +12 -0
  469. package/dist/types/evaluator/evaluation-context.d.ts +66 -0
  470. package/dist/types/evaluator/evaluation-error.d.ts +20 -0
  471. package/dist/types/evaluator/formula-evaluator.d.ts +67 -0
  472. package/dist/types/evaluator/open-range-evaluator.test.d.ts +1 -0
  473. package/dist/types/evaluator/range-evaluation-node.d.ts +16 -0
  474. package/dist/types/functions/_template/template.d.ts +5 -0
  475. package/dist/types/functions/_template/template.test.d.ts +1 -0
  476. package/dist/types/functions/array/sequence/performance-test.d.ts +1 -0
  477. package/dist/types/functions/array/sequence/sequence.d.ts +14 -0
  478. package/dist/types/functions/array/sequence/sequence.test.d.ts +1 -0
  479. package/dist/types/functions/criteria-parser.d.ts +27 -0
  480. package/dist/types/functions/criteria-utils.d.ts +61 -0
  481. package/dist/types/functions/function-utils.d.ts +21 -0
  482. package/dist/types/functions/index.d.ts +2 -0
  483. package/dist/types/functions/information/cell/cell.d.ts +24 -0
  484. package/dist/types/functions/information/cell/cell.test.d.ts +1 -0
  485. package/dist/types/functions/information/column/column.d.ts +14 -0
  486. package/dist/types/functions/information/column/column.test.d.ts +1 -0
  487. package/dist/types/functions/information/row/row.d.ts +14 -0
  488. package/dist/types/functions/information/row/row.test.d.ts +1 -0
  489. package/dist/types/functions/logical/and/and.d.ts +5 -0
  490. package/dist/types/functions/logical/and/and.test.d.ts +1 -0
  491. package/dist/types/functions/logical/if/if.d.ts +5 -0
  492. package/dist/types/functions/logical/if/if.test.d.ts +1 -0
  493. package/dist/types/functions/logical/iferror/iferror.d.ts +5 -0
  494. package/dist/types/functions/logical/iferror/iferror.test.d.ts +1 -0
  495. package/dist/types/functions/logical/or/or.d.ts +5 -0
  496. package/dist/types/functions/logical/or/or.test.d.ts +1 -0
  497. package/dist/types/functions/lookup/count/count-utils.d.ts +14 -0
  498. package/dist/types/functions/lookup/count/count.d.ts +21 -0
  499. package/dist/types/functions/lookup/count/count.test.d.ts +1 -0
  500. package/dist/types/functions/lookup/count/countif.d.ts +26 -0
  501. package/dist/types/functions/lookup/count/countif.test.d.ts +1 -0
  502. package/dist/types/functions/lookup/count/countifs.d.ts +21 -0
  503. package/dist/types/functions/lookup/count/countifs.test.d.ts +1 -0
  504. package/dist/types/functions/lookup/index-lookup/index-lookup.d.ts +2 -0
  505. package/dist/types/functions/lookup/index-lookup/index-lookup.test.d.ts +1 -0
  506. package/dist/types/functions/lookup/match/match.d.ts +2 -0
  507. package/dist/types/functions/lookup/match/match.test.d.ts +1 -0
  508. package/dist/types/functions/lookup/xlookup/xlookup.d.ts +2 -0
  509. package/dist/types/functions/lookup/xlookup/xlookup.test.d.ts +1 -0
  510. package/dist/types/functions/math/average/average-utils.d.ts +10 -0
  511. package/dist/types/functions/math/average/average.d.ts +18 -0
  512. package/dist/types/functions/math/average/average.test.d.ts +1 -0
  513. package/dist/types/functions/math/average/averageif.d.ts +23 -0
  514. package/dist/types/functions/math/average/averageif.test.d.ts +1 -0
  515. package/dist/types/functions/math/average/averageifs.d.ts +21 -0
  516. package/dist/types/functions/math/average/averageifs.test.d.ts +1 -0
  517. package/dist/types/functions/math/ceiling/ceiling.d.ts +5 -0
  518. package/dist/types/functions/math/ceiling/ceiling.test.d.ts +1 -0
  519. package/dist/types/functions/math/max/max-utils.d.ts +20 -0
  520. package/dist/types/functions/math/max/max.d.ts +18 -0
  521. package/dist/types/functions/math/max/max.test.d.ts +1 -0
  522. package/dist/types/functions/math/max/maxif.d.ts +23 -0
  523. package/dist/types/functions/math/max/maxif.test.d.ts +1 -0
  524. package/dist/types/functions/math/max/maxifs.d.ts +21 -0
  525. package/dist/types/functions/math/max/maxifs.test.d.ts +1 -0
  526. package/dist/types/functions/math/min/min-utils.d.ts +20 -0
  527. package/dist/types/functions/math/min/min.d.ts +5 -0
  528. package/dist/types/functions/math/min/min.test.d.ts +1 -0
  529. package/dist/types/functions/math/min/minif.d.ts +23 -0
  530. package/dist/types/functions/math/min/minif.test.d.ts +1 -0
  531. package/dist/types/functions/math/min/minifs.d.ts +21 -0
  532. package/dist/types/functions/math/min/minifs.test.d.ts +1 -0
  533. package/dist/types/functions/math/sum/sum.d.ts +5 -0
  534. package/dist/types/functions/math/sum/sum.test.d.ts +1 -0
  535. package/dist/types/functions/math/sum/sumif.d.ts +23 -0
  536. package/dist/types/functions/math/sum/sumif.test.d.ts +1 -0
  537. package/dist/types/functions/math/sum/sumifs.d.ts +21 -0
  538. package/dist/types/functions/math/sum/sumifs.test.d.ts +1 -0
  539. package/dist/types/functions/math/sum/summation-utils.d.ts +19 -0
  540. package/dist/types/functions/reference/address/address.d.ts +18 -0
  541. package/dist/types/functions/reference/address/address.test.d.ts +1 -0
  542. package/dist/types/functions/reference/indirect/indirect.d.ts +20 -0
  543. package/dist/types/functions/reference/indirect/indirect.test.d.ts +1 -0
  544. package/dist/types/functions/reference/offset/offset.d.ts +23 -0
  545. package/dist/types/functions/reference/offset/offset.test.d.ts +1 -0
  546. package/dist/types/functions/text/concatenate/concatenate.d.ts +5 -0
  547. package/dist/types/functions/text/concatenate/concatenate.test.d.ts +1 -0
  548. package/dist/types/functions/text/exact/exact.d.ts +5 -0
  549. package/dist/types/functions/text/exact/exact.test.d.ts +1 -0
  550. package/dist/types/functions/text/find/find.d.ts +20 -0
  551. package/dist/types/functions/text/find/find.test.d.ts +1 -0
  552. package/dist/types/functions/text/left/left.d.ts +19 -0
  553. package/dist/types/functions/text/left/left.test.d.ts +1 -0
  554. package/dist/types/functions/text/len/len.d.ts +16 -0
  555. package/dist/types/functions/text/len/len.test.d.ts +1 -0
  556. package/dist/types/functions/text/mid/mid.d.ts +20 -0
  557. package/dist/types/functions/text/mid/mid.test.d.ts +1 -0
  558. package/dist/types/functions/text/right/right.d.ts +2 -0
  559. package/dist/types/functions/text/right/right.test.d.ts +1 -0
  560. package/dist/types/functions/text/text-helpers.d.ts +27 -0
  561. package/dist/types/functions/text/textjoin/textjoin.d.ts +5 -0
  562. package/dist/types/functions/text/textjoin/textjoin.test.d.ts +1 -0
  563. package/dist/types/parser/ast.d.ts +275 -0
  564. package/dist/types/parser/formatter.d.ts +6 -0
  565. package/dist/types/parser/grammar.d.ts +203 -0
  566. package/dist/types/parser/lexer.d.ts +144 -0
  567. package/dist/types/parser/parser.d.ts +159 -0
  568. package/dist/types/react/hooks.d.ts +5 -0
  569. package/package.json +41 -0
@@ -0,0 +1,1700 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/parser/parser.ts
30
+ var exports_parser = {};
31
+ __export(exports_parser, {
32
+ parseFormula: () => parseFormula,
33
+ Parser: () => Parser,
34
+ ParseError: () => ParseError
35
+ });
36
+ module.exports = __toCommonJS(exports_parser);
37
+ var import_utils = require("../core/utils.cjs");
38
+ var import_types = require("../core/types.cjs");
39
+ var import_ast = require("./ast.cjs");
40
+ var import_grammar = require("./grammar.cjs");
41
+ var import_lexer = require("./lexer.cjs");
42
+
43
+ class ParseError extends Error {
44
+ position;
45
+ constructor(message, position) {
46
+ super(message);
47
+ this.position = position;
48
+ this.name = "ParseError";
49
+ }
50
+ }
51
+
52
+ class Parser {
53
+ tokens;
54
+ input;
55
+ constructor(tokens, input) {
56
+ this.tokens = new import_lexer.TokenStream(tokens);
57
+ this.input = input || "";
58
+ }
59
+ lookAheadForWorkbookReference() {
60
+ let pos = 1;
61
+ while (pos < 10) {
62
+ const token = this.tokens.peekAhead(pos);
63
+ if (!token || token.type === "EOF") {
64
+ return { isWorkbookReference: false };
65
+ }
66
+ if (token.type === "RBRACKET") {
67
+ const nextToken = this.tokens.peekAhead(pos + 1);
68
+ if (nextToken && nextToken.type === "IDENTIFIER") {
69
+ let lookPos = pos + 2;
70
+ while (lookPos < pos + 10) {
71
+ const lookToken = this.tokens.peekAhead(lookPos);
72
+ if (!lookToken || lookToken.type === "EOF") {
73
+ return { isWorkbookReference: true };
74
+ }
75
+ if (lookToken.type === "EXCLAMATION") {
76
+ return { isWorkbookReference: true };
77
+ }
78
+ lookPos++;
79
+ }
80
+ }
81
+ return { isWorkbookReference: false };
82
+ }
83
+ if (token.type === "IDENTIFIER" || token.type === "FUNCTION" || token.type === "NUMBER" || token.type === "OPERATOR" && (token.value === "-" || token.value === "=" || token.value === "%") || token.type === "LPAREN" || token.type === "RPAREN") {
84
+ pos++;
85
+ continue;
86
+ }
87
+ return { isWorkbookReference: false };
88
+ }
89
+ return { isWorkbookReference: false };
90
+ }
91
+ parseWorkbookReference() {
92
+ const start = this.tokens.peek().position.start;
93
+ this.tokens.consume();
94
+ const workbookStartPos = this.tokens.peek().position.start;
95
+ let workbookEndPos = workbookStartPos;
96
+ while (!this.tokens.match("RBRACKET")) {
97
+ if (this.tokens.isAtEnd()) {
98
+ throw new ParseError("Expected ] to close workbook reference", this.tokens.peek().position);
99
+ }
100
+ const token = this.tokens.peek();
101
+ if (token.type === "IDENTIFIER" || token.type === "FUNCTION" || token.type === "NUMBER" || token.type === "OPERATOR" && (token.value === "-" || token.value === "=" || token.value === "%") || token.type === "LPAREN" || token.type === "RPAREN") {
102
+ const consumedToken = this.tokens.consume();
103
+ workbookEndPos = consumedToken.position.end;
104
+ } else {
105
+ throw new ParseError(`Invalid character in workbook name: ${token.value}`, token.position);
106
+ }
107
+ }
108
+ const workbookName = this.input.substring(workbookStartPos, workbookEndPos);
109
+ this.tokens.consume();
110
+ if (!this.tokens.match("IDENTIFIER")) {
111
+ throw new ParseError("Expected sheet name after workbook reference", this.tokens.peek().position);
112
+ }
113
+ const sheetToken = this.tokens.consume();
114
+ let sheetName = sheetToken.value;
115
+ if (sheetName.startsWith("'") && sheetName.endsWith("'")) {
116
+ sheetName = sheetName.slice(1, -1).replace(/''/g, "'");
117
+ }
118
+ if (this.tokens.match("COLON")) {
119
+ const nextToken = this.tokens.peekAhead(1);
120
+ const tokenAfterNext = this.tokens.peekAhead(2);
121
+ if (nextToken?.type === "IDENTIFIER" && tokenAfterNext?.type === "EXCLAMATION") {
122
+ this.tokens.consume();
123
+ const endSheetToken = this.tokens.consume();
124
+ let endSheetName = endSheetToken.value;
125
+ if (endSheetName.startsWith("'") && endSheetName.endsWith("'")) {
126
+ endSheetName = endSheetName.slice(1, -1).replace(/''/g, "'");
127
+ }
128
+ this.tokens.consume();
129
+ const ref = this.parseCellOrRangeAfterSheets();
130
+ return import_ast.createThreeDRangeNode(sheetName, endSheetName, ref, {
131
+ start,
132
+ end: this.tokens.peek().position?.end ?? 0
133
+ }, workbookName);
134
+ }
135
+ }
136
+ if (this.tokens.match("EXCLAMATION")) {
137
+ this.tokens.consume();
138
+ const cellRef = this.parseCellOrRangeWithWorkbookAndSheet(workbookName, sheetName, start);
139
+ return cellRef;
140
+ } else {
141
+ const range = {
142
+ start: {
143
+ col: 0,
144
+ row: 0
145
+ },
146
+ end: {
147
+ col: {
148
+ type: "infinity",
149
+ sign: "positive"
150
+ },
151
+ row: {
152
+ type: "infinity",
153
+ sign: "positive"
154
+ }
155
+ }
156
+ };
157
+ return import_ast.createRangeNode({
158
+ workbookName,
159
+ sheetName,
160
+ range,
161
+ isAbsolute: {
162
+ start: { col: false, row: false },
163
+ end: { col: false, row: false }
164
+ },
165
+ position: {
166
+ start,
167
+ end: this.tokens.peek().position?.start ?? 0
168
+ }
169
+ });
170
+ }
171
+ }
172
+ parseBareColumnReference() {
173
+ const startPos = this.tokens.peek().position.start;
174
+ this.tokens.consume();
175
+ let selector;
176
+ let cols;
177
+ let isCurrentRow = false;
178
+ if (this.tokens.match("HASH")) {
179
+ this.tokens.consume();
180
+ if (!this.tokens.match("IDENTIFIER")) {
181
+ throw new ParseError("Expected selector name after #", this.tokens.peek().position);
182
+ }
183
+ const selectorName = this.tokens.consume().value;
184
+ selector = `#${selectorName}`;
185
+ } else if (this.tokens.match("IDENTIFIER")) {
186
+ const colStart = this.parseColumnName();
187
+ if (this.tokens.match("COLON")) {
188
+ this.tokens.consume();
189
+ const colEnd = this.parseColumnName();
190
+ cols = {
191
+ startCol: colStart,
192
+ endCol: colEnd
193
+ };
194
+ } else {
195
+ cols = {
196
+ startCol: colStart,
197
+ endCol: colStart
198
+ };
199
+ }
200
+ } else {
201
+ throw new ParseError("Expected column name or selector in bare column reference", this.tokens.peek().position);
202
+ }
203
+ if (!this.tokens.match("RBRACKET")) {
204
+ throw new ParseError("Expected ] to close column reference", this.tokens.peek().position);
205
+ }
206
+ this.tokens.consume();
207
+ return import_ast.createStructuredReferenceNode({
208
+ tableName: undefined,
209
+ cols,
210
+ selector,
211
+ isCurrentRow,
212
+ position: {
213
+ start: startPos,
214
+ end: this.tokens.peek().position?.end ?? 0
215
+ }
216
+ });
217
+ }
218
+ parseColumnName() {
219
+ if (!this.tokens.match("IDENTIFIER") && !this.tokens.match("FUNCTION") && !this.tokens.match("NUMBER") && !this.tokens.match("OPERATOR")) {
220
+ throw new ParseError("Expected column name", this.tokens.peek().position);
221
+ }
222
+ const startToken = this.tokens.peek();
223
+ const startPos = startToken.position.start;
224
+ this.tokens.consume();
225
+ const endTokens = new Set([
226
+ "RBRACKET",
227
+ "COMMA",
228
+ "EOF"
229
+ ]);
230
+ while (!endTokens.has(this.tokens.peek().type)) {
231
+ if (this.tokens.match("OPERATOR")) {
232
+ this.tokens.consume();
233
+ } else {
234
+ this.tokens.consume();
235
+ }
236
+ }
237
+ const currentPos = this.tokens.getPosition();
238
+ let endPos = currentPos > 0 ? this.tokens.getTokens()[currentPos - 1]?.position?.end || startPos : startPos;
239
+ if (this.tokens.match("RBRACKET")) {
240
+ const nextTokenPos = this.tokens.peek().position.start;
241
+ endPos = nextTokenPos;
242
+ }
243
+ const columnName = this.input.substring(startPos, endPos);
244
+ return columnName;
245
+ }
246
+ static parse(formula) {
247
+ const lexer = new import_lexer.Lexer(formula);
248
+ const tokens = lexer.tokenize();
249
+ const parser = new Parser(tokens, formula);
250
+ return parser.parseFormula();
251
+ }
252
+ parseFormula() {
253
+ if (this.tokens.isAtEnd()) {
254
+ return import_ast.createEmptyNode();
255
+ }
256
+ if (this.tokens.peek().type === "EOF") {
257
+ return import_ast.createErrorNode(import_types.FormulaError.ERROR, "Empty formula");
258
+ }
259
+ try {
260
+ const expr = this.parseExpression();
261
+ if (!this.tokens.isAtEnd()) {
262
+ throw new ParseError(`Unexpected token: ${this.tokens.peek().value}`, this.tokens.peek().position);
263
+ }
264
+ return expr;
265
+ } catch (error) {
266
+ if (error instanceof ParseError) {
267
+ throw error;
268
+ }
269
+ throw new ParseError(String(error));
270
+ }
271
+ }
272
+ parseExpression() {
273
+ return this.parseBinaryExpression(0);
274
+ }
275
+ parseBinaryExpression(minPrecedence) {
276
+ let left = this.parseUnaryExpression();
277
+ while (true) {
278
+ const token = this.tokens.peek();
279
+ if (token.type !== "OPERATOR" || !import_grammar.isBinaryOperator(token.value)) {
280
+ break;
281
+ }
282
+ const precedence = import_grammar.getOperatorPrecedence(token.value);
283
+ if (precedence < minPrecedence) {
284
+ break;
285
+ }
286
+ const operator = token.value;
287
+ const associativity = import_grammar.getOperatorAssociativity(operator);
288
+ const start = token.position.start;
289
+ this.tokens.consume();
290
+ const nextMinPrecedence = associativity === "right" ? precedence : precedence + 1;
291
+ const right = this.parseBinaryExpression(nextMinPrecedence);
292
+ left = import_ast.createBinaryOpNode(operator, left, right, right.position?.end ? {
293
+ start,
294
+ end: right.position.end
295
+ } : undefined);
296
+ }
297
+ return left;
298
+ }
299
+ parseUnaryExpression() {
300
+ const token = this.tokens.peek();
301
+ if (token.type === "OPERATOR" && (token.value === "+" || token.value === "-")) {
302
+ const start = token.position.start;
303
+ const operator = token.value;
304
+ this.tokens.consume();
305
+ const operand = this.parseUnaryExpression();
306
+ return import_ast.createUnaryOpNode(operator, operand, operand.position ? {
307
+ start,
308
+ end: operand.position.end
309
+ } : undefined);
310
+ }
311
+ return this.parsePostfixExpression();
312
+ }
313
+ parsePostfixExpression() {
314
+ let expr = this.parsePrimaryExpression();
315
+ if (this.tokens.match("OPERATOR") && this.tokens.peek().value === "%") {
316
+ const token = this.tokens.consume();
317
+ expr = import_ast.createUnaryOpNode("%", expr, expr.position ? {
318
+ start: expr.position.start,
319
+ end: token.position.end
320
+ } : undefined);
321
+ }
322
+ return expr;
323
+ }
324
+ parsePrimaryExpression() {
325
+ const token = this.tokens.peek();
326
+ const start = token.position.start;
327
+ switch (token.type) {
328
+ case "NUMBER":
329
+ return this.parseNumber();
330
+ case "STRING":
331
+ return this.parseString();
332
+ case "BOOLEAN":
333
+ return this.parseBoolean();
334
+ case "ERROR":
335
+ return this.parseError();
336
+ case "FUNCTION":
337
+ return this.parseFunctionCall();
338
+ case "IDENTIFIER":
339
+ return this.parseIdentifier();
340
+ case "INFINITY":
341
+ const infinityToken = this.tokens.consume();
342
+ return import_ast.createInfinityNode(infinityToken.position);
343
+ case "AT":
344
+ return this.parseCurrentRowReference();
345
+ case "HASH":
346
+ return this.parseTableSelector();
347
+ case "DOLLAR":
348
+ return this.parseAbsoluteReference();
349
+ case "LPAREN":
350
+ return this.parseParenthesizedExpression();
351
+ case "LBRACE":
352
+ return this.parseArrayLiteral();
353
+ case "LBRACKET":
354
+ if (this.tokens.peekAhead(1)?.type === "AT") {
355
+ return this.parseCurrentRowReference();
356
+ } else if (this.tokens.peekAhead(1)?.type === "IDENTIFIER" || this.tokens.peekAhead(1)?.type === "FUNCTION" || this.tokens.peekAhead(1)?.type === "NUMBER" || this.tokens.peekAhead(1)?.type === "HASH") {
357
+ const lookahead = this.lookAheadForWorkbookReference();
358
+ if (lookahead.isWorkbookReference) {
359
+ return this.parseWorkbookReference();
360
+ }
361
+ return this.parseBareColumnReference();
362
+ }
363
+ throw new ParseError(`Unexpected bracket: ${token.value}`, token.position);
364
+ default:
365
+ throw new ParseError(`Unexpected token: ${token.value}`, token.position);
366
+ }
367
+ }
368
+ parseAbsoluteReference() {
369
+ const start = this.tokens.peek().position.start;
370
+ let ref = "";
371
+ ref += this.tokens.consume().value;
372
+ if (this.tokens.match("IDENTIFIER")) {
373
+ const identifier = this.tokens.consume().value;
374
+ const match = identifier.match(/^([A-Z]+)(\d+)$/i);
375
+ if (match) {
376
+ ref += identifier;
377
+ } else if (/^[A-Z]+$/i.test(identifier)) {
378
+ ref += identifier;
379
+ if (this.tokens.match("DOLLAR")) {
380
+ ref += this.tokens.consume().value;
381
+ }
382
+ if (this.tokens.match("NUMBER")) {
383
+ ref += this.tokens.consume().value;
384
+ } else if (!this.tokens.match("COLON")) {
385
+ throw new ParseError("Expected row number", this.tokens.peek().position);
386
+ }
387
+ } else {
388
+ throw new ParseError("Invalid cell reference format", this.tokens.peek().position);
389
+ }
390
+ } else if (this.tokens.match("NUMBER")) {
391
+ const number = this.tokens.consume().value;
392
+ ref += number;
393
+ } else {
394
+ throw new ParseError("Expected column letter or row number after $", this.tokens.peek().position);
395
+ }
396
+ if (this.tokens.match("COLON")) {
397
+ this.tokens.consume();
398
+ const endRef = this.parseRangeEnd();
399
+ return this.parseRange(ref, endRef, start, this.tokens.peek().position.start);
400
+ }
401
+ const cellRef = this.parseCellReferenceString(ref);
402
+ if (cellRef) {
403
+ return cellRef;
404
+ }
405
+ throw new ParseError(`Invalid cell reference: ${ref}`, {
406
+ start,
407
+ end: this.tokens.peek().position.start
408
+ });
409
+ }
410
+ parseNumber() {
411
+ const token = this.tokens.peek();
412
+ const start = token.position.start;
413
+ if (this.tokens.peekNext() && this.tokens.peekNext().type === "COLON") {
414
+ const startRow = this.tokens.consume().value;
415
+ this.tokens.consume();
416
+ let endRow = "";
417
+ if (this.tokens.match("DOLLAR")) {
418
+ endRow += this.tokens.consume().value;
419
+ }
420
+ if (this.tokens.match("NUMBER")) {
421
+ endRow += this.tokens.consume().value;
422
+ } else {
423
+ throw new ParseError("Expected row number after :", this.tokens.peek().position);
424
+ }
425
+ return this.parseRange(startRow, endRow, start, this.tokens.peek().position.start);
426
+ }
427
+ this.tokens.consume();
428
+ const value = parseFloat(token.value);
429
+ if (isNaN(value)) {
430
+ throw new ParseError(`Invalid number: ${token.value}`, token.position);
431
+ }
432
+ return import_ast.createValueNode({
433
+ type: "number",
434
+ value
435
+ }, {
436
+ start: token.position.start,
437
+ end: token.position.end
438
+ });
439
+ }
440
+ parseString() {
441
+ const token = this.tokens.consume();
442
+ return import_ast.createValueNode({
443
+ type: "string",
444
+ value: token.value
445
+ }, {
446
+ start: token.position.start,
447
+ end: token.position.end
448
+ });
449
+ }
450
+ parseBoolean() {
451
+ const token = this.tokens.consume();
452
+ const value = token.value.toUpperCase() === "TRUE";
453
+ return import_ast.createValueNode({
454
+ type: "boolean",
455
+ value
456
+ }, {
457
+ start: token.position.start,
458
+ end: token.position.end
459
+ });
460
+ }
461
+ parseError() {
462
+ const token = this.tokens.consume();
463
+ const error = token.value;
464
+ return import_ast.createErrorNode(error, `Error literal: ${error}`, {
465
+ start: token.position.start,
466
+ end: token.position.end
467
+ });
468
+ }
469
+ parseFunctionCall() {
470
+ const nameToken = this.tokens.consume();
471
+ const functionName = nameToken.value;
472
+ const start = nameToken.position.start;
473
+ if (import_grammar.SPECIAL_FUNCTIONS.has(functionName.toUpperCase()) && !this.tokens.match("LPAREN")) {
474
+ return import_ast.createFunctionNode(functionName, [], {
475
+ start,
476
+ end: nameToken.position.end
477
+ });
478
+ }
479
+ if (!this.tokens.match("LPAREN")) {
480
+ throw new ParseError(`Expected '(' after function name ${functionName}`, this.tokens.peek().position);
481
+ }
482
+ this.tokens.consume();
483
+ const args = [];
484
+ if (this.tokens.match("RPAREN")) {
485
+ const rparenToken = this.tokens.consume();
486
+ const endPos = rparenToken.position.end;
487
+ const node = import_ast.createFunctionNode(functionName, args, {
488
+ start,
489
+ end: endPos
490
+ });
491
+ return node;
492
+ }
493
+ while (true) {
494
+ args.push(this.parseExpression());
495
+ if (this.tokens.match("COMMA")) {
496
+ this.tokens.consume();
497
+ } else if (this.tokens.match("RPAREN")) {
498
+ const rparenToken = this.tokens.consume();
499
+ const end = rparenToken.position.end;
500
+ const node = import_ast.createFunctionNode(functionName, args, {
501
+ start,
502
+ end
503
+ });
504
+ return node;
505
+ } else {
506
+ throw new ParseError(`Expected ',' or ')' in function arguments`, this.tokens.peek().position);
507
+ }
508
+ }
509
+ throw new ParseError("Unexpected end of function argument parsing", this.tokens.peek().position);
510
+ }
511
+ parseIdentifier() {
512
+ const start = this.tokens.peek().position.start;
513
+ const token = this.tokens.consume();
514
+ let value = token.value;
515
+ if (this.tokens.match("COLON")) {
516
+ const colonPos = this.tokens.getPosition();
517
+ const nextToken = this.tokens.peekAhead(1);
518
+ const tokenAfterNext = this.tokens.peekAhead(2);
519
+ if (nextToken?.type === "IDENTIFIER" && tokenAfterNext?.type === "EXCLAMATION") {
520
+ this.tokens.consume();
521
+ const endSheetToken = this.tokens.consume();
522
+ const endSheet = endSheetToken.value;
523
+ this.tokens.consume();
524
+ let startSheet = value;
525
+ if (startSheet.startsWith("'") && startSheet.endsWith("'")) {
526
+ startSheet = startSheet.slice(1, -1).replace(/''/g, "'");
527
+ }
528
+ let endSheetName = endSheet;
529
+ if (endSheetName.startsWith("'") && endSheetName.endsWith("'")) {
530
+ endSheetName = endSheetName.slice(1, -1).replace(/''/g, "'");
531
+ }
532
+ const ref = this.parseCellOrRangeAfterSheets();
533
+ return import_ast.createThreeDRangeNode(startSheet, endSheetName, ref, {
534
+ start,
535
+ end: this.tokens.peek().position?.end ?? 0
536
+ });
537
+ }
538
+ }
539
+ if (this.tokens.match("EXCLAMATION")) {
540
+ this.tokens.consume();
541
+ let sheetName = value;
542
+ if (sheetName.startsWith("'") && sheetName.endsWith("'")) {
543
+ sheetName = sheetName.slice(1, -1).replace(/''/g, "'");
544
+ }
545
+ const cellRef = this.parseCellOrRangeWithSheet(sheetName, start);
546
+ return cellRef;
547
+ }
548
+ if (this.tokens.match("LBRACKET")) {
549
+ return this.parseTableReference(value, start);
550
+ }
551
+ if (this.tokens.match("DOLLAR") && this.isColumnIdentifier(value)) {
552
+ value += this.tokens.consume().value;
553
+ if (this.tokens.match("NUMBER")) {
554
+ value += this.tokens.consume().value;
555
+ } else {
556
+ throw new ParseError("Expected row number after $", this.tokens.peek().position);
557
+ }
558
+ } else if (this.tokens.match("NUMBER") && this.isColumnIdentifier(value)) {
559
+ value += this.tokens.consume().value;
560
+ }
561
+ if (this.tokens.match("COLON")) {
562
+ this.tokens.consume();
563
+ const endStart = this.tokens.peek().position.start;
564
+ const endRef = this.parseRangeEnd();
565
+ const endPos = this.tokens.peek().position.start;
566
+ return this.parseRange(value, endRef, start, endPos);
567
+ }
568
+ const parsedCellRef = this.parseCellReferenceString(value);
569
+ if (parsedCellRef) {
570
+ return parsedCellRef;
571
+ }
572
+ return import_ast.createNamedExpressionNode(value, {
573
+ start,
574
+ end: token.position.end
575
+ });
576
+ }
577
+ isColumnIdentifier(str) {
578
+ return /^[A-Z]+$/i.test(str);
579
+ }
580
+ parseRangeEnd() {
581
+ let result = "";
582
+ if (this.tokens.match("INFINITY")) {
583
+ result += this.tokens.consume().value;
584
+ return result;
585
+ }
586
+ if (this.tokens.match("DOLLAR")) {
587
+ result += this.tokens.consume().value;
588
+ }
589
+ if (this.tokens.match("IDENTIFIER")) {
590
+ result += this.tokens.consume().value;
591
+ if (this.tokens.match("DOLLAR")) {
592
+ result += this.tokens.consume().value;
593
+ }
594
+ if (this.tokens.match("NUMBER")) {
595
+ result += this.tokens.consume().value;
596
+ }
597
+ } else if (this.tokens.match("NUMBER")) {
598
+ result += this.tokens.consume().value;
599
+ } else {
600
+ throw new ParseError("Expected cell reference, column, row, or INFINITY after :", this.tokens.peek().position);
601
+ }
602
+ return result;
603
+ }
604
+ parseParenthesizedExpression() {
605
+ const start = this.tokens.peek().position.start;
606
+ this.tokens.consume();
607
+ const expr = this.parseExpression();
608
+ if (!this.tokens.match("RPAREN")) {
609
+ throw new ParseError(`Expected ')'`, this.tokens.peek().position);
610
+ }
611
+ const end = this.tokens.peek().position.end;
612
+ this.tokens.consume();
613
+ if (expr.position) {
614
+ expr.position.start = start;
615
+ expr.position.end = end;
616
+ }
617
+ return expr;
618
+ }
619
+ parseArrayLiteral() {
620
+ const start = this.tokens.peek().position.start;
621
+ this.tokens.consume();
622
+ const rows = [];
623
+ let currentRow = [];
624
+ if (this.tokens.match("RBRACE")) {
625
+ this.tokens.consume();
626
+ return import_ast.createArrayNode([[import_ast.createEmptyNode()]], {
627
+ start,
628
+ end: this.tokens.peek().position.start
629
+ });
630
+ }
631
+ while (true) {
632
+ currentRow.push(this.parseExpression());
633
+ if (this.tokens.match("COMMA")) {
634
+ this.tokens.consume();
635
+ } else if (this.tokens.match("SEMICOLON")) {
636
+ this.tokens.consume();
637
+ rows.push(currentRow);
638
+ currentRow = [];
639
+ } else if (this.tokens.match("RBRACE")) {
640
+ this.tokens.consume();
641
+ rows.push(currentRow);
642
+ break;
643
+ } else {
644
+ throw new ParseError(`Expected ',', ';', or '}' in array literal`, this.tokens.peek().position);
645
+ }
646
+ }
647
+ if (rows.length > 0 && rows[0]) {
648
+ const rowLength = rows[0].length;
649
+ for (let i = 1;i < rows.length; i++) {
650
+ const row = rows[i];
651
+ if (row && row.length !== rowLength) {
652
+ throw new ParseError(`Inconsistent row lengths in array literal`, {
653
+ start,
654
+ end: this.tokens.peek().position.start
655
+ });
656
+ }
657
+ }
658
+ }
659
+ return import_ast.createArrayNode(rows, {
660
+ start,
661
+ end: this.tokens.peek().position.start
662
+ });
663
+ }
664
+ parseCellReferenceString(value) {
665
+ const parsed = import_grammar.parseCellReference(value);
666
+ if (!parsed) {
667
+ return null;
668
+ }
669
+ const colNum = import_utils.columnToIndex(parsed.col);
670
+ const rowNum = parseInt(parsed.row) - 1;
671
+ if (colNum < 0 || rowNum < 0) {
672
+ return null;
673
+ }
674
+ return import_ast.createReferenceNode({
675
+ address: {
676
+ colIndex: colNum,
677
+ rowIndex: rowNum
678
+ },
679
+ isAbsolute: {
680
+ col: parsed.colAbsolute,
681
+ row: parsed.rowAbsolute
682
+ },
683
+ sheetName: parsed.sheet
684
+ });
685
+ }
686
+ parseTableReference(tableName, startPos) {
687
+ this.tokens.consume();
688
+ let selector;
689
+ let cols;
690
+ let isCurrentRow = false;
691
+ if (this.tokens.match("LBRACKET")) {
692
+ this.tokens.consume();
693
+ if (this.tokens.match("HASH")) {
694
+ this.tokens.consume();
695
+ if (!this.tokens.match("IDENTIFIER")) {
696
+ throw new ParseError("Expected selector name after #", this.tokens.peek().position);
697
+ }
698
+ const selectorName = this.tokens.consume().value;
699
+ selector = `#${selectorName}`;
700
+ if (!this.tokens.match("RBRACKET")) {
701
+ throw new ParseError("Expected ] after selector", this.tokens.peek().position);
702
+ }
703
+ this.tokens.consume();
704
+ if (this.tokens.match("COMMA")) {
705
+ this.tokens.consume();
706
+ if (!this.tokens.match("LBRACKET")) {
707
+ throw new ParseError("Expected [ after comma", this.tokens.peek().position);
708
+ }
709
+ this.tokens.consume();
710
+ if (!this.tokens.match("IDENTIFIER") && !this.tokens.match("FUNCTION") && !this.tokens.match("NUMBER") && !this.tokens.match("OPERATOR")) {
711
+ throw new ParseError("Expected column name", this.tokens.peek().position);
712
+ }
713
+ const colStart = this.parseColumnName();
714
+ if (this.tokens.match("COLON") && !this.tokens.peekAhead(1)?.type.match(/RBRACKET/)) {
715
+ this.tokens.consume();
716
+ if (!this.tokens.match("IDENTIFIER") && !this.tokens.match("FUNCTION") && !this.tokens.match("NUMBER") && !this.tokens.match("OPERATOR")) {
717
+ throw new ParseError("Expected end column name after :", this.tokens.peek().position);
718
+ }
719
+ const colEnd = this.parseColumnName();
720
+ cols = {
721
+ startCol: colStart,
722
+ endCol: colEnd
723
+ };
724
+ } else {
725
+ cols = {
726
+ startCol: colStart,
727
+ endCol: colStart
728
+ };
729
+ }
730
+ if (!this.tokens.match("RBRACKET")) {
731
+ throw new ParseError("Expected ] after column specification", this.tokens.peek().position);
732
+ }
733
+ this.tokens.consume();
734
+ if (this.tokens.match("COLON")) {
735
+ this.tokens.consume();
736
+ if (!this.tokens.match("LBRACKET")) {
737
+ throw new ParseError("Expected [ after : in column range", this.tokens.peek().position);
738
+ }
739
+ this.tokens.consume();
740
+ if (!this.tokens.match("IDENTIFIER") && !this.tokens.match("FUNCTION") && !this.tokens.match("NUMBER") && !this.tokens.match("OPERATOR")) {
741
+ throw new ParseError("Expected end column name", this.tokens.peek().position);
742
+ }
743
+ const colEnd = this.parseColumnName();
744
+ if (!this.tokens.match("RBRACKET")) {
745
+ throw new ParseError("Expected ] after end column name", this.tokens.peek().position);
746
+ }
747
+ this.tokens.consume();
748
+ cols = {
749
+ startCol: colStart,
750
+ endCol: colEnd
751
+ };
752
+ }
753
+ }
754
+ if (!this.tokens.match("RBRACKET")) {
755
+ throw new ParseError("Expected ] to close table reference", this.tokens.peek().position);
756
+ }
757
+ this.tokens.consume();
758
+ } else if (this.tokens.match("IDENTIFIER") || this.tokens.match("FUNCTION") || this.tokens.match("NUMBER") || this.tokens.match("OPERATOR")) {
759
+ const colStart = this.parseColumnName();
760
+ if (!this.tokens.match("RBRACKET")) {
761
+ throw new ParseError("Expected ] after column name", this.tokens.peek().position);
762
+ }
763
+ this.tokens.consume();
764
+ if (this.tokens.match("COLON")) {
765
+ this.tokens.consume();
766
+ if (!this.tokens.match("LBRACKET")) {
767
+ throw new ParseError("Expected [ before second column name", this.tokens.peek().position);
768
+ }
769
+ this.tokens.consume();
770
+ const colEnd = this.parseColumnName();
771
+ if (!this.tokens.match("RBRACKET")) {
772
+ throw new ParseError("Expected ] after second column name", this.tokens.peek().position);
773
+ }
774
+ this.tokens.consume();
775
+ if (!this.tokens.match("RBRACKET")) {
776
+ throw new ParseError("Expected ] to close table reference", this.tokens.peek().position);
777
+ }
778
+ this.tokens.consume();
779
+ cols = {
780
+ startCol: colStart,
781
+ endCol: colEnd
782
+ };
783
+ } else {
784
+ if (!this.tokens.match("RBRACKET")) {
785
+ throw new ParseError("Expected ] to close table reference", this.tokens.peek().position);
786
+ }
787
+ this.tokens.consume();
788
+ cols = {
789
+ startCol: colStart,
790
+ endCol: colStart
791
+ };
792
+ }
793
+ }
794
+ } else if (this.tokens.match("AT")) {
795
+ this.tokens.consume();
796
+ isCurrentRow = true;
797
+ if (this.tokens.match("LBRACKET")) {
798
+ this.tokens.consume();
799
+ const colStart = this.parseColumnName();
800
+ if (!this.tokens.match("RBRACKET")) {
801
+ throw new ParseError("Expected ] after column name", this.tokens.peek().position);
802
+ }
803
+ this.tokens.consume();
804
+ if (this.tokens.match("COLON")) {
805
+ this.tokens.consume();
806
+ if (!this.tokens.match("LBRACKET")) {
807
+ throw new ParseError("Expected [ before second column name", this.tokens.peek().position);
808
+ }
809
+ this.tokens.consume();
810
+ const colEnd = this.parseColumnName();
811
+ if (!this.tokens.match("RBRACKET")) {
812
+ throw new ParseError("Expected ] after second column name", this.tokens.peek().position);
813
+ }
814
+ this.tokens.consume();
815
+ cols = {
816
+ startCol: colStart,
817
+ endCol: colEnd
818
+ };
819
+ } else {
820
+ cols = {
821
+ startCol: colStart,
822
+ endCol: colStart
823
+ };
824
+ }
825
+ if (!this.tokens.match("RBRACKET")) {
826
+ throw new ParseError("Expected ] to close table reference", this.tokens.peek().position);
827
+ }
828
+ this.tokens.consume();
829
+ } else {
830
+ const colStart = this.parseColumnName();
831
+ if (this.tokens.match("COLON")) {
832
+ this.tokens.consume();
833
+ const colEnd = this.parseColumnName();
834
+ cols = {
835
+ startCol: colStart,
836
+ endCol: colEnd
837
+ };
838
+ } else {
839
+ cols = {
840
+ startCol: colStart,
841
+ endCol: colStart
842
+ };
843
+ }
844
+ if (!this.tokens.match("RBRACKET")) {
845
+ throw new ParseError("Expected ] after column reference", this.tokens.peek().position);
846
+ }
847
+ this.tokens.consume();
848
+ }
849
+ } else if (this.tokens.match("IDENTIFIER") || this.tokens.match("FUNCTION") || this.tokens.match("NUMBER") || this.tokens.match("OPERATOR")) {
850
+ const colStart = this.parseColumnName();
851
+ if (this.tokens.match("COLON")) {
852
+ this.tokens.consume();
853
+ const colEnd = this.parseColumnName();
854
+ cols = {
855
+ startCol: colStart,
856
+ endCol: colEnd
857
+ };
858
+ } else {
859
+ cols = {
860
+ startCol: colStart,
861
+ endCol: colStart
862
+ };
863
+ }
864
+ if (!this.tokens.match("RBRACKET")) {
865
+ throw new ParseError("Expected ] after column name", this.tokens.peek().position);
866
+ }
867
+ this.tokens.consume();
868
+ } else if (this.tokens.match("HASH")) {
869
+ this.tokens.consume();
870
+ if (!this.tokens.match("IDENTIFIER")) {
871
+ throw new ParseError("Expected selector name after #", this.tokens.peek().position);
872
+ }
873
+ const selectorName = this.tokens.consume().value;
874
+ selector = `#${selectorName}`;
875
+ if (!this.tokens.match("RBRACKET")) {
876
+ throw new ParseError("Expected ] after selector", this.tokens.peek().position);
877
+ }
878
+ this.tokens.consume();
879
+ } else {
880
+ throw new ParseError("Expected column name or selector in table reference", this.tokens.peek().position);
881
+ }
882
+ return import_ast.createStructuredReferenceNode({
883
+ tableName,
884
+ cols,
885
+ selector,
886
+ isCurrentRow,
887
+ position: {
888
+ start: startPos,
889
+ end: this.tokens.peek().position?.end ?? 0
890
+ }
891
+ });
892
+ }
893
+ parseTableReferenceWithSheet(tableName, sheetName, startPos) {
894
+ this.tokens.consume();
895
+ let selector;
896
+ let cols;
897
+ let isCurrentRow = false;
898
+ if (this.tokens.match("LBRACKET")) {
899
+ this.tokens.consume();
900
+ if (this.tokens.match("HASH")) {
901
+ this.tokens.consume();
902
+ if (!this.tokens.match("IDENTIFIER")) {
903
+ throw new ParseError("Expected selector name after #", this.tokens.peek().position);
904
+ }
905
+ const selectorName = this.tokens.consume().value;
906
+ selector = `#${selectorName}`;
907
+ if (!this.tokens.match("RBRACKET")) {
908
+ throw new ParseError("Expected ] after selector", this.tokens.peek().position);
909
+ }
910
+ this.tokens.consume();
911
+ if (this.tokens.match("COMMA")) {
912
+ this.tokens.consume();
913
+ if (!this.tokens.match("LBRACKET")) {
914
+ throw new ParseError("Expected [ after comma", this.tokens.peek().position);
915
+ }
916
+ this.tokens.consume();
917
+ if (!this.tokens.match("IDENTIFIER") && !this.tokens.match("FUNCTION") && !this.tokens.match("NUMBER") && !this.tokens.match("OPERATOR")) {
918
+ throw new ParseError("Expected column name", this.tokens.peek().position);
919
+ }
920
+ const colStart = this.parseColumnName();
921
+ if (this.tokens.match("COLON") && !this.tokens.peekAhead(1)?.type.match(/RBRACKET/)) {
922
+ this.tokens.consume();
923
+ if (!this.tokens.match("IDENTIFIER") && !this.tokens.match("FUNCTION") && !this.tokens.match("NUMBER") && !this.tokens.match("OPERATOR")) {
924
+ throw new ParseError("Expected end column name after :", this.tokens.peek().position);
925
+ }
926
+ const colEnd = this.parseColumnName();
927
+ cols = {
928
+ startCol: colStart,
929
+ endCol: colEnd
930
+ };
931
+ } else {
932
+ cols = {
933
+ startCol: colStart,
934
+ endCol: colStart
935
+ };
936
+ }
937
+ if (!this.tokens.match("RBRACKET")) {
938
+ throw new ParseError("Expected ] after column specification", this.tokens.peek().position);
939
+ }
940
+ this.tokens.consume();
941
+ if (this.tokens.match("COLON")) {
942
+ this.tokens.consume();
943
+ if (!this.tokens.match("LBRACKET")) {
944
+ throw new ParseError("Expected [ after : in column range", this.tokens.peek().position);
945
+ }
946
+ this.tokens.consume();
947
+ if (!this.tokens.match("IDENTIFIER") && !this.tokens.match("FUNCTION") && !this.tokens.match("NUMBER") && !this.tokens.match("OPERATOR")) {
948
+ throw new ParseError("Expected end column name", this.tokens.peek().position);
949
+ }
950
+ const colEnd = this.parseColumnName();
951
+ if (!this.tokens.match("RBRACKET")) {
952
+ throw new ParseError("Expected ] after end column name", this.tokens.peek().position);
953
+ }
954
+ this.tokens.consume();
955
+ cols = {
956
+ startCol: colStart,
957
+ endCol: colEnd
958
+ };
959
+ }
960
+ }
961
+ if (!this.tokens.match("RBRACKET")) {
962
+ throw new ParseError("Expected ] to close table reference", this.tokens.peek().position);
963
+ }
964
+ this.tokens.consume();
965
+ } else if (this.tokens.match("IDENTIFIER") || this.tokens.match("FUNCTION") || this.tokens.match("NUMBER") || this.tokens.match("OPERATOR")) {
966
+ const colStart = this.parseColumnName();
967
+ if (!this.tokens.match("RBRACKET")) {
968
+ throw new ParseError("Expected ] after column name", this.tokens.peek().position);
969
+ }
970
+ this.tokens.consume();
971
+ if (this.tokens.match("COLON")) {
972
+ this.tokens.consume();
973
+ if (!this.tokens.match("LBRACKET")) {
974
+ throw new ParseError("Expected [ before second column name", this.tokens.peek().position);
975
+ }
976
+ this.tokens.consume();
977
+ const colEnd = this.parseColumnName();
978
+ if (!this.tokens.match("RBRACKET")) {
979
+ throw new ParseError("Expected ] after second column name", this.tokens.peek().position);
980
+ }
981
+ this.tokens.consume();
982
+ if (!this.tokens.match("RBRACKET")) {
983
+ throw new ParseError("Expected ] to close table reference", this.tokens.peek().position);
984
+ }
985
+ this.tokens.consume();
986
+ cols = {
987
+ startCol: colStart,
988
+ endCol: colEnd
989
+ };
990
+ } else {
991
+ if (!this.tokens.match("RBRACKET")) {
992
+ throw new ParseError("Expected ] to close table reference", this.tokens.peek().position);
993
+ }
994
+ this.tokens.consume();
995
+ cols = {
996
+ startCol: colStart,
997
+ endCol: colStart
998
+ };
999
+ }
1000
+ }
1001
+ } else if (this.tokens.match("AT")) {
1002
+ this.tokens.consume();
1003
+ isCurrentRow = true;
1004
+ if (this.tokens.match("LBRACKET")) {
1005
+ this.tokens.consume();
1006
+ const colStart = this.parseColumnName();
1007
+ if (!this.tokens.match("RBRACKET")) {
1008
+ throw new ParseError("Expected ] after column name", this.tokens.peek().position);
1009
+ }
1010
+ this.tokens.consume();
1011
+ if (this.tokens.match("COLON")) {
1012
+ this.tokens.consume();
1013
+ if (!this.tokens.match("LBRACKET")) {
1014
+ throw new ParseError("Expected [ before second column name", this.tokens.peek().position);
1015
+ }
1016
+ this.tokens.consume();
1017
+ const colEnd = this.parseColumnName();
1018
+ if (!this.tokens.match("RBRACKET")) {
1019
+ throw new ParseError("Expected ] after second column name", this.tokens.peek().position);
1020
+ }
1021
+ this.tokens.consume();
1022
+ cols = {
1023
+ startCol: colStart,
1024
+ endCol: colEnd
1025
+ };
1026
+ } else {
1027
+ cols = {
1028
+ startCol: colStart,
1029
+ endCol: colStart
1030
+ };
1031
+ }
1032
+ if (!this.tokens.match("RBRACKET")) {
1033
+ throw new ParseError("Expected ] to close table reference", this.tokens.peek().position);
1034
+ }
1035
+ this.tokens.consume();
1036
+ } else {
1037
+ const colStart = this.parseColumnName();
1038
+ if (this.tokens.match("COLON")) {
1039
+ this.tokens.consume();
1040
+ const colEnd = this.parseColumnName();
1041
+ cols = {
1042
+ startCol: colStart,
1043
+ endCol: colEnd
1044
+ };
1045
+ } else {
1046
+ cols = {
1047
+ startCol: colStart,
1048
+ endCol: colStart
1049
+ };
1050
+ }
1051
+ if (!this.tokens.match("RBRACKET")) {
1052
+ throw new ParseError("Expected ] after column reference", this.tokens.peek().position);
1053
+ }
1054
+ this.tokens.consume();
1055
+ }
1056
+ } else if (this.tokens.match("IDENTIFIER") || this.tokens.match("FUNCTION") || this.tokens.match("NUMBER") || this.tokens.match("OPERATOR")) {
1057
+ const colStart = this.parseColumnName();
1058
+ if (this.tokens.match("COLON")) {
1059
+ this.tokens.consume();
1060
+ const colEnd = this.parseColumnName();
1061
+ cols = {
1062
+ startCol: colStart,
1063
+ endCol: colEnd
1064
+ };
1065
+ } else {
1066
+ cols = {
1067
+ startCol: colStart,
1068
+ endCol: colStart
1069
+ };
1070
+ }
1071
+ if (!this.tokens.match("RBRACKET")) {
1072
+ throw new ParseError("Expected ] after column name", this.tokens.peek().position);
1073
+ }
1074
+ this.tokens.consume();
1075
+ } else if (this.tokens.match("HASH")) {
1076
+ this.tokens.consume();
1077
+ if (!this.tokens.match("IDENTIFIER")) {
1078
+ throw new ParseError("Expected selector name after #", this.tokens.peek().position);
1079
+ }
1080
+ const selectorName = this.tokens.consume().value;
1081
+ selector = `#${selectorName}`;
1082
+ if (!this.tokens.match("RBRACKET")) {
1083
+ throw new ParseError("Expected ] after selector", this.tokens.peek().position);
1084
+ }
1085
+ this.tokens.consume();
1086
+ } else {
1087
+ throw new ParseError("Expected column name or selector in table reference", this.tokens.peek().position);
1088
+ }
1089
+ return import_ast.createStructuredReferenceNode({
1090
+ tableName,
1091
+ sheetName,
1092
+ cols,
1093
+ selector,
1094
+ isCurrentRow,
1095
+ position: {
1096
+ start: startPos,
1097
+ end: this.tokens.peek().position?.end ?? 0
1098
+ }
1099
+ });
1100
+ }
1101
+ parseCellOrRangeAfterSheets() {
1102
+ const start = this.tokens.peek().position?.start ?? 0;
1103
+ if (this.tokens.match("IDENTIFIER")) {
1104
+ const firstIdent = this.tokens.consume().value;
1105
+ const cellRef = this.parseCellReferenceString(firstIdent);
1106
+ if (cellRef) {
1107
+ if (this.tokens.match("COLON")) {
1108
+ this.tokens.consume();
1109
+ const endRef = this.parseRangeEnd();
1110
+ const endPos = this.tokens.peek().position?.end ?? 0;
1111
+ const parsed = this.parseRange(firstIdent, endRef, start, endPos);
1112
+ if (parsed.type === "range") {
1113
+ parsed.sheetName = undefined;
1114
+ }
1115
+ return parsed;
1116
+ }
1117
+ if (cellRef.type === "reference") {
1118
+ cellRef.sheetName = undefined;
1119
+ }
1120
+ return cellRef;
1121
+ }
1122
+ }
1123
+ if (this.tokens.match("DOLLAR")) {
1124
+ const dollarStart = this.tokens.getPosition();
1125
+ this.tokens.consume();
1126
+ let ref = "$";
1127
+ if (this.tokens.match("IDENTIFIER")) {
1128
+ const col = this.tokens.consume().value;
1129
+ if (this.isColumnIdentifier(col)) {
1130
+ ref += col;
1131
+ }
1132
+ }
1133
+ if (this.tokens.match("DOLLAR")) {
1134
+ ref += this.tokens.consume().value;
1135
+ }
1136
+ if (this.tokens.match("NUMBER")) {
1137
+ ref += this.tokens.consume().value;
1138
+ }
1139
+ if (this.tokens.match("COLON")) {
1140
+ this.tokens.consume();
1141
+ const endRef = this.parseRangeEnd();
1142
+ const endPos = this.tokens.peek().position?.end ?? 0;
1143
+ const parsed = this.parseRange(ref, endRef, start, endPos);
1144
+ if (parsed.type === "range") {
1145
+ parsed.sheetName = undefined;
1146
+ }
1147
+ return parsed;
1148
+ }
1149
+ const cellRef = this.parseCellReferenceString(ref);
1150
+ if (!cellRef) {
1151
+ throw new ParseError(`Invalid cell reference: ${ref}`, this.tokens.peek().position);
1152
+ }
1153
+ if (cellRef.type === "reference") {
1154
+ cellRef.sheetName = undefined;
1155
+ }
1156
+ return cellRef;
1157
+ }
1158
+ throw new ParseError("Expected cell or range reference after sheet range", this.tokens.peek().position);
1159
+ }
1160
+ parseCurrentRowReference() {
1161
+ const start = this.tokens.getPosition();
1162
+ if (this.tokens.match("LBRACKET")) {
1163
+ this.tokens.consume();
1164
+ if (!this.tokens.match("AT")) {
1165
+ throw new ParseError("Expected @ after [", this.tokens.peek().position);
1166
+ }
1167
+ this.tokens.consume();
1168
+ let columnName2;
1169
+ if (this.tokens.match("LBRACKET")) {
1170
+ this.tokens.consume();
1171
+ const colStart = this.parseColumnName();
1172
+ if (!this.tokens.match("RBRACKET")) {
1173
+ throw new ParseError("Expected ] to close column name", this.tokens.peek().position);
1174
+ }
1175
+ this.tokens.consume();
1176
+ if (this.tokens.match("COLON")) {
1177
+ this.tokens.consume();
1178
+ if (!this.tokens.match("LBRACKET")) {
1179
+ throw new ParseError("Expected [ before second column name", this.tokens.peek().position);
1180
+ }
1181
+ this.tokens.consume();
1182
+ const colEnd = this.parseColumnName();
1183
+ if (!this.tokens.match("RBRACKET")) {
1184
+ throw new ParseError("Expected ] after second column name", this.tokens.peek().position);
1185
+ }
1186
+ this.tokens.consume();
1187
+ if (!this.tokens.match("RBRACKET")) {
1188
+ throw new ParseError("Expected ] to close column range", this.tokens.peek().position);
1189
+ }
1190
+ this.tokens.consume();
1191
+ return import_ast.createStructuredReferenceNode({
1192
+ tableName: undefined,
1193
+ cols: {
1194
+ startCol: colStart,
1195
+ endCol: colEnd
1196
+ },
1197
+ isCurrentRow: true,
1198
+ position: {
1199
+ start: this.tokens.getTokens()[start]?.position?.start ?? 0,
1200
+ end: this.tokens.peek().position?.end ?? 0
1201
+ }
1202
+ });
1203
+ } else {
1204
+ if (!this.tokens.match("RBRACKET")) {
1205
+ throw new ParseError("Expected ] after column reference", this.tokens.peek().position);
1206
+ }
1207
+ this.tokens.consume();
1208
+ return import_ast.createStructuredReferenceNode({
1209
+ tableName: undefined,
1210
+ cols: {
1211
+ startCol: colStart,
1212
+ endCol: colStart
1213
+ },
1214
+ isCurrentRow: true,
1215
+ position: {
1216
+ start: this.tokens.getTokens()[start]?.position?.start ?? 0,
1217
+ end: this.tokens.peek().position?.end ?? 0
1218
+ }
1219
+ });
1220
+ }
1221
+ } else {
1222
+ columnName2 = this.parseColumnName();
1223
+ }
1224
+ if (!this.tokens.match("RBRACKET")) {
1225
+ throw new ParseError("Expected ] after column reference", this.tokens.peek().position);
1226
+ }
1227
+ this.tokens.consume();
1228
+ return import_ast.createStructuredReferenceNode({
1229
+ tableName: undefined,
1230
+ cols: {
1231
+ startCol: columnName2,
1232
+ endCol: columnName2
1233
+ },
1234
+ isCurrentRow: true,
1235
+ position: {
1236
+ start: this.tokens.getTokens()[start]?.position?.start ?? 0,
1237
+ end: this.tokens.peek().position?.end ?? 0
1238
+ }
1239
+ });
1240
+ }
1241
+ this.tokens.consume();
1242
+ const columnName = this.parseColumnName();
1243
+ return import_ast.createStructuredReferenceNode({
1244
+ tableName: undefined,
1245
+ cols: {
1246
+ startCol: columnName,
1247
+ endCol: columnName
1248
+ },
1249
+ isCurrentRow: true,
1250
+ position: {
1251
+ start: this.tokens.getTokens()[start]?.position?.start ?? 0,
1252
+ end: this.tokens.peek().position?.end ?? 0
1253
+ }
1254
+ });
1255
+ }
1256
+ parseTableSelector() {
1257
+ const hashToken = this.tokens.consume();
1258
+ if (!this.tokens.match("IDENTIFIER")) {
1259
+ throw new ParseError("Expected selector name after #", this.tokens.peek().position);
1260
+ }
1261
+ const selectorName = this.tokens.consume().value;
1262
+ const selector = `#${selectorName}`;
1263
+ if (!["#All", "#Data", "#Headers"].includes(selector.toUpperCase())) {
1264
+ throw new ParseError(`Invalid table selector: ${selector}`, hashToken.position);
1265
+ }
1266
+ throw new ParseError("Table selector must be part of a table reference", hashToken.position);
1267
+ }
1268
+ parseRangeWithWorkbook(startRef, endRef, workbookName, startPos, endPos) {
1269
+ const rangeNode = this.parseRange(startRef, endRef, startPos, endPos);
1270
+ rangeNode.workbookName = workbookName;
1271
+ return rangeNode;
1272
+ }
1273
+ parseTableReferenceWithWorkbookAndSheet(tableName, workbookName, sheetName, startPos) {
1274
+ const tableRef = this.parseTableReferenceWithSheet(tableName, sheetName, startPos);
1275
+ if (tableRef.type === "structured-reference") {
1276
+ tableRef.workbookName = workbookName;
1277
+ }
1278
+ return tableRef;
1279
+ }
1280
+ parseRange(startRef, endRef, startPos, endPos) {
1281
+ let fullRange = `${startRef}:${endRef}`;
1282
+ let sheetName;
1283
+ const sheetMatch = startRef.match(/^(?:([A-Za-z_][A-Za-z0-9_]*)|'([^']+)')!/);
1284
+ if (sheetMatch) {
1285
+ sheetName = sheetMatch[1] || sheetMatch[2];
1286
+ const infiniteTest = import_grammar.parseInfiniteRange(fullRange);
1287
+ const openEndedTest = import_grammar.parseOpenEndedRange(fullRange);
1288
+ if (infiniteTest || openEndedTest) {} else {
1289
+ const endSheetMatch = endRef.match(/^(?:([A-Za-z_][A-Za-z0-9_]*)|'([^']+)')!/);
1290
+ if (!endSheetMatch && sheetName) {
1291
+ const quotedSheetName = sheetName.includes(" ") ? `'${sheetName}'` : sheetName;
1292
+ endRef = `${quotedSheetName}!${endRef}`;
1293
+ fullRange = `${startRef}:${endRef}`;
1294
+ }
1295
+ }
1296
+ }
1297
+ const infiniteParsed = import_grammar.parseInfiniteRange(fullRange);
1298
+ if (infiniteParsed) {
1299
+ sheetName = sheetName ?? infiniteParsed.sheet;
1300
+ if (infiniteParsed.type === "column") {
1301
+ const startCol2 = import_utils.columnToIndex(infiniteParsed.start);
1302
+ const endCol2 = import_utils.columnToIndex(infiniteParsed.end);
1303
+ if (startCol2 < 0 || endCol2 < 0) {
1304
+ throw new ParseError(`Invalid column range: ${startRef}:${endRef}`, {
1305
+ start: startPos,
1306
+ end: endPos
1307
+ });
1308
+ }
1309
+ const range2 = {
1310
+ start: {
1311
+ col: Math.min(startCol2, endCol2),
1312
+ row: 0
1313
+ },
1314
+ end: {
1315
+ col: {
1316
+ type: "number",
1317
+ value: Math.max(startCol2, endCol2)
1318
+ },
1319
+ row: {
1320
+ type: "infinity",
1321
+ sign: "positive"
1322
+ }
1323
+ }
1324
+ };
1325
+ return import_ast.createRangeNode({
1326
+ sheetName,
1327
+ range: range2,
1328
+ isAbsolute: {
1329
+ start: {
1330
+ col: infiniteParsed.startAbsolute,
1331
+ row: false
1332
+ },
1333
+ end: {
1334
+ col: infiniteParsed.endAbsolute,
1335
+ row: false
1336
+ }
1337
+ },
1338
+ position: {
1339
+ start: startPos,
1340
+ end: endPos
1341
+ }
1342
+ });
1343
+ } else {
1344
+ const startRow2 = parseInt(infiniteParsed.start) - 1;
1345
+ const endRow2 = parseInt(infiniteParsed.end) - 1;
1346
+ if (startRow2 < 0 || endRow2 < 0) {
1347
+ throw new ParseError(`Invalid row range: ${startRef}:${endRef}`, {
1348
+ start: startPos,
1349
+ end: endPos
1350
+ });
1351
+ }
1352
+ const range2 = {
1353
+ start: {
1354
+ col: 0,
1355
+ row: Math.min(startRow2, endRow2)
1356
+ },
1357
+ end: {
1358
+ col: {
1359
+ type: "infinity",
1360
+ sign: "positive"
1361
+ },
1362
+ row: {
1363
+ type: "number",
1364
+ value: Math.max(startRow2, endRow2)
1365
+ }
1366
+ }
1367
+ };
1368
+ return import_ast.createRangeNode({
1369
+ sheetName,
1370
+ range: range2,
1371
+ isAbsolute: {
1372
+ start: {
1373
+ col: false,
1374
+ row: infiniteParsed.startAbsolute
1375
+ },
1376
+ end: {
1377
+ col: false,
1378
+ row: infiniteParsed.endAbsolute
1379
+ }
1380
+ },
1381
+ position: {
1382
+ start: startPos,
1383
+ end: endPos
1384
+ }
1385
+ });
1386
+ }
1387
+ }
1388
+ const openEndedParsed = import_grammar.parseOpenEndedRange(fullRange);
1389
+ if (openEndedParsed) {
1390
+ sheetName = sheetName ?? openEndedParsed.sheet;
1391
+ const startCol2 = import_utils.columnToIndex(openEndedParsed.startCol);
1392
+ const startRow2 = parseInt(openEndedParsed.startRow) - 1;
1393
+ if (startCol2 < 0 || startRow2 < 0) {
1394
+ throw new ParseError(`Invalid range reference: ${startRef}:${endRef}`, {
1395
+ start: startPos,
1396
+ end: endPos
1397
+ });
1398
+ }
1399
+ if (openEndedParsed.type === "infinity") {
1400
+ const range2 = {
1401
+ start: {
1402
+ col: startCol2,
1403
+ row: startRow2
1404
+ },
1405
+ end: {
1406
+ col: {
1407
+ type: "infinity",
1408
+ sign: "positive"
1409
+ },
1410
+ row: {
1411
+ type: "infinity",
1412
+ sign: "positive"
1413
+ }
1414
+ }
1415
+ };
1416
+ return import_ast.createRangeNode({
1417
+ sheetName,
1418
+ range: range2,
1419
+ isAbsolute: {
1420
+ start: {
1421
+ col: openEndedParsed.startColAbsolute,
1422
+ row: openEndedParsed.startRowAbsolute
1423
+ },
1424
+ end: {
1425
+ col: false,
1426
+ row: false
1427
+ }
1428
+ },
1429
+ position: {
1430
+ start: startPos,
1431
+ end: endPos
1432
+ }
1433
+ });
1434
+ } else if (openEndedParsed.type === "column-bounded") {
1435
+ const endCol2 = import_utils.columnToIndex(openEndedParsed.endCol);
1436
+ if (endCol2 < 0) {
1437
+ throw new ParseError(`Invalid column range: ${startRef}:${endRef}`, {
1438
+ start: startPos,
1439
+ end: endPos
1440
+ });
1441
+ }
1442
+ const range2 = {
1443
+ start: {
1444
+ col: Math.min(startCol2, endCol2),
1445
+ row: startRow2
1446
+ },
1447
+ end: {
1448
+ col: {
1449
+ type: "number",
1450
+ value: Math.max(startCol2, endCol2)
1451
+ },
1452
+ row: {
1453
+ type: "infinity",
1454
+ sign: "positive"
1455
+ }
1456
+ }
1457
+ };
1458
+ return import_ast.createRangeNode({
1459
+ sheetName,
1460
+ range: range2,
1461
+ isAbsolute: {
1462
+ start: {
1463
+ col: openEndedParsed.startColAbsolute,
1464
+ row: openEndedParsed.startRowAbsolute
1465
+ },
1466
+ end: {
1467
+ col: openEndedParsed.endColAbsolute,
1468
+ row: false
1469
+ }
1470
+ },
1471
+ position: {
1472
+ start: startPos,
1473
+ end: endPos
1474
+ }
1475
+ });
1476
+ } else if (openEndedParsed.type === "row-bounded") {
1477
+ const endRow2 = parseInt(openEndedParsed.endRow) - 1;
1478
+ if (endRow2 < 0) {
1479
+ throw new ParseError(`Invalid row range: ${startRef}:${endRef}`, {
1480
+ start: startPos,
1481
+ end: endPos
1482
+ });
1483
+ }
1484
+ const range2 = {
1485
+ start: {
1486
+ col: startCol2,
1487
+ row: Math.min(startRow2, endRow2)
1488
+ },
1489
+ end: {
1490
+ col: {
1491
+ type: "infinity",
1492
+ sign: "positive"
1493
+ },
1494
+ row: {
1495
+ type: "number",
1496
+ value: Math.max(startRow2, endRow2)
1497
+ }
1498
+ }
1499
+ };
1500
+ return import_ast.createRangeNode({
1501
+ sheetName,
1502
+ range: range2,
1503
+ isAbsolute: {
1504
+ start: {
1505
+ col: openEndedParsed.startColAbsolute,
1506
+ row: openEndedParsed.startRowAbsolute
1507
+ },
1508
+ end: {
1509
+ col: false,
1510
+ row: openEndedParsed.endRowAbsolute
1511
+ }
1512
+ },
1513
+ position: {
1514
+ start: startPos,
1515
+ end: endPos
1516
+ }
1517
+ });
1518
+ }
1519
+ }
1520
+ const startParsed = import_grammar.parseCellReference(startRef);
1521
+ const endParsed = import_grammar.parseCellReference(endRef);
1522
+ if (!startParsed || !endParsed) {
1523
+ throw new ParseError(`Invalid range reference: ${startRef}:${endRef}`, {
1524
+ start: startPos,
1525
+ end: endPos
1526
+ });
1527
+ }
1528
+ const startSheet = startParsed.sheet;
1529
+ const endSheet = endParsed.sheet;
1530
+ if (startSheet !== endSheet) {
1531
+ throw new ParseError(`Range references must be on the same sheet`, {
1532
+ start: startPos,
1533
+ end: endPos
1534
+ });
1535
+ }
1536
+ sheetName = sheetName ?? startSheet;
1537
+ const startCol = import_utils.columnToIndex(startParsed.col);
1538
+ const startRow = parseInt(startParsed.row) - 1;
1539
+ const endCol = import_utils.columnToIndex(endParsed.col);
1540
+ const endRow = parseInt(endParsed.row) - 1;
1541
+ if (startCol < 0 || startRow < 0 || endCol < 0 || endRow < 0) {
1542
+ throw new ParseError(`Invalid range reference: ${startRef}:${endRef}`, {
1543
+ start: startPos,
1544
+ end: endPos
1545
+ });
1546
+ }
1547
+ const range = {
1548
+ start: {
1549
+ col: Math.min(startCol, endCol),
1550
+ row: Math.min(startRow, endRow)
1551
+ },
1552
+ end: {
1553
+ col: {
1554
+ type: "number",
1555
+ value: Math.max(startCol, endCol)
1556
+ },
1557
+ row: {
1558
+ type: "number",
1559
+ value: Math.max(startRow, endRow)
1560
+ }
1561
+ }
1562
+ };
1563
+ return import_ast.createRangeNode({
1564
+ sheetName,
1565
+ range,
1566
+ isAbsolute: {
1567
+ start: {
1568
+ col: startParsed.colAbsolute,
1569
+ row: startParsed.rowAbsolute
1570
+ },
1571
+ end: {
1572
+ col: endParsed.colAbsolute,
1573
+ row: endParsed.rowAbsolute
1574
+ }
1575
+ },
1576
+ position: {
1577
+ start: startPos,
1578
+ end: endPos
1579
+ }
1580
+ });
1581
+ }
1582
+ parseCellOrRangeWithWorkbookAndSheet(workbookName, sheetName, startPos) {
1583
+ let ref = sheetName.includes(" ") ? `'${sheetName}'!` : sheetName + "!";
1584
+ if (this.tokens.match("DOLLAR")) {
1585
+ ref += this.tokens.consume().value;
1586
+ }
1587
+ if (this.tokens.match("IDENTIFIER")) {
1588
+ const identifier2 = this.tokens.consume();
1589
+ ref += identifier2.value;
1590
+ if (this.tokens.match("LBRACKET")) {
1591
+ return this.parseTableReferenceWithWorkbookAndSheet(identifier2.value, workbookName, sheetName, startPos);
1592
+ }
1593
+ if (this.tokens.match("COLON")) {
1594
+ this.tokens.consume();
1595
+ const endRef = this.parseRangeEnd();
1596
+ return this.parseRangeWithWorkbook(ref, endRef, workbookName, startPos, this.tokens.peek().position.start);
1597
+ }
1598
+ if (this.tokens.match("DOLLAR")) {
1599
+ ref += this.tokens.consume().value;
1600
+ }
1601
+ if (this.tokens.match("NUMBER")) {
1602
+ ref += this.tokens.consume().value;
1603
+ }
1604
+ } else if (this.tokens.match("NUMBER")) {
1605
+ const number = this.tokens.consume();
1606
+ ref += number.value;
1607
+ if (this.tokens.match("COLON")) {
1608
+ this.tokens.consume();
1609
+ const endRef = this.parseRangeEnd();
1610
+ return this.parseRangeWithWorkbook(ref, endRef, workbookName, startPos, this.tokens.peek().position.start);
1611
+ }
1612
+ } else {
1613
+ throw new ParseError(`Expected cell reference after [${workbookName}]${sheetName}!`, this.tokens.peek().position);
1614
+ }
1615
+ if (this.tokens.match("COLON")) {
1616
+ this.tokens.consume();
1617
+ const endRef = this.parseRangeEnd();
1618
+ return this.parseRangeWithWorkbook(ref, endRef, workbookName, startPos, this.tokens.peek().position.start);
1619
+ }
1620
+ const cellRef = this.parseCellReferenceString(ref);
1621
+ if (cellRef) {
1622
+ cellRef.workbookName = workbookName;
1623
+ return cellRef;
1624
+ }
1625
+ const sheetPrefix = sheetName.includes(" ") ? `'${sheetName}'!` : `${sheetName}!`;
1626
+ const identifier = ref.substring(sheetPrefix.length);
1627
+ if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(identifier)) {
1628
+ return import_ast.createNamedExpressionNode(identifier, {
1629
+ start: startPos,
1630
+ end: this.tokens.peek().position.start
1631
+ }, sheetName, workbookName);
1632
+ }
1633
+ throw new ParseError(`Invalid cell reference: ${ref}`, {
1634
+ start: startPos,
1635
+ end: this.tokens.peek().position.start
1636
+ });
1637
+ }
1638
+ parseCellOrRangeWithSheet(sheetName, startPos) {
1639
+ let ref = sheetName.includes(" ") ? `'${sheetName}'!` : sheetName + "!";
1640
+ if (this.tokens.match("DOLLAR")) {
1641
+ ref += this.tokens.consume().value;
1642
+ }
1643
+ if (this.tokens.match("IDENTIFIER")) {
1644
+ const identifier = this.tokens.consume();
1645
+ ref += identifier.value;
1646
+ if (this.tokens.match("LBRACKET")) {
1647
+ return this.parseTableReferenceWithSheet(identifier.value, sheetName, startPos);
1648
+ }
1649
+ if (this.tokens.match("COLON")) {
1650
+ this.tokens.consume();
1651
+ const endRef = this.parseRangeEnd();
1652
+ return this.parseRange(ref, endRef, startPos, this.tokens.peek().position.start);
1653
+ }
1654
+ if (this.tokens.match("DOLLAR")) {
1655
+ ref += this.tokens.consume().value;
1656
+ }
1657
+ if (this.tokens.match("NUMBER")) {
1658
+ ref += this.tokens.consume().value;
1659
+ }
1660
+ } else if (this.tokens.match("NUMBER")) {
1661
+ const number = this.tokens.consume();
1662
+ ref += number.value;
1663
+ if (this.tokens.match("COLON")) {
1664
+ this.tokens.consume();
1665
+ const endRef = this.parseRangeEnd();
1666
+ return this.parseRange(ref, endRef, startPos, this.tokens.peek().position.start);
1667
+ }
1668
+ } else {
1669
+ throw new ParseError(`Expected cell reference after ${sheetName}!`, this.tokens.peek().position);
1670
+ }
1671
+ if (this.tokens.match("COLON")) {
1672
+ this.tokens.consume();
1673
+ const endRef = this.parseRangeEnd();
1674
+ return this.parseRange(ref, endRef, startPos, this.tokens.peek().position.start);
1675
+ }
1676
+ const cellRef = this.parseCellReferenceString(ref);
1677
+ if (cellRef) {
1678
+ return cellRef;
1679
+ }
1680
+ if (this.tokens.isAtEnd() || !this.tokens.match("IDENTIFIER")) {
1681
+ const sheetPrefix = sheetName.includes(" ") ? `'${sheetName}'!` : `${sheetName}!`;
1682
+ const identifier = ref.substring(sheetPrefix.length);
1683
+ if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(identifier)) {
1684
+ return import_ast.createNamedExpressionNode(identifier, {
1685
+ start: startPos,
1686
+ end: this.tokens.peek().position.start
1687
+ }, sheetName);
1688
+ }
1689
+ }
1690
+ throw new ParseError(`Invalid cell reference: ${ref}`, {
1691
+ start: startPos,
1692
+ end: this.tokens.peek().position.start
1693
+ });
1694
+ }
1695
+ }
1696
+ function parseFormula(formula) {
1697
+ return Parser.parse(formula);
1698
+ }
1699
+
1700
+ //# debugId=1BD93F3357F24C4664756E2164756E21