research-copilot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (395) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +190 -0
  3. package/app/build/icon.icns +0 -0
  4. package/app/build/icon.ico +0 -0
  5. package/app/build/icon.png +0 -0
  6. package/app/out/main/index.mjs +6719 -0
  7. package/app/out/preload/index.js +141 -0
  8. package/app/out/renderer/assets/Inter-Variable-Latin-8kRkwJBP.woff2 +0 -0
  9. package/app/out/renderer/assets/Inter-Variable-LatinExt-B_-bZUTo.woff2 +0 -0
  10. package/app/out/renderer/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  11. package/app/out/renderer/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  12. package/app/out/renderer/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  13. package/app/out/renderer/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  14. package/app/out/renderer/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  15. package/app/out/renderer/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  16. package/app/out/renderer/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  17. package/app/out/renderer/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  18. package/app/out/renderer/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  19. package/app/out/renderer/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  20. package/app/out/renderer/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  21. package/app/out/renderer/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  22. package/app/out/renderer/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  23. package/app/out/renderer/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  24. package/app/out/renderer/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  25. package/app/out/renderer/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  26. package/app/out/renderer/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  27. package/app/out/renderer/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  28. package/app/out/renderer/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  29. package/app/out/renderer/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  30. package/app/out/renderer/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  31. package/app/out/renderer/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  32. package/app/out/renderer/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  33. package/app/out/renderer/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  34. package/app/out/renderer/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  35. package/app/out/renderer/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  36. package/app/out/renderer/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  37. package/app/out/renderer/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  38. package/app/out/renderer/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  39. package/app/out/renderer/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  40. package/app/out/renderer/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  41. package/app/out/renderer/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  42. package/app/out/renderer/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  43. package/app/out/renderer/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  44. package/app/out/renderer/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  45. package/app/out/renderer/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  46. package/app/out/renderer/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  47. package/app/out/renderer/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  48. package/app/out/renderer/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  49. package/app/out/renderer/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  50. package/app/out/renderer/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  51. package/app/out/renderer/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  52. package/app/out/renderer/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  53. package/app/out/renderer/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  54. package/app/out/renderer/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  55. package/app/out/renderer/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  56. package/app/out/renderer/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  57. package/app/out/renderer/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  58. package/app/out/renderer/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  59. package/app/out/renderer/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  60. package/app/out/renderer/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  61. package/app/out/renderer/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  62. package/app/out/renderer/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  63. package/app/out/renderer/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  64. package/app/out/renderer/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  65. package/app/out/renderer/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  66. package/app/out/renderer/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  67. package/app/out/renderer/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  68. package/app/out/renderer/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  69. package/app/out/renderer/assets/MilkdownMarkdownEditor-bLPxrCVb.js +89821 -0
  70. package/app/out/renderer/assets/MilkdownMarkdownEditor-tTNRIB2K.css +2555 -0
  71. package/app/out/renderer/assets/Tableau10-BqnYsPR6.js +9 -0
  72. package/app/out/renderer/assets/apl-fqmucPXA.js +140 -0
  73. package/app/out/renderer/assets/arc-J47ePHZ2.js +132 -0
  74. package/app/out/renderer/assets/array-DgktLKBx.js +6 -0
  75. package/app/out/renderer/assets/asciiarmor-DucZyvP0.js +56 -0
  76. package/app/out/renderer/assets/asn1-BnOEsgAm.js +144 -0
  77. package/app/out/renderer/assets/asterisk-QAlztEwS.js +345 -0
  78. package/app/out/renderer/assets/blockDiagram-c4efeb88-5uRQXgQJ.js +1817 -0
  79. package/app/out/renderer/assets/brainfuck-DZVCuF_t.js +53 -0
  80. package/app/out/renderer/assets/c4Diagram-c83219d4-C4iCTPEL.js +2464 -0
  81. package/app/out/renderer/assets/channel-ZAmhHE3g.js +7 -0
  82. package/app/out/renderer/assets/classDiagram-beda092f-7NOZxq_W.js +357 -0
  83. package/app/out/renderer/assets/classDiagram-v2-2358418a-5fPT-cUH.js +291 -0
  84. package/app/out/renderer/assets/clike-xqXYL6ge.js +805 -0
  85. package/app/out/renderer/assets/clojure-BhXMqnxz.js +849 -0
  86. package/app/out/renderer/assets/clone-CsnzsYXQ.js +8 -0
  87. package/app/out/renderer/assets/cmake-BGaNd9E7.js +71 -0
  88. package/app/out/renderer/assets/cobol-4yqQntpt.js +120 -0
  89. package/app/out/renderer/assets/coffeescript-D2dXvhEc.js +308 -0
  90. package/app/out/renderer/assets/commonlisp-CF_VNHQR.js +130 -0
  91. package/app/out/renderer/assets/createText-1719965b-Cji7KN4K.js +4904 -0
  92. package/app/out/renderer/assets/crystal-DyuLTqLs.js +398 -0
  93. package/app/out/renderer/assets/css-c-jst79C.js +1783 -0
  94. package/app/out/renderer/assets/cypher-Dlu_3r4V.js +121 -0
  95. package/app/out/renderer/assets/d-UURgV0Ux.js +179 -0
  96. package/app/out/renderer/assets/diff-B_Bi2Crb.js +25 -0
  97. package/app/out/renderer/assets/dockerfile-Bvk733Ga.js +201 -0
  98. package/app/out/renderer/assets/dtd-Dy74G54E.js +114 -0
  99. package/app/out/renderer/assets/dylan-TSb-Nfix.js +314 -0
  100. package/app/out/renderer/assets/ebnf-DAomQUbD.js +139 -0
  101. package/app/out/renderer/assets/ecl-B59qGGVg.js +178 -0
  102. package/app/out/renderer/assets/edges-96097737-CD0EvAZQ.js +1844 -0
  103. package/app/out/renderer/assets/eiffel-Dze7nlu3.js +134 -0
  104. package/app/out/renderer/assets/elm-DG7jkhNZ.js +176 -0
  105. package/app/out/renderer/assets/erDiagram-0228fc6a-DRYXBpi7.js +1321 -0
  106. package/app/out/renderer/assets/erlang-BO6gOnGA.js +674 -0
  107. package/app/out/renderer/assets/factor-CMxFHDqz.js +65 -0
  108. package/app/out/renderer/assets/fcl-CDDUNjTj.js +141 -0
  109. package/app/out/renderer/assets/flowDb-c6c81e3f-CuoIN-Cy.js +1713 -0
  110. package/app/out/renderer/assets/flowDiagram-50d868cf-CPWPLOml.js +1272 -0
  111. package/app/out/renderer/assets/flowDiagram-v2-4f6560a1-C_R12s4S.js +33 -0
  112. package/app/out/renderer/assets/flowchart-elk-definition-6af322e1-BdKUSFpi.js +92921 -0
  113. package/app/out/renderer/assets/forth-B9D2JCeE.js +116 -0
  114. package/app/out/renderer/assets/fortran-CAG2BFbe.js +467 -0
  115. package/app/out/renderer/assets/ganttDiagram-a2739b55-ygqT5HlG.js +3399 -0
  116. package/app/out/renderer/assets/gas-d3KEcW3x.js +294 -0
  117. package/app/out/renderer/assets/gherkin-DhZlEZiy.js +115 -0
  118. package/app/out/renderer/assets/gitGraphDiagram-82fe8481-D97GT4iA.js +1791 -0
  119. package/app/out/renderer/assets/graph-DpC13d95.js +1237 -0
  120. package/app/out/renderer/assets/groovy-CpwJiBl7.js +223 -0
  121. package/app/out/renderer/assets/haskell-BlGBCCe3.js +459 -0
  122. package/app/out/renderer/assets/haxe-7MlzfeYV.js +514 -0
  123. package/app/out/renderer/assets/http-BqypyemW.js +79 -0
  124. package/app/out/renderer/assets/idl-4HIGJlDI.js +985 -0
  125. package/app/out/renderer/assets/index-4-ziknCv.js +292 -0
  126. package/app/out/renderer/assets/index-5325376f-Bbs7Fbqr.js +663 -0
  127. package/app/out/renderer/assets/index-B2jip-rk.js +2489 -0
  128. package/app/out/renderer/assets/index-BKTVfokE.js +312 -0
  129. package/app/out/renderer/assets/index-BiJbFgVG.js +118 -0
  130. package/app/out/renderer/assets/index-Bn433Fat.js +83 -0
  131. package/app/out/renderer/assets/index-BqDyyRCx.js +39679 -0
  132. package/app/out/renderer/assets/index-BzFMeMPn.js +158 -0
  133. package/app/out/renderer/assets/index-C-_uCjZJ.css +2701 -0
  134. package/app/out/renderer/assets/index-C1ithNW1.js +1765 -0
  135. package/app/out/renderer/assets/index-CAJkRYkO.js +407 -0
  136. package/app/out/renderer/assets/index-CleO0-yj.js +690 -0
  137. package/app/out/renderer/assets/index-Cq4MH3sY.js +1020 -0
  138. package/app/out/renderer/assets/index-CtA0Xj22.js +705 -0
  139. package/app/out/renderer/assets/index-CvAZkqBZ.js +83 -0
  140. package/app/out/renderer/assets/index-D3UDN-5c.js +152 -0
  141. package/app/out/renderer/assets/index-D4F9R5ao.js +179 -0
  142. package/app/out/renderer/assets/index-D6RguhZ5.js +328 -0
  143. package/app/out/renderer/assets/index-DnEowqXv.js +386 -0
  144. package/app/out/renderer/assets/index-K8c8Mqdy.js +98 -0
  145. package/app/out/renderer/assets/index-Kh14gO6K.js +62 -0
  146. package/app/out/renderer/assets/index-WFd2jRnA.js +333 -0
  147. package/app/out/renderer/assets/index-WgMfkRFp.js +313 -0
  148. package/app/out/renderer/assets/index-Y4lKyF6t.js +1042 -0
  149. package/app/out/renderer/assets/index-fx307_f1.js +643 -0
  150. package/app/out/renderer/assets/infoDiagram-8eee0895-ptaVSwzq.js +511 -0
  151. package/app/out/renderer/assets/init-ZxktEp_H.js +16 -0
  152. package/app/out/renderer/assets/javascript-C3MnDRiU.js +994 -0
  153. package/app/out/renderer/assets/journeyDiagram-c64418c1-aloEGOQp.js +1184 -0
  154. package/app/out/renderer/assets/julia-Bs6JJhYG.js +407 -0
  155. package/app/out/renderer/assets/layout-ZeuHE_aY.js +2217 -0
  156. package/app/out/renderer/assets/line-CAgaGl-S.js +45 -0
  157. package/app/out/renderer/assets/linear-DIg7lTe1.js +539 -0
  158. package/app/out/renderer/assets/livescript-DmzgM3Yt.js +296 -0
  159. package/app/out/renderer/assets/lua-8cJgIlqe.js +256 -0
  160. package/app/out/renderer/assets/mathematica-DNLOL9PQ.js +110 -0
  161. package/app/out/renderer/assets/mbox-Ga7d4MMN.js +117 -0
  162. package/app/out/renderer/assets/mindmap-definition-8da855dc-B8XVoUxz.js +36054 -0
  163. package/app/out/renderer/assets/mirc-Dma3B8rS.js +107 -0
  164. package/app/out/renderer/assets/mllike-DHn7xckP.js +334 -0
  165. package/app/out/renderer/assets/modelica-0d55jYY0.js +147 -0
  166. package/app/out/renderer/assets/mscgen-DdqZYINH.js +135 -0
  167. package/app/out/renderer/assets/mumps-Btr8VblO.js +93 -0
  168. package/app/out/renderer/assets/nginx-DTDtBDVN.js +141 -0
  169. package/app/out/renderer/assets/nsis-3zG7tgur.js +62 -0
  170. package/app/out/renderer/assets/ntriples-CvgOYMpL.js +153 -0
  171. package/app/out/renderer/assets/octave-DYBj3-tl.js +200 -0
  172. package/app/out/renderer/assets/ordinal-DSZU4PqD.js +76 -0
  173. package/app/out/renderer/assets/oz-R_e8WMIi.js +231 -0
  174. package/app/out/renderer/assets/pascal-GD8iposT.js +105 -0
  175. package/app/out/renderer/assets/path-Cp2qmpkd.js +109 -0
  176. package/app/out/renderer/assets/perl-DL9mHpoi.js +1105 -0
  177. package/app/out/renderer/assets/pieDiagram-a8764435-DlwoeBU2.js +770 -0
  178. package/app/out/renderer/assets/pig-C_4T4YIV.js +101 -0
  179. package/app/out/renderer/assets/powershell-B0suO7Vd.js +328 -0
  180. package/app/out/renderer/assets/properties-BR-vP1aU.js +58 -0
  181. package/app/out/renderer/assets/protobuf-BxgpyhoW.js +77 -0
  182. package/app/out/renderer/assets/pug-By0kVCfm.js +405 -0
  183. package/app/out/renderer/assets/puppet-Bdao66PW.js +137 -0
  184. package/app/out/renderer/assets/python-CvWbmiX4.js +427 -0
  185. package/app/out/renderer/assets/q-CrbCVq4a.js +131 -0
  186. package/app/out/renderer/assets/quadrantDiagram-1e28029f-BaSi1XB4.js +1200 -0
  187. package/app/out/renderer/assets/r-V7nswm59.js +170 -0
  188. package/app/out/renderer/assets/requirementDiagram-08caed73-D3EFyegZ.js +1092 -0
  189. package/app/out/renderer/assets/rpm-C-DLY-If.js +109 -0
  190. package/app/out/renderer/assets/ruby-JDKLJNK0.js +330 -0
  191. package/app/out/renderer/assets/sankeyDiagram-a04cb91d-Cv44AsnM.js +1174 -0
  192. package/app/out/renderer/assets/sas-D2UG-yhZ.js +207 -0
  193. package/app/out/renderer/assets/scheme-BKzrkGJD.js +222 -0
  194. package/app/out/renderer/assets/sequenceDiagram-c5b8d532-CuUBu-x4.js +3337 -0
  195. package/app/out/renderer/assets/shell-BlsXDxCn.js +222 -0
  196. package/app/out/renderer/assets/sieve-CjwBwOY5.js +135 -0
  197. package/app/out/renderer/assets/simple-mode-DMneyfDu.js +130 -0
  198. package/app/out/renderer/assets/smalltalk-BOIGQuhN.js +121 -0
  199. package/app/out/renderer/assets/solr-CwD7U71z.js +69 -0
  200. package/app/out/renderer/assets/sparql-DYskk2vE.js +249 -0
  201. package/app/out/renderer/assets/spreadsheet-Bgtt3oLP.js +87 -0
  202. package/app/out/renderer/assets/sql-BSrOzCRI.js +354 -0
  203. package/app/out/renderer/assets/stateDiagram-1ecb1508-BOU34Zp4.js +454 -0
  204. package/app/out/renderer/assets/stateDiagram-v2-c2b004d7-BgRoffou.js +326 -0
  205. package/app/out/renderer/assets/stex-B6LNC55o.js +231 -0
  206. package/app/out/renderer/assets/styles-b4e223ce-BMr9TPuj.js +1483 -0
  207. package/app/out/renderer/assets/styles-ca3715f6-DgbNw99p.js +1363 -0
  208. package/app/out/renderer/assets/styles-d45a18b0-DtRYKYKf.js +574 -0
  209. package/app/out/renderer/assets/stylus-BkS-boTH.js +565 -0
  210. package/app/out/renderer/assets/svgDrawCommon-b86b1483-Bein03PD.js +100 -0
  211. package/app/out/renderer/assets/swift-FRZi1uvB.js +291 -0
  212. package/app/out/renderer/assets/tcl-CUcaCdmq.js +114 -0
  213. package/app/out/renderer/assets/textile-BnFpjsrl.js +414 -0
  214. package/app/out/renderer/assets/tiddlywiki-CjprD-Qp.js +218 -0
  215. package/app/out/renderer/assets/tiki-B4EPSQ1G.js +265 -0
  216. package/app/out/renderer/assets/timeline-definition-faaaa080-BlWpLE_4.js +1212 -0
  217. package/app/out/renderer/assets/toml-BOuWGMcf.js +76 -0
  218. package/app/out/renderer/assets/troff-E1bJ0PPL.js +61 -0
  219. package/app/out/renderer/assets/ttcn-cfg-Dc39-fIP.js +133 -0
  220. package/app/out/renderer/assets/ttcn-tKd4HLu4.js +192 -0
  221. package/app/out/renderer/assets/turtle-Dq7-1WAf.js +124 -0
  222. package/app/out/renderer/assets/vb-Dp90gtsv.js +196 -0
  223. package/app/out/renderer/assets/vbscript-CI6_mxxU.js +479 -0
  224. package/app/out/renderer/assets/velocity-BwIZK1TH.js +149 -0
  225. package/app/out/renderer/assets/verilog-DDCYnHN8.js +430 -0
  226. package/app/out/renderer/assets/vhdl-DCkMIyT9.js +158 -0
  227. package/app/out/renderer/assets/webidl-BTLTThCm.js +204 -0
  228. package/app/out/renderer/assets/xquery-BgiOC5Ce.js +525 -0
  229. package/app/out/renderer/assets/xychartDiagram-f5964ef8-Bhga-YXm.js +1799 -0
  230. package/app/out/renderer/assets/yacas-b5lAVEIl.js +130 -0
  231. package/app/out/renderer/assets/z80-BZV19vqv.js +93 -0
  232. package/app/out/renderer/index.html +13 -0
  233. package/app/out/skills/community-builtin/README.md +29 -0
  234. package/app/out/skills/community-builtin/document-docx/SKILL.md +44 -0
  235. package/app/out/skills/community-builtin/document-docx/scripts/docx-to-markdown.sh +20 -0
  236. package/app/out/skills/community-builtin/document-docx/scripts/extract-docx-text.sh +28 -0
  237. package/app/out/skills/community-builtin/document-docx/scripts/init-docx-template.sh +32 -0
  238. package/app/out/skills/community-builtin/document-docx/scripts/setup-docx-tools.sh +10 -0
  239. package/app/out/skills/community-builtin/markitdown/SKILL.md +105 -0
  240. package/app/out/skills/community-builtin/markitdown/scripts/batch-convert.sh +40 -0
  241. package/app/out/skills/community-builtin/markitdown/scripts/convert-file.sh +24 -0
  242. package/app/out/skills/community-builtin/markitdown/scripts/setup-markitdown.sh +10 -0
  243. package/app/out/skills/community-builtin/repo-quick-audit/SKILL.md +27 -0
  244. package/app/out/skills/community-builtin/repo-quick-audit/scripts/audit-basics.sh +19 -0
  245. package/app/out/skills/research-pilot-default-project-skills/README.md +23 -0
  246. package/app/out/skills/research-pilot-default-project-skills/citation-management/SKILL.md +39 -0
  247. package/app/out/skills/research-pilot-default-project-skills/citation-management/scripts/doi-to-bibtex.sh +25 -0
  248. package/app/out/skills/research-pilot-default-project-skills/citation-management/scripts/normalize-bibtex-keys.sh +51 -0
  249. package/app/out/skills/research-pilot-default-project-skills/citation-management/scripts/setup-citation-tools.sh +10 -0
  250. package/app/out/skills/research-pilot-default-project-skills/citation-management/scripts/validate-bib.sh +31 -0
  251. package/app/out/skills/research-pilot-default-project-skills/matplotlib/SKILL.md +34 -0
  252. package/app/out/skills/research-pilot-default-project-skills/matplotlib/references/api_reference.md +412 -0
  253. package/app/out/skills/research-pilot-default-project-skills/matplotlib/references/common_issues.md +563 -0
  254. package/app/out/skills/research-pilot-default-project-skills/matplotlib/references/plot_types.md +476 -0
  255. package/app/out/skills/research-pilot-default-project-skills/matplotlib/references/styling_guide.md +589 -0
  256. package/app/out/skills/research-pilot-default-project-skills/matplotlib/references/subagent_quickstart.md +30 -0
  257. package/app/out/skills/research-pilot-default-project-skills/matplotlib/scripts/plot_template.py +401 -0
  258. package/app/out/skills/research-pilot-default-project-skills/matplotlib/scripts/style_configurator.py +409 -0
  259. package/app/out/skills/research-pilot-default-project-skills/research-grants/SKILL.md +38 -0
  260. package/app/out/skills/research-pilot-default-project-skills/research-grants/scripts/check-grant-compliance.sh +40 -0
  261. package/app/out/skills/research-pilot-default-project-skills/research-grants/scripts/grant-summary-card.sh +32 -0
  262. package/app/out/skills/research-pilot-default-project-skills/research-grants/scripts/init-grant-structure.sh +70 -0
  263. package/app/package.json +77 -0
  264. package/bin/cli.mjs +56 -0
  265. package/lib/README.md +145 -0
  266. package/lib/skills/_generated.ts +13 -0
  267. package/lib/skills/builtin/brainstorming-research-ideas/SKILL.md +280 -0
  268. package/lib/skills/builtin/coding/SKILL.md +114 -0
  269. package/lib/skills/builtin/creative-thinking-for-research/SKILL.md +273 -0
  270. package/lib/skills/builtin/matplotlib/SKILL.md +361 -0
  271. package/lib/skills/builtin/matplotlib/references/api_reference.md +412 -0
  272. package/lib/skills/builtin/matplotlib/references/common_issues.md +563 -0
  273. package/lib/skills/builtin/matplotlib/references/plot_types.md +476 -0
  274. package/lib/skills/builtin/matplotlib/references/styling_guide.md +589 -0
  275. package/lib/skills/builtin/matplotlib/scripts/plot_template.py +401 -0
  276. package/lib/skills/builtin/matplotlib/scripts/style_configurator.py +409 -0
  277. package/lib/skills/builtin/paper-writing/SKILL.md +554 -0
  278. package/lib/skills/builtin/paper-writing/references/checklists.md +524 -0
  279. package/lib/skills/builtin/paper-writing/references/citation-workflow.md +562 -0
  280. package/lib/skills/builtin/paper-writing/references/reviewer-guidelines.md +462 -0
  281. package/lib/skills/builtin/paper-writing/references/sources.md +189 -0
  282. package/lib/skills/builtin/paper-writing/references/systems-conferences.md +260 -0
  283. package/lib/skills/builtin/paper-writing/references/writing-guide.md +476 -0
  284. package/lib/skills/builtin/paper-writing/templates/README.md +408 -0
  285. package/lib/skills/builtin/paper-writing/templates/aaai2026/README.md +534 -0
  286. package/lib/skills/builtin/paper-writing/templates/aaai2026/aaai2026-unified-supp.tex +144 -0
  287. package/lib/skills/builtin/paper-writing/templates/aaai2026/aaai2026-unified-template.tex +952 -0
  288. package/lib/skills/builtin/paper-writing/templates/aaai2026/aaai2026.bib +111 -0
  289. package/lib/skills/builtin/paper-writing/templates/aaai2026/aaai2026.bst +1493 -0
  290. package/lib/skills/builtin/paper-writing/templates/aaai2026/aaai2026.sty +315 -0
  291. package/lib/skills/builtin/paper-writing/templates/acl/README.md +50 -0
  292. package/lib/skills/builtin/paper-writing/templates/acl/acl.sty +312 -0
  293. package/lib/skills/builtin/paper-writing/templates/acl/acl_latex.tex +377 -0
  294. package/lib/skills/builtin/paper-writing/templates/acl/acl_lualatex.tex +101 -0
  295. package/lib/skills/builtin/paper-writing/templates/acl/acl_natbib.bst +1940 -0
  296. package/lib/skills/builtin/paper-writing/templates/acl/anthology.bib.txt +26 -0
  297. package/lib/skills/builtin/paper-writing/templates/acl/custom.bib +70 -0
  298. package/lib/skills/builtin/paper-writing/templates/acl/formatting.md +326 -0
  299. package/lib/skills/builtin/paper-writing/templates/asplos2027/main.tex +459 -0
  300. package/lib/skills/builtin/paper-writing/templates/asplos2027/references.bib +135 -0
  301. package/lib/skills/builtin/paper-writing/templates/colm2025/README.md +3 -0
  302. package/lib/skills/builtin/paper-writing/templates/colm2025/colm2025_conference.bib +11 -0
  303. package/lib/skills/builtin/paper-writing/templates/colm2025/colm2025_conference.bst +1440 -0
  304. package/lib/skills/builtin/paper-writing/templates/colm2025/colm2025_conference.pdf +0 -0
  305. package/lib/skills/builtin/paper-writing/templates/colm2025/colm2025_conference.sty +218 -0
  306. package/lib/skills/builtin/paper-writing/templates/colm2025/colm2025_conference.tex +305 -0
  307. package/lib/skills/builtin/paper-writing/templates/colm2025/fancyhdr.sty +485 -0
  308. package/lib/skills/builtin/paper-writing/templates/colm2025/math_commands.tex +508 -0
  309. package/lib/skills/builtin/paper-writing/templates/colm2025/natbib.sty +1246 -0
  310. package/lib/skills/builtin/paper-writing/templates/iclr2026/fancyhdr.sty +485 -0
  311. package/lib/skills/builtin/paper-writing/templates/iclr2026/iclr2026_conference.bib +24 -0
  312. package/lib/skills/builtin/paper-writing/templates/iclr2026/iclr2026_conference.bst +1440 -0
  313. package/lib/skills/builtin/paper-writing/templates/iclr2026/iclr2026_conference.pdf +0 -0
  314. package/lib/skills/builtin/paper-writing/templates/iclr2026/iclr2026_conference.sty +246 -0
  315. package/lib/skills/builtin/paper-writing/templates/iclr2026/iclr2026_conference.tex +414 -0
  316. package/lib/skills/builtin/paper-writing/templates/iclr2026/math_commands.tex +508 -0
  317. package/lib/skills/builtin/paper-writing/templates/iclr2026/natbib.sty +1246 -0
  318. package/lib/skills/builtin/paper-writing/templates/icml2026/algorithm.sty +79 -0
  319. package/lib/skills/builtin/paper-writing/templates/icml2026/algorithmic.sty +201 -0
  320. package/lib/skills/builtin/paper-writing/templates/icml2026/example_paper.bib +75 -0
  321. package/lib/skills/builtin/paper-writing/templates/icml2026/example_paper.pdf +0 -0
  322. package/lib/skills/builtin/paper-writing/templates/icml2026/example_paper.tex +662 -0
  323. package/lib/skills/builtin/paper-writing/templates/icml2026/fancyhdr.sty +864 -0
  324. package/lib/skills/builtin/paper-writing/templates/icml2026/icml2026.bst +1443 -0
  325. package/lib/skills/builtin/paper-writing/templates/icml2026/icml2026.sty +767 -0
  326. package/lib/skills/builtin/paper-writing/templates/icml2026/icml_numpapers.pdf +0 -0
  327. package/lib/skills/builtin/paper-writing/templates/neurips2025/Makefile +36 -0
  328. package/lib/skills/builtin/paper-writing/templates/neurips2025/extra_pkgs.tex +53 -0
  329. package/lib/skills/builtin/paper-writing/templates/neurips2025/main.tex +38 -0
  330. package/lib/skills/builtin/paper-writing/templates/neurips2025/neurips.sty +382 -0
  331. package/lib/skills/builtin/paper-writing/templates/nsdi2027/main.tex +426 -0
  332. package/lib/skills/builtin/paper-writing/templates/nsdi2027/references.bib +151 -0
  333. package/lib/skills/builtin/paper-writing/templates/nsdi2027/usenix-2020-09.sty +83 -0
  334. package/lib/skills/builtin/paper-writing/templates/osdi2026/main.tex +429 -0
  335. package/lib/skills/builtin/paper-writing/templates/osdi2026/references.bib +150 -0
  336. package/lib/skills/builtin/paper-writing/templates/osdi2026/usenix-2020-09.sty +83 -0
  337. package/lib/skills/builtin/paper-writing/templates/sosp2026/main.tex +532 -0
  338. package/lib/skills/builtin/paper-writing/templates/sosp2026/references.bib +148 -0
  339. package/lib/skills/builtin/research-grants/SKILL.md +958 -0
  340. package/lib/skills/builtin/research-grants/assets/budget_justification_template.md +453 -0
  341. package/lib/skills/builtin/research-grants/assets/nih_specific_aims_template.md +166 -0
  342. package/lib/skills/builtin/research-grants/assets/nsf_project_summary_template.md +92 -0
  343. package/lib/skills/builtin/research-grants/references/README.md +285 -0
  344. package/lib/skills/builtin/research-grants/references/broader_impacts.md +392 -0
  345. package/lib/skills/builtin/research-grants/references/darpa_guidelines.md +636 -0
  346. package/lib/skills/builtin/research-grants/references/doe_guidelines.md +586 -0
  347. package/lib/skills/builtin/research-grants/references/nih_guidelines.md +851 -0
  348. package/lib/skills/builtin/research-grants/references/nsf_guidelines.md +570 -0
  349. package/lib/skills/builtin/research-grants/references/nstc_guidelines.md +733 -0
  350. package/lib/skills/builtin/research-grants/references/specific_aims_guide.md +458 -0
  351. package/lib/skills/builtin/rewrite-humanize/SKILL.md +116 -0
  352. package/lib/skills/builtin/rewrite-humanize/references/cs-venue-tone.md +57 -0
  353. package/lib/skills/builtin/rewrite-humanize/references/lexicon.md +50 -0
  354. package/lib/skills/builtin/scholar-evaluation/SKILL.md +300 -0
  355. package/lib/skills/builtin/scholar-evaluation/references/evaluation_framework.md +663 -0
  356. package/lib/skills/builtin/scholar-evaluation/scripts/calculate_scores.py +379 -0
  357. package/lib/skills/builtin/scientific-schematics/SKILL.md +603 -0
  358. package/lib/skills/builtin/scientific-schematics/references/QUICK_REFERENCE.md +182 -0
  359. package/lib/skills/builtin/scientific-schematics/references/README.md +292 -0
  360. package/lib/skills/builtin/scientific-schematics/references/best_practices.md +560 -0
  361. package/lib/skills/builtin/scientific-schematics/scripts/__pycache__/generate_schematic.cpython-312.pyc +0 -0
  362. package/lib/skills/builtin/scientific-schematics/scripts/__pycache__/generate_schematic_ai.cpython-312.pyc +0 -0
  363. package/lib/skills/builtin/scientific-schematics/scripts/example_usage.sh +85 -0
  364. package/lib/skills/builtin/scientific-schematics/scripts/generate_schematic.py +141 -0
  365. package/lib/skills/builtin/scientific-schematics/scripts/generate_schematic_ai.py +910 -0
  366. package/lib/skills/builtin/scientific-visualization/SKILL.md +749 -0
  367. package/lib/skills/builtin/scientific-visualization/assets/color_palettes.py +197 -0
  368. package/lib/skills/builtin/scientific-visualization/assets/nature.mplstyle +63 -0
  369. package/lib/skills/builtin/scientific-visualization/assets/presentation.mplstyle +61 -0
  370. package/lib/skills/builtin/scientific-visualization/assets/publication.mplstyle +68 -0
  371. package/lib/skills/builtin/scientific-visualization/references/color_palettes.md +348 -0
  372. package/lib/skills/builtin/scientific-visualization/references/journal_requirements.md +320 -0
  373. package/lib/skills/builtin/scientific-visualization/references/matplotlib_examples.md +620 -0
  374. package/lib/skills/builtin/scientific-visualization/references/publication_guidelines.md +205 -0
  375. package/lib/skills/builtin/scientific-visualization/scripts/figure_export.py +343 -0
  376. package/lib/skills/builtin/scientific-visualization/scripts/style_presets.py +416 -0
  377. package/lib/skills/builtin/scientific-writing/SKILL.md +745 -0
  378. package/lib/skills/builtin/scientific-writing/assets/REPORT_FORMATTING_GUIDE.md +574 -0
  379. package/lib/skills/builtin/scientific-writing/assets/scientific_report.sty +606 -0
  380. package/lib/skills/builtin/scientific-writing/assets/scientific_report_template.tex +449 -0
  381. package/lib/skills/builtin/scientific-writing/references/citation_styles.md +720 -0
  382. package/lib/skills/builtin/scientific-writing/references/figures_tables.md +806 -0
  383. package/lib/skills/builtin/scientific-writing/references/imrad_structure.md +686 -0
  384. package/lib/skills/builtin/scientific-writing/references/professional_report_formatting.md +664 -0
  385. package/lib/skills/builtin/scientific-writing/references/reporting_guidelines.md +748 -0
  386. package/lib/skills/builtin/scientific-writing/references/writing_principles.md +824 -0
  387. package/lib/skills/builtin/seaborn/SKILL.md +674 -0
  388. package/lib/skills/builtin/seaborn/references/examples.md +822 -0
  389. package/lib/skills/builtin/seaborn/references/function_reference.md +770 -0
  390. package/lib/skills/builtin/seaborn/references/objects_interface.md +964 -0
  391. package/lib/skills/data-analysis/SKILL.md +285 -0
  392. package/lib/skills/generate-skill-content.mjs +58 -0
  393. package/lib/skills/index.ts +34 -0
  394. package/lib/skills/loader.ts +452 -0
  395. package/package.json +62 -0
@@ -0,0 +1,1765 @@
1
+ import { P as Parser, N as NodeSet, k as NodeType, D as DefaultBufferLength, l as NodeProp, T as Tree, I as IterMode } from "./MilkdownMarkdownEditor-bLPxrCVb.js";
2
+ var define_process_env_default = {};
3
+ class Stack {
4
+ /**
5
+ @internal
6
+ */
7
+ constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
8
+ this.p = p;
9
+ this.stack = stack;
10
+ this.state = state;
11
+ this.reducePos = reducePos;
12
+ this.pos = pos;
13
+ this.score = score;
14
+ this.buffer = buffer;
15
+ this.bufferBase = bufferBase;
16
+ this.curContext = curContext;
17
+ this.lookAhead = lookAhead;
18
+ this.parent = parent;
19
+ }
20
+ /**
21
+ @internal
22
+ */
23
+ toString() {
24
+ return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
25
+ }
26
+ // Start an empty stack
27
+ /**
28
+ @internal
29
+ */
30
+ static start(p, state, pos = 0) {
31
+ let cx = p.parser.context;
32
+ return new Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null);
33
+ }
34
+ /**
35
+ The stack's current [context](#lr.ContextTracker) value, if
36
+ any. Its type will depend on the context tracker's type
37
+ parameter, or it will be `null` if there is no context
38
+ tracker.
39
+ */
40
+ get context() {
41
+ return this.curContext ? this.curContext.context : null;
42
+ }
43
+ // Push a state onto the stack, tracking its start position as well
44
+ // as the buffer base at that point.
45
+ /**
46
+ @internal
47
+ */
48
+ pushState(state, start) {
49
+ this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
50
+ this.state = state;
51
+ }
52
+ // Apply a reduce action
53
+ /**
54
+ @internal
55
+ */
56
+ reduce(action) {
57
+ var _a;
58
+ let depth = action >> 19, type = action & 65535;
59
+ let { parser } = this.p;
60
+ let lookaheadRecord = this.reducePos < this.pos - 25 && this.setLookAhead(this.pos);
61
+ let dPrec = parser.dynamicPrecedence(type);
62
+ if (dPrec)
63
+ this.score += dPrec;
64
+ if (depth == 0) {
65
+ this.pushState(parser.getGoto(this.state, type, true), this.reducePos);
66
+ if (type < parser.minRepeatTerm)
67
+ this.storeNode(type, this.reducePos, this.reducePos, lookaheadRecord ? 8 : 4, true);
68
+ this.reduceContext(type, this.reducePos);
69
+ return;
70
+ }
71
+ let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
72
+ let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
73
+ if (size >= 2e3 && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
74
+ if (start == this.p.lastBigReductionStart) {
75
+ this.p.bigReductionCount++;
76
+ this.p.lastBigReductionSize = size;
77
+ } else if (this.p.lastBigReductionSize < size) {
78
+ this.p.bigReductionCount = 1;
79
+ this.p.lastBigReductionStart = start;
80
+ this.p.lastBigReductionSize = size;
81
+ }
82
+ }
83
+ let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
84
+ if (type < parser.minRepeatTerm || action & 131072) {
85
+ let pos = parser.stateFlag(
86
+ this.state,
87
+ 1
88
+ /* StateFlag.Skipped */
89
+ ) ? this.pos : this.reducePos;
90
+ this.storeNode(type, start, pos, count + 4, true);
91
+ }
92
+ if (action & 262144) {
93
+ this.state = this.stack[base];
94
+ } else {
95
+ let baseStateID = this.stack[base - 3];
96
+ this.state = parser.getGoto(baseStateID, type, true);
97
+ }
98
+ while (this.stack.length > base)
99
+ this.stack.pop();
100
+ this.reduceContext(type, start);
101
+ }
102
+ // Shift a value into the buffer
103
+ /**
104
+ @internal
105
+ */
106
+ storeNode(term, start, end, size = 4, mustSink = false) {
107
+ if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
108
+ let cur = this, top = this.buffer.length;
109
+ if (top == 0 && cur.parent) {
110
+ top = cur.bufferBase - cur.parent.bufferBase;
111
+ cur = cur.parent;
112
+ }
113
+ if (top > 0 && cur.buffer[top - 4] == 0 && cur.buffer[top - 1] > -1) {
114
+ if (start == end)
115
+ return;
116
+ if (cur.buffer[top - 2] >= start) {
117
+ cur.buffer[top - 2] = end;
118
+ return;
119
+ }
120
+ }
121
+ }
122
+ if (!mustSink || this.pos == end) {
123
+ this.buffer.push(term, start, end, size);
124
+ } else {
125
+ let index = this.buffer.length;
126
+ if (index > 0 && (this.buffer[index - 4] != 0 || this.buffer[index - 1] < 0)) {
127
+ let mustMove = false;
128
+ for (let scan = index; scan > 0 && this.buffer[scan - 2] > end; scan -= 4) {
129
+ if (this.buffer[scan - 1] >= 0) {
130
+ mustMove = true;
131
+ break;
132
+ }
133
+ }
134
+ if (mustMove)
135
+ while (index > 0 && this.buffer[index - 2] > end) {
136
+ this.buffer[index] = this.buffer[index - 4];
137
+ this.buffer[index + 1] = this.buffer[index - 3];
138
+ this.buffer[index + 2] = this.buffer[index - 2];
139
+ this.buffer[index + 3] = this.buffer[index - 1];
140
+ index -= 4;
141
+ if (size > 4)
142
+ size -= 4;
143
+ }
144
+ }
145
+ this.buffer[index] = term;
146
+ this.buffer[index + 1] = start;
147
+ this.buffer[index + 2] = end;
148
+ this.buffer[index + 3] = size;
149
+ }
150
+ }
151
+ // Apply a shift action
152
+ /**
153
+ @internal
154
+ */
155
+ shift(action, type, start, end) {
156
+ if (action & 131072) {
157
+ this.pushState(action & 65535, this.pos);
158
+ } else if ((action & 262144) == 0) {
159
+ let nextState = action, { parser } = this.p;
160
+ this.pos = end;
161
+ let skipped = parser.stateFlag(
162
+ nextState,
163
+ 1
164
+ /* StateFlag.Skipped */
165
+ );
166
+ if (!skipped && (end > start || type <= parser.maxNode))
167
+ this.reducePos = end;
168
+ this.pushState(nextState, skipped ? start : Math.min(start, this.reducePos));
169
+ this.shiftContext(type, start);
170
+ if (type <= parser.maxNode)
171
+ this.buffer.push(type, start, end, 4);
172
+ } else {
173
+ this.pos = end;
174
+ this.shiftContext(type, start);
175
+ if (type <= this.p.parser.maxNode)
176
+ this.buffer.push(type, start, end, 4);
177
+ }
178
+ }
179
+ // Apply an action
180
+ /**
181
+ @internal
182
+ */
183
+ apply(action, next, nextStart, nextEnd) {
184
+ if (action & 65536)
185
+ this.reduce(action);
186
+ else
187
+ this.shift(action, next, nextStart, nextEnd);
188
+ }
189
+ // Add a prebuilt (reused) node into the buffer.
190
+ /**
191
+ @internal
192
+ */
193
+ useNode(value, next) {
194
+ let index = this.p.reused.length - 1;
195
+ if (index < 0 || this.p.reused[index] != value) {
196
+ this.p.reused.push(value);
197
+ index++;
198
+ }
199
+ let start = this.pos;
200
+ this.reducePos = this.pos = start + value.length;
201
+ this.pushState(next, start);
202
+ this.buffer.push(
203
+ index,
204
+ start,
205
+ this.reducePos,
206
+ -1
207
+ /* size == -1 means this is a reused value */
208
+ );
209
+ if (this.curContext)
210
+ this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
211
+ }
212
+ // Split the stack. Due to the buffer sharing and the fact
213
+ // that `this.stack` tends to stay quite shallow, this isn't very
214
+ // expensive.
215
+ /**
216
+ @internal
217
+ */
218
+ split() {
219
+ let parent = this;
220
+ let off = parent.buffer.length;
221
+ while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
222
+ off -= 4;
223
+ let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
224
+ while (parent && base == parent.bufferBase)
225
+ parent = parent.parent;
226
+ return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
227
+ }
228
+ // Try to recover from an error by 'deleting' (ignoring) one token.
229
+ /**
230
+ @internal
231
+ */
232
+ recoverByDelete(next, nextEnd) {
233
+ let isNode = next <= this.p.parser.maxNode;
234
+ if (isNode)
235
+ this.storeNode(next, this.pos, nextEnd, 4);
236
+ this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
237
+ this.pos = this.reducePos = nextEnd;
238
+ this.score -= 190;
239
+ }
240
+ /**
241
+ Check if the given term would be able to be shifted (optionally
242
+ after some reductions) on this stack. This can be useful for
243
+ external tokenizers that want to make sure they only provide a
244
+ given token when it applies.
245
+ */
246
+ canShift(term) {
247
+ for (let sim = new SimulatedStack(this); ; ) {
248
+ let action = this.p.parser.stateSlot(
249
+ sim.state,
250
+ 4
251
+ /* ParseState.DefaultReduce */
252
+ ) || this.p.parser.hasAction(sim.state, term);
253
+ if (action == 0)
254
+ return false;
255
+ if ((action & 65536) == 0)
256
+ return true;
257
+ sim.reduce(action);
258
+ }
259
+ }
260
+ // Apply up to Recover.MaxNext recovery actions that conceptually
261
+ // inserts some missing token or rule.
262
+ /**
263
+ @internal
264
+ */
265
+ recoverByInsert(next) {
266
+ if (this.stack.length >= 300)
267
+ return [];
268
+ let nextStates = this.p.parser.nextStates(this.state);
269
+ if (nextStates.length > 4 << 1 || this.stack.length >= 120) {
270
+ let best = [];
271
+ for (let i = 0, s; i < nextStates.length; i += 2) {
272
+ if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
273
+ best.push(nextStates[i], s);
274
+ }
275
+ if (this.stack.length < 120)
276
+ for (let i = 0; best.length < 4 << 1 && i < nextStates.length; i += 2) {
277
+ let s = nextStates[i + 1];
278
+ if (!best.some((v, i2) => i2 & 1 && v == s))
279
+ best.push(nextStates[i], s);
280
+ }
281
+ nextStates = best;
282
+ }
283
+ let result = [];
284
+ for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
285
+ let s = nextStates[i + 1];
286
+ if (s == this.state)
287
+ continue;
288
+ let stack = this.split();
289
+ stack.pushState(s, this.pos);
290
+ stack.storeNode(0, stack.pos, stack.pos, 4, true);
291
+ stack.shiftContext(nextStates[i], this.pos);
292
+ stack.reducePos = this.pos;
293
+ stack.score -= 200;
294
+ result.push(stack);
295
+ }
296
+ return result;
297
+ }
298
+ // Force a reduce, if possible. Return false if that can't
299
+ // be done.
300
+ /**
301
+ @internal
302
+ */
303
+ forceReduce() {
304
+ let { parser } = this.p;
305
+ let reduce = parser.stateSlot(
306
+ this.state,
307
+ 5
308
+ /* ParseState.ForcedReduce */
309
+ );
310
+ if ((reduce & 65536) == 0)
311
+ return false;
312
+ if (!parser.validAction(this.state, reduce)) {
313
+ let depth = reduce >> 19, term = reduce & 65535;
314
+ let target = this.stack.length - depth * 3;
315
+ if (target < 0 || parser.getGoto(this.stack[target], term, false) < 0) {
316
+ let backup = this.findForcedReduction();
317
+ if (backup == null)
318
+ return false;
319
+ reduce = backup;
320
+ }
321
+ this.storeNode(0, this.pos, this.pos, 4, true);
322
+ this.score -= 100;
323
+ }
324
+ this.reducePos = this.pos;
325
+ this.reduce(reduce);
326
+ return true;
327
+ }
328
+ /**
329
+ Try to scan through the automaton to find some kind of reduction
330
+ that can be applied. Used when the regular ForcedReduce field
331
+ isn't a valid action. @internal
332
+ */
333
+ findForcedReduction() {
334
+ let { parser } = this.p, seen = [];
335
+ let explore = (state, depth) => {
336
+ if (seen.includes(state))
337
+ return;
338
+ seen.push(state);
339
+ return parser.allActions(state, (action) => {
340
+ if (action & (262144 | 131072)) ;
341
+ else if (action & 65536) {
342
+ let rDepth = (action >> 19) - depth;
343
+ if (rDepth > 1) {
344
+ let term = action & 65535, target = this.stack.length - rDepth * 3;
345
+ if (target >= 0 && parser.getGoto(this.stack[target], term, false) >= 0)
346
+ return rDepth << 19 | 65536 | term;
347
+ }
348
+ } else {
349
+ let found = explore(action, depth + 1);
350
+ if (found != null)
351
+ return found;
352
+ }
353
+ });
354
+ };
355
+ return explore(this.state, 0);
356
+ }
357
+ /**
358
+ @internal
359
+ */
360
+ forceAll() {
361
+ while (!this.p.parser.stateFlag(
362
+ this.state,
363
+ 2
364
+ /* StateFlag.Accepting */
365
+ )) {
366
+ if (!this.forceReduce()) {
367
+ this.storeNode(0, this.pos, this.pos, 4, true);
368
+ break;
369
+ }
370
+ }
371
+ return this;
372
+ }
373
+ /**
374
+ Check whether this state has no further actions (assumed to be a direct descendant of the
375
+ top state, since any other states must be able to continue
376
+ somehow). @internal
377
+ */
378
+ get deadEnd() {
379
+ if (this.stack.length != 3)
380
+ return false;
381
+ let { parser } = this.p;
382
+ return parser.data[parser.stateSlot(
383
+ this.state,
384
+ 1
385
+ /* ParseState.Actions */
386
+ )] == 65535 && !parser.stateSlot(
387
+ this.state,
388
+ 4
389
+ /* ParseState.DefaultReduce */
390
+ );
391
+ }
392
+ /**
393
+ Restart the stack (put it back in its start state). Only safe
394
+ when this.stack.length == 3 (state is directly below the top
395
+ state). @internal
396
+ */
397
+ restart() {
398
+ this.storeNode(0, this.pos, this.pos, 4, true);
399
+ this.state = this.stack[0];
400
+ this.stack.length = 0;
401
+ }
402
+ /**
403
+ @internal
404
+ */
405
+ sameState(other) {
406
+ if (this.state != other.state || this.stack.length != other.stack.length)
407
+ return false;
408
+ for (let i = 0; i < this.stack.length; i += 3)
409
+ if (this.stack[i] != other.stack[i])
410
+ return false;
411
+ return true;
412
+ }
413
+ /**
414
+ Get the parser used by this stack.
415
+ */
416
+ get parser() {
417
+ return this.p.parser;
418
+ }
419
+ /**
420
+ Test whether a given dialect (by numeric ID, as exported from
421
+ the terms file) is enabled.
422
+ */
423
+ dialectEnabled(dialectID) {
424
+ return this.p.parser.dialect.flags[dialectID];
425
+ }
426
+ shiftContext(term, start) {
427
+ if (this.curContext)
428
+ this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
429
+ }
430
+ reduceContext(term, start) {
431
+ if (this.curContext)
432
+ this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
433
+ }
434
+ /**
435
+ @internal
436
+ */
437
+ emitContext() {
438
+ let last = this.buffer.length - 1;
439
+ if (last < 0 || this.buffer[last] != -3)
440
+ this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
441
+ }
442
+ /**
443
+ @internal
444
+ */
445
+ emitLookAhead() {
446
+ let last = this.buffer.length - 1;
447
+ if (last < 0 || this.buffer[last] != -4)
448
+ this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
449
+ }
450
+ updateContext(context) {
451
+ if (context != this.curContext.context) {
452
+ let newCx = new StackContext(this.curContext.tracker, context);
453
+ if (newCx.hash != this.curContext.hash)
454
+ this.emitContext();
455
+ this.curContext = newCx;
456
+ }
457
+ }
458
+ /**
459
+ @internal
460
+ */
461
+ setLookAhead(lookAhead) {
462
+ if (lookAhead <= this.lookAhead)
463
+ return false;
464
+ this.emitLookAhead();
465
+ this.lookAhead = lookAhead;
466
+ return true;
467
+ }
468
+ /**
469
+ @internal
470
+ */
471
+ close() {
472
+ if (this.curContext && this.curContext.tracker.strict)
473
+ this.emitContext();
474
+ if (this.lookAhead > 0)
475
+ this.emitLookAhead();
476
+ }
477
+ }
478
+ class StackContext {
479
+ constructor(tracker, context) {
480
+ this.tracker = tracker;
481
+ this.context = context;
482
+ this.hash = tracker.strict ? tracker.hash(context) : 0;
483
+ }
484
+ }
485
+ class SimulatedStack {
486
+ constructor(start) {
487
+ this.start = start;
488
+ this.state = start.state;
489
+ this.stack = start.stack;
490
+ this.base = this.stack.length;
491
+ }
492
+ reduce(action) {
493
+ let term = action & 65535, depth = action >> 19;
494
+ if (depth == 0) {
495
+ if (this.stack == this.start.stack)
496
+ this.stack = this.stack.slice();
497
+ this.stack.push(this.state, 0, 0);
498
+ this.base += 3;
499
+ } else {
500
+ this.base -= (depth - 1) * 3;
501
+ }
502
+ let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
503
+ this.state = goto;
504
+ }
505
+ }
506
+ class StackBufferCursor {
507
+ constructor(stack, pos, index) {
508
+ this.stack = stack;
509
+ this.pos = pos;
510
+ this.index = index;
511
+ this.buffer = stack.buffer;
512
+ if (this.index == 0)
513
+ this.maybeNext();
514
+ }
515
+ static create(stack, pos = stack.bufferBase + stack.buffer.length) {
516
+ return new StackBufferCursor(stack, pos, pos - stack.bufferBase);
517
+ }
518
+ maybeNext() {
519
+ let next = this.stack.parent;
520
+ if (next != null) {
521
+ this.index = this.stack.bufferBase - next.bufferBase;
522
+ this.stack = next;
523
+ this.buffer = next.buffer;
524
+ }
525
+ }
526
+ get id() {
527
+ return this.buffer[this.index - 4];
528
+ }
529
+ get start() {
530
+ return this.buffer[this.index - 3];
531
+ }
532
+ get end() {
533
+ return this.buffer[this.index - 2];
534
+ }
535
+ get size() {
536
+ return this.buffer[this.index - 1];
537
+ }
538
+ next() {
539
+ this.index -= 4;
540
+ this.pos -= 4;
541
+ if (this.index == 0)
542
+ this.maybeNext();
543
+ }
544
+ fork() {
545
+ return new StackBufferCursor(this.stack, this.pos, this.index);
546
+ }
547
+ }
548
+ function decodeArray(input, Type = Uint16Array) {
549
+ if (typeof input != "string")
550
+ return input;
551
+ let array = null;
552
+ for (let pos = 0, out = 0; pos < input.length; ) {
553
+ let value = 0;
554
+ for (; ; ) {
555
+ let next = input.charCodeAt(pos++), stop = false;
556
+ if (next == 126) {
557
+ value = 65535;
558
+ break;
559
+ }
560
+ if (next >= 92)
561
+ next--;
562
+ if (next >= 34)
563
+ next--;
564
+ let digit = next - 32;
565
+ if (digit >= 46) {
566
+ digit -= 46;
567
+ stop = true;
568
+ }
569
+ value += digit;
570
+ if (stop)
571
+ break;
572
+ value *= 46;
573
+ }
574
+ if (array)
575
+ array[out++] = value;
576
+ else
577
+ array = new Type(value);
578
+ }
579
+ return array;
580
+ }
581
+ class CachedToken {
582
+ constructor() {
583
+ this.start = -1;
584
+ this.value = -1;
585
+ this.end = -1;
586
+ this.extended = -1;
587
+ this.lookAhead = 0;
588
+ this.mask = 0;
589
+ this.context = 0;
590
+ }
591
+ }
592
+ const nullToken = new CachedToken();
593
+ class InputStream {
594
+ /**
595
+ @internal
596
+ */
597
+ constructor(input, ranges) {
598
+ this.input = input;
599
+ this.ranges = ranges;
600
+ this.chunk = "";
601
+ this.chunkOff = 0;
602
+ this.chunk2 = "";
603
+ this.chunk2Pos = 0;
604
+ this.next = -1;
605
+ this.token = nullToken;
606
+ this.rangeIndex = 0;
607
+ this.pos = this.chunkPos = ranges[0].from;
608
+ this.range = ranges[0];
609
+ this.end = ranges[ranges.length - 1].to;
610
+ this.readNext();
611
+ }
612
+ /**
613
+ @internal
614
+ */
615
+ resolveOffset(offset, assoc) {
616
+ let range = this.range, index = this.rangeIndex;
617
+ let pos = this.pos + offset;
618
+ while (pos < range.from) {
619
+ if (!index)
620
+ return null;
621
+ let next = this.ranges[--index];
622
+ pos -= range.from - next.to;
623
+ range = next;
624
+ }
625
+ while (assoc < 0 ? pos > range.to : pos >= range.to) {
626
+ if (index == this.ranges.length - 1)
627
+ return null;
628
+ let next = this.ranges[++index];
629
+ pos += next.from - range.to;
630
+ range = next;
631
+ }
632
+ return pos;
633
+ }
634
+ /**
635
+ @internal
636
+ */
637
+ clipPos(pos) {
638
+ if (pos >= this.range.from && pos < this.range.to)
639
+ return pos;
640
+ for (let range of this.ranges)
641
+ if (range.to > pos)
642
+ return Math.max(pos, range.from);
643
+ return this.end;
644
+ }
645
+ /**
646
+ Look at a code unit near the stream position. `.peek(0)` equals
647
+ `.next`, `.peek(-1)` gives you the previous character, and so
648
+ on.
649
+
650
+ Note that looking around during tokenizing creates dependencies
651
+ on potentially far-away content, which may reduce the
652
+ effectiveness incremental parsing—when looking forward—or even
653
+ cause invalid reparses when looking backward more than 25 code
654
+ units, since the library does not track lookbehind.
655
+ */
656
+ peek(offset) {
657
+ let idx = this.chunkOff + offset, pos, result;
658
+ if (idx >= 0 && idx < this.chunk.length) {
659
+ pos = this.pos + offset;
660
+ result = this.chunk.charCodeAt(idx);
661
+ } else {
662
+ let resolved = this.resolveOffset(offset, 1);
663
+ if (resolved == null)
664
+ return -1;
665
+ pos = resolved;
666
+ if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
667
+ result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
668
+ } else {
669
+ let i = this.rangeIndex, range = this.range;
670
+ while (range.to <= pos)
671
+ range = this.ranges[++i];
672
+ this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
673
+ if (pos + this.chunk2.length > range.to)
674
+ this.chunk2 = this.chunk2.slice(0, range.to - pos);
675
+ result = this.chunk2.charCodeAt(0);
676
+ }
677
+ }
678
+ if (pos >= this.token.lookAhead)
679
+ this.token.lookAhead = pos + 1;
680
+ return result;
681
+ }
682
+ /**
683
+ Accept a token. By default, the end of the token is set to the
684
+ current stream position, but you can pass an offset (relative to
685
+ the stream position) to change that.
686
+ */
687
+ acceptToken(token, endOffset = 0) {
688
+ let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
689
+ if (end == null || end < this.token.start)
690
+ throw new RangeError("Token end out of bounds");
691
+ this.token.value = token;
692
+ this.token.end = end;
693
+ }
694
+ /**
695
+ Accept a token ending at a specific given position.
696
+ */
697
+ acceptTokenTo(token, endPos) {
698
+ this.token.value = token;
699
+ this.token.end = endPos;
700
+ }
701
+ getChunk() {
702
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
703
+ let { chunk, chunkPos } = this;
704
+ this.chunk = this.chunk2;
705
+ this.chunkPos = this.chunk2Pos;
706
+ this.chunk2 = chunk;
707
+ this.chunk2Pos = chunkPos;
708
+ this.chunkOff = this.pos - this.chunkPos;
709
+ } else {
710
+ this.chunk2 = this.chunk;
711
+ this.chunk2Pos = this.chunkPos;
712
+ let nextChunk = this.input.chunk(this.pos);
713
+ let end = this.pos + nextChunk.length;
714
+ this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
715
+ this.chunkPos = this.pos;
716
+ this.chunkOff = 0;
717
+ }
718
+ }
719
+ readNext() {
720
+ if (this.chunkOff >= this.chunk.length) {
721
+ this.getChunk();
722
+ if (this.chunkOff == this.chunk.length)
723
+ return this.next = -1;
724
+ }
725
+ return this.next = this.chunk.charCodeAt(this.chunkOff);
726
+ }
727
+ /**
728
+ Move the stream forward N (defaults to 1) code units. Returns
729
+ the new value of [`next`](#lr.InputStream.next).
730
+ */
731
+ advance(n = 1) {
732
+ this.chunkOff += n;
733
+ while (this.pos + n >= this.range.to) {
734
+ if (this.rangeIndex == this.ranges.length - 1)
735
+ return this.setDone();
736
+ n -= this.range.to - this.pos;
737
+ this.range = this.ranges[++this.rangeIndex];
738
+ this.pos = this.range.from;
739
+ }
740
+ this.pos += n;
741
+ if (this.pos >= this.token.lookAhead)
742
+ this.token.lookAhead = this.pos + 1;
743
+ return this.readNext();
744
+ }
745
+ setDone() {
746
+ this.pos = this.chunkPos = this.end;
747
+ this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
748
+ this.chunk = "";
749
+ return this.next = -1;
750
+ }
751
+ /**
752
+ @internal
753
+ */
754
+ reset(pos, token) {
755
+ if (token) {
756
+ this.token = token;
757
+ token.start = pos;
758
+ token.lookAhead = pos + 1;
759
+ token.value = token.extended = -1;
760
+ } else {
761
+ this.token = nullToken;
762
+ }
763
+ if (this.pos != pos) {
764
+ this.pos = pos;
765
+ if (pos == this.end) {
766
+ this.setDone();
767
+ return this;
768
+ }
769
+ while (pos < this.range.from)
770
+ this.range = this.ranges[--this.rangeIndex];
771
+ while (pos >= this.range.to)
772
+ this.range = this.ranges[++this.rangeIndex];
773
+ if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
774
+ this.chunkOff = pos - this.chunkPos;
775
+ } else {
776
+ this.chunk = "";
777
+ this.chunkOff = 0;
778
+ }
779
+ this.readNext();
780
+ }
781
+ return this;
782
+ }
783
+ /**
784
+ @internal
785
+ */
786
+ read(from, to) {
787
+ if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
788
+ return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
789
+ if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
790
+ return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
791
+ if (from >= this.range.from && to <= this.range.to)
792
+ return this.input.read(from, to);
793
+ let result = "";
794
+ for (let r of this.ranges) {
795
+ if (r.from >= to)
796
+ break;
797
+ if (r.to > from)
798
+ result += this.input.read(Math.max(r.from, from), Math.min(r.to, to));
799
+ }
800
+ return result;
801
+ }
802
+ }
803
+ class TokenGroup {
804
+ constructor(data, id2) {
805
+ this.data = data;
806
+ this.id = id2;
807
+ }
808
+ token(input, stack) {
809
+ let { parser } = stack.p;
810
+ readToken(this.data, input, stack, this.id, parser.data, parser.tokenPrecTable);
811
+ }
812
+ }
813
+ TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
814
+ class LocalTokenGroup {
815
+ constructor(data, precTable, elseToken) {
816
+ this.precTable = precTable;
817
+ this.elseToken = elseToken;
818
+ this.data = typeof data == "string" ? decodeArray(data) : data;
819
+ }
820
+ token(input, stack) {
821
+ let start = input.pos, skipped = 0;
822
+ for (; ; ) {
823
+ let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1);
824
+ readToken(this.data, input, stack, 0, this.data, this.precTable);
825
+ if (input.token.value > -1)
826
+ break;
827
+ if (this.elseToken == null)
828
+ return;
829
+ if (!atEof)
830
+ skipped++;
831
+ if (nextPos == null)
832
+ break;
833
+ input.reset(nextPos, input.token);
834
+ }
835
+ if (skipped) {
836
+ input.reset(start, input.token);
837
+ input.acceptToken(this.elseToken, skipped);
838
+ }
839
+ }
840
+ }
841
+ LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
842
+ class ExternalTokenizer {
843
+ /**
844
+ Create a tokenizer. The first argument is the function that,
845
+ given an input stream, scans for the types of tokens it
846
+ recognizes at the stream's position, and calls
847
+ [`acceptToken`](#lr.InputStream.acceptToken) when it finds
848
+ one.
849
+ */
850
+ constructor(token, options = {}) {
851
+ this.token = token;
852
+ this.contextual = !!options.contextual;
853
+ this.fallback = !!options.fallback;
854
+ this.extend = !!options.extend;
855
+ }
856
+ }
857
+ function readToken(data, input, stack, group, precTable, precOffset) {
858
+ let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
859
+ scan: for (; ; ) {
860
+ if ((groupMask & data[state]) == 0)
861
+ break;
862
+ let accEnd = data[state + 1];
863
+ for (let i = state + 3; i < accEnd; i += 2)
864
+ if ((data[i + 1] & groupMask) > 0) {
865
+ let term = data[i];
866
+ if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
867
+ input.acceptToken(term);
868
+ break;
869
+ }
870
+ }
871
+ let next = input.next, low = 0, high = data[state + 2];
872
+ if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535) {
873
+ state = data[accEnd + high * 3 - 1];
874
+ continue scan;
875
+ }
876
+ for (; low < high; ) {
877
+ let mid = low + high >> 1;
878
+ let index = accEnd + mid + (mid << 1);
879
+ let from = data[index], to = data[index + 1] || 65536;
880
+ if (next < from)
881
+ high = mid;
882
+ else if (next >= to)
883
+ low = mid + 1;
884
+ else {
885
+ state = data[index + 2];
886
+ input.advance();
887
+ continue scan;
888
+ }
889
+ }
890
+ break;
891
+ }
892
+ }
893
+ function findOffset(data, start, term) {
894
+ for (let i = start, next; (next = data[i]) != 65535; i++)
895
+ if (next == term)
896
+ return i - start;
897
+ return -1;
898
+ }
899
+ function overrides(token, prev, tableData, tableOffset) {
900
+ let iPrev = findOffset(tableData, tableOffset, prev);
901
+ return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
902
+ }
903
+ const verbose = typeof process != "undefined" && define_process_env_default && /\bparse\b/.test(define_process_env_default.LOG);
904
+ let stackIDs = null;
905
+ function cutAt(tree, pos, side) {
906
+ let cursor = tree.cursor(IterMode.IncludeAnonymous);
907
+ cursor.moveTo(pos);
908
+ for (; ; ) {
909
+ if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
910
+ for (; ; ) {
911
+ if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
912
+ return side < 0 ? Math.max(0, Math.min(
913
+ cursor.to - 1,
914
+ pos - 25
915
+ /* Lookahead.Margin */
916
+ )) : Math.min(tree.length, Math.max(
917
+ cursor.from + 1,
918
+ pos + 25
919
+ /* Lookahead.Margin */
920
+ ));
921
+ if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
922
+ break;
923
+ if (!cursor.parent())
924
+ return side < 0 ? 0 : tree.length;
925
+ }
926
+ }
927
+ }
928
+ class FragmentCursor {
929
+ constructor(fragments, nodeSet) {
930
+ this.fragments = fragments;
931
+ this.nodeSet = nodeSet;
932
+ this.i = 0;
933
+ this.fragment = null;
934
+ this.safeFrom = -1;
935
+ this.safeTo = -1;
936
+ this.trees = [];
937
+ this.start = [];
938
+ this.index = [];
939
+ this.nextFragment();
940
+ }
941
+ nextFragment() {
942
+ let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
943
+ if (fr) {
944
+ this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
945
+ this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
946
+ while (this.trees.length) {
947
+ this.trees.pop();
948
+ this.start.pop();
949
+ this.index.pop();
950
+ }
951
+ this.trees.push(fr.tree);
952
+ this.start.push(-fr.offset);
953
+ this.index.push(0);
954
+ this.nextStart = this.safeFrom;
955
+ } else {
956
+ this.nextStart = 1e9;
957
+ }
958
+ }
959
+ // `pos` must be >= any previously given `pos` for this cursor
960
+ nodeAt(pos) {
961
+ if (pos < this.nextStart)
962
+ return null;
963
+ while (this.fragment && this.safeTo <= pos)
964
+ this.nextFragment();
965
+ if (!this.fragment)
966
+ return null;
967
+ for (; ; ) {
968
+ let last = this.trees.length - 1;
969
+ if (last < 0) {
970
+ this.nextFragment();
971
+ return null;
972
+ }
973
+ let top = this.trees[last], index = this.index[last];
974
+ if (index == top.children.length) {
975
+ this.trees.pop();
976
+ this.start.pop();
977
+ this.index.pop();
978
+ continue;
979
+ }
980
+ let next = top.children[index];
981
+ let start = this.start[last] + top.positions[index];
982
+ if (start > pos) {
983
+ this.nextStart = start;
984
+ return null;
985
+ }
986
+ if (next instanceof Tree) {
987
+ if (start == pos) {
988
+ if (start < this.safeFrom)
989
+ return null;
990
+ let end = start + next.length;
991
+ if (end <= this.safeTo) {
992
+ let lookAhead = next.prop(NodeProp.lookAhead);
993
+ if (!lookAhead || end + lookAhead < this.fragment.to)
994
+ return next;
995
+ }
996
+ }
997
+ this.index[last]++;
998
+ if (start + next.length >= Math.max(this.safeFrom, pos)) {
999
+ this.trees.push(next);
1000
+ this.start.push(start);
1001
+ this.index.push(0);
1002
+ }
1003
+ } else {
1004
+ this.index[last]++;
1005
+ this.nextStart = start + next.length;
1006
+ }
1007
+ }
1008
+ }
1009
+ }
1010
+ class TokenCache {
1011
+ constructor(parser, stream) {
1012
+ this.stream = stream;
1013
+ this.tokens = [];
1014
+ this.mainToken = null;
1015
+ this.actions = [];
1016
+ this.tokens = parser.tokenizers.map((_) => new CachedToken());
1017
+ }
1018
+ getActions(stack) {
1019
+ let actionIndex = 0;
1020
+ let main = null;
1021
+ let { parser } = stack.p, { tokenizers } = parser;
1022
+ let mask = parser.stateSlot(
1023
+ stack.state,
1024
+ 3
1025
+ /* ParseState.TokenizerMask */
1026
+ );
1027
+ let context = stack.curContext ? stack.curContext.hash : 0;
1028
+ let lookAhead = 0;
1029
+ for (let i = 0; i < tokenizers.length; i++) {
1030
+ if ((1 << i & mask) == 0)
1031
+ continue;
1032
+ let tokenizer = tokenizers[i], token = this.tokens[i];
1033
+ if (main && !tokenizer.fallback)
1034
+ continue;
1035
+ if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
1036
+ this.updateCachedToken(token, tokenizer, stack);
1037
+ token.mask = mask;
1038
+ token.context = context;
1039
+ }
1040
+ if (token.lookAhead > token.end + 25)
1041
+ lookAhead = Math.max(token.lookAhead, lookAhead);
1042
+ if (token.value != 0) {
1043
+ let startIndex = actionIndex;
1044
+ if (token.extended > -1)
1045
+ actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
1046
+ actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
1047
+ if (!tokenizer.extend) {
1048
+ main = token;
1049
+ if (actionIndex > startIndex)
1050
+ break;
1051
+ }
1052
+ }
1053
+ }
1054
+ while (this.actions.length > actionIndex)
1055
+ this.actions.pop();
1056
+ if (lookAhead)
1057
+ stack.setLookAhead(lookAhead);
1058
+ if (!main && stack.pos == this.stream.end) {
1059
+ main = new CachedToken();
1060
+ main.value = stack.p.parser.eofTerm;
1061
+ main.start = main.end = stack.pos;
1062
+ actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
1063
+ }
1064
+ this.mainToken = main;
1065
+ return this.actions;
1066
+ }
1067
+ getMainToken(stack) {
1068
+ if (this.mainToken)
1069
+ return this.mainToken;
1070
+ let main = new CachedToken(), { pos, p } = stack;
1071
+ main.start = pos;
1072
+ main.end = Math.min(pos + 1, p.stream.end);
1073
+ main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
1074
+ return main;
1075
+ }
1076
+ updateCachedToken(token, tokenizer, stack) {
1077
+ let start = this.stream.clipPos(stack.pos);
1078
+ tokenizer.token(this.stream.reset(start, token), stack);
1079
+ if (token.value > -1) {
1080
+ let { parser } = stack.p;
1081
+ for (let i = 0; i < parser.specialized.length; i++)
1082
+ if (parser.specialized[i] == token.value) {
1083
+ let result = parser.specializers[i](this.stream.read(token.start, token.end), stack);
1084
+ if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
1085
+ if ((result & 1) == 0)
1086
+ token.value = result >> 1;
1087
+ else
1088
+ token.extended = result >> 1;
1089
+ break;
1090
+ }
1091
+ }
1092
+ } else {
1093
+ token.value = 0;
1094
+ token.end = this.stream.clipPos(start + 1);
1095
+ }
1096
+ }
1097
+ putAction(action, token, end, index) {
1098
+ for (let i = 0; i < index; i += 3)
1099
+ if (this.actions[i] == action)
1100
+ return index;
1101
+ this.actions[index++] = action;
1102
+ this.actions[index++] = token;
1103
+ this.actions[index++] = end;
1104
+ return index;
1105
+ }
1106
+ addActions(stack, token, end, index) {
1107
+ let { state } = stack, { parser } = stack.p, { data } = parser;
1108
+ for (let set = 0; set < 2; set++) {
1109
+ for (let i = parser.stateSlot(
1110
+ state,
1111
+ set ? 2 : 1
1112
+ /* ParseState.Actions */
1113
+ ); ; i += 3) {
1114
+ if (data[i] == 65535) {
1115
+ if (data[i + 1] == 1) {
1116
+ i = pair(data, i + 2);
1117
+ } else {
1118
+ if (index == 0 && data[i + 1] == 2)
1119
+ index = this.putAction(pair(data, i + 2), token, end, index);
1120
+ break;
1121
+ }
1122
+ }
1123
+ if (data[i] == token)
1124
+ index = this.putAction(pair(data, i + 1), token, end, index);
1125
+ }
1126
+ }
1127
+ return index;
1128
+ }
1129
+ }
1130
+ class Parse {
1131
+ constructor(parser, input, fragments, ranges) {
1132
+ this.parser = parser;
1133
+ this.input = input;
1134
+ this.ranges = ranges;
1135
+ this.recovering = 0;
1136
+ this.nextStackID = 9812;
1137
+ this.minStackPos = 0;
1138
+ this.reused = [];
1139
+ this.stoppedAt = null;
1140
+ this.lastBigReductionStart = -1;
1141
+ this.lastBigReductionSize = 0;
1142
+ this.bigReductionCount = 0;
1143
+ this.stream = new InputStream(input, ranges);
1144
+ this.tokens = new TokenCache(parser, this.stream);
1145
+ this.topTerm = parser.top[1];
1146
+ let { from } = ranges[0];
1147
+ this.stacks = [Stack.start(this, parser.top[0], from)];
1148
+ this.fragments = fragments.length && this.stream.end - from > parser.bufferLength * 4 ? new FragmentCursor(fragments, parser.nodeSet) : null;
1149
+ }
1150
+ get parsedPos() {
1151
+ return this.minStackPos;
1152
+ }
1153
+ // Move the parser forward. This will process all parse stacks at
1154
+ // `this.pos` and try to advance them to a further position. If no
1155
+ // stack for such a position is found, it'll start error-recovery.
1156
+ //
1157
+ // When the parse is finished, this will return a syntax tree. When
1158
+ // not, it returns `null`.
1159
+ advance() {
1160
+ let stacks = this.stacks, pos = this.minStackPos;
1161
+ let newStacks = this.stacks = [];
1162
+ let stopped, stoppedTokens;
1163
+ if (this.bigReductionCount > 300 && stacks.length == 1) {
1164
+ let [s] = stacks;
1165
+ while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) {
1166
+ }
1167
+ this.bigReductionCount = this.lastBigReductionSize = 0;
1168
+ }
1169
+ for (let i = 0; i < stacks.length; i++) {
1170
+ let stack = stacks[i];
1171
+ for (; ; ) {
1172
+ this.tokens.mainToken = null;
1173
+ if (stack.pos > pos) {
1174
+ newStacks.push(stack);
1175
+ } else if (this.advanceStack(stack, newStacks, stacks)) {
1176
+ continue;
1177
+ } else {
1178
+ if (!stopped) {
1179
+ stopped = [];
1180
+ stoppedTokens = [];
1181
+ }
1182
+ stopped.push(stack);
1183
+ let tok = this.tokens.getMainToken(stack);
1184
+ stoppedTokens.push(tok.value, tok.end);
1185
+ }
1186
+ break;
1187
+ }
1188
+ }
1189
+ if (!newStacks.length) {
1190
+ let finished = stopped && findFinished(stopped);
1191
+ if (finished) {
1192
+ if (verbose)
1193
+ console.log("Finish with " + this.stackID(finished));
1194
+ return this.stackToTree(finished);
1195
+ }
1196
+ if (this.parser.strict) {
1197
+ if (verbose && stopped)
1198
+ console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
1199
+ throw new SyntaxError("No parse at " + pos);
1200
+ }
1201
+ if (!this.recovering)
1202
+ this.recovering = 5;
1203
+ }
1204
+ if (this.recovering && stopped) {
1205
+ let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
1206
+ if (finished) {
1207
+ if (verbose)
1208
+ console.log("Force-finish " + this.stackID(finished));
1209
+ return this.stackToTree(finished.forceAll());
1210
+ }
1211
+ }
1212
+ if (this.recovering) {
1213
+ let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
1214
+ if (newStacks.length > maxRemaining) {
1215
+ newStacks.sort((a, b) => b.score - a.score);
1216
+ while (newStacks.length > maxRemaining)
1217
+ newStacks.pop();
1218
+ }
1219
+ if (newStacks.some((s) => s.reducePos > pos))
1220
+ this.recovering--;
1221
+ } else if (newStacks.length > 1) {
1222
+ outer: for (let i = 0; i < newStacks.length - 1; i++) {
1223
+ let stack = newStacks[i];
1224
+ for (let j = i + 1; j < newStacks.length; j++) {
1225
+ let other = newStacks[j];
1226
+ if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) {
1227
+ if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) {
1228
+ newStacks.splice(j--, 1);
1229
+ } else {
1230
+ newStacks.splice(i--, 1);
1231
+ continue outer;
1232
+ }
1233
+ }
1234
+ }
1235
+ }
1236
+ if (newStacks.length > 12) {
1237
+ newStacks.sort((a, b) => b.score - a.score);
1238
+ newStacks.splice(
1239
+ 12,
1240
+ newStacks.length - 12
1241
+ /* Rec.MaxStackCount */
1242
+ );
1243
+ }
1244
+ }
1245
+ this.minStackPos = newStacks[0].pos;
1246
+ for (let i = 1; i < newStacks.length; i++)
1247
+ if (newStacks[i].pos < this.minStackPos)
1248
+ this.minStackPos = newStacks[i].pos;
1249
+ return null;
1250
+ }
1251
+ stopAt(pos) {
1252
+ if (this.stoppedAt != null && this.stoppedAt < pos)
1253
+ throw new RangeError("Can't move stoppedAt forward");
1254
+ this.stoppedAt = pos;
1255
+ }
1256
+ // Returns an updated version of the given stack, or null if the
1257
+ // stack can't advance normally. When `split` and `stacks` are
1258
+ // given, stacks split off by ambiguous operations will be pushed to
1259
+ // `split`, or added to `stacks` if they move `pos` forward.
1260
+ advanceStack(stack, stacks, split) {
1261
+ let start = stack.pos, { parser } = this;
1262
+ let base = verbose ? this.stackID(stack) + " -> " : "";
1263
+ if (this.stoppedAt != null && start > this.stoppedAt)
1264
+ return stack.forceReduce() ? stack : null;
1265
+ if (this.fragments) {
1266
+ let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
1267
+ for (let cached = this.fragments.nodeAt(start); cached; ) {
1268
+ let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser.getGoto(stack.state, cached.type.id) : -1;
1269
+ if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
1270
+ stack.useNode(cached, match);
1271
+ if (verbose)
1272
+ console.log(base + this.stackID(stack) + ` (via reuse of ${parser.getName(cached.type.id)})`);
1273
+ return true;
1274
+ }
1275
+ if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
1276
+ break;
1277
+ let inner = cached.children[0];
1278
+ if (inner instanceof Tree && cached.positions[0] == 0)
1279
+ cached = inner;
1280
+ else
1281
+ break;
1282
+ }
1283
+ }
1284
+ let defaultReduce = parser.stateSlot(
1285
+ stack.state,
1286
+ 4
1287
+ /* ParseState.DefaultReduce */
1288
+ );
1289
+ if (defaultReduce > 0) {
1290
+ stack.reduce(defaultReduce);
1291
+ if (verbose)
1292
+ console.log(base + this.stackID(stack) + ` (via always-reduce ${parser.getName(
1293
+ defaultReduce & 65535
1294
+ /* Action.ValueMask */
1295
+ )})`);
1296
+ return true;
1297
+ }
1298
+ if (stack.stack.length >= 8400) {
1299
+ while (stack.stack.length > 6e3 && stack.forceReduce()) {
1300
+ }
1301
+ }
1302
+ let actions = this.tokens.getActions(stack);
1303
+ for (let i = 0; i < actions.length; ) {
1304
+ let action = actions[i++], term = actions[i++], end = actions[i++];
1305
+ let last = i == actions.length || !split;
1306
+ let localStack = last ? stack : stack.split();
1307
+ let main = this.tokens.mainToken;
1308
+ localStack.apply(action, term, main ? main.start : localStack.pos, end);
1309
+ if (verbose)
1310
+ console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser.getName(
1311
+ action & 65535
1312
+ /* Action.ValueMask */
1313
+ )}`} for ${parser.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
1314
+ if (last)
1315
+ return true;
1316
+ else if (localStack.pos > start)
1317
+ stacks.push(localStack);
1318
+ else
1319
+ split.push(localStack);
1320
+ }
1321
+ return false;
1322
+ }
1323
+ // Advance a given stack forward as far as it will go. Returns the
1324
+ // (possibly updated) stack if it got stuck, or null if it moved
1325
+ // forward and was given to `pushStackDedup`.
1326
+ advanceFully(stack, newStacks) {
1327
+ let pos = stack.pos;
1328
+ for (; ; ) {
1329
+ if (!this.advanceStack(stack, null, null))
1330
+ return false;
1331
+ if (stack.pos > pos) {
1332
+ pushStackDedup(stack, newStacks);
1333
+ return true;
1334
+ }
1335
+ }
1336
+ }
1337
+ runRecovery(stacks, tokens, newStacks) {
1338
+ let finished = null, restarted = false;
1339
+ for (let i = 0; i < stacks.length; i++) {
1340
+ let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
1341
+ let base = verbose ? this.stackID(stack) + " -> " : "";
1342
+ if (stack.deadEnd) {
1343
+ if (restarted)
1344
+ continue;
1345
+ restarted = true;
1346
+ stack.restart();
1347
+ if (verbose)
1348
+ console.log(base + this.stackID(stack) + " (restarted)");
1349
+ let done = this.advanceFully(stack, newStacks);
1350
+ if (done)
1351
+ continue;
1352
+ }
1353
+ let force = stack.split(), forceBase = base;
1354
+ for (let j = 0; j < 10 && force.forceReduce(); j++) {
1355
+ if (verbose)
1356
+ console.log(forceBase + this.stackID(force) + " (via force-reduce)");
1357
+ let done = this.advanceFully(force, newStacks);
1358
+ if (done)
1359
+ break;
1360
+ if (verbose)
1361
+ forceBase = this.stackID(force) + " -> ";
1362
+ }
1363
+ for (let insert of stack.recoverByInsert(token)) {
1364
+ if (verbose)
1365
+ console.log(base + this.stackID(insert) + " (via recover-insert)");
1366
+ this.advanceFully(insert, newStacks);
1367
+ }
1368
+ if (this.stream.end > stack.pos) {
1369
+ if (tokenEnd == stack.pos) {
1370
+ tokenEnd++;
1371
+ token = 0;
1372
+ }
1373
+ stack.recoverByDelete(token, tokenEnd);
1374
+ if (verbose)
1375
+ console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
1376
+ pushStackDedup(stack, newStacks);
1377
+ } else if (!finished || finished.score < force.score) {
1378
+ finished = force;
1379
+ }
1380
+ }
1381
+ return finished;
1382
+ }
1383
+ // Convert the stack's buffer to a syntax tree.
1384
+ stackToTree(stack) {
1385
+ stack.close();
1386
+ return Tree.build({
1387
+ buffer: StackBufferCursor.create(stack),
1388
+ nodeSet: this.parser.nodeSet,
1389
+ topID: this.topTerm,
1390
+ maxBufferLength: this.parser.bufferLength,
1391
+ reused: this.reused,
1392
+ start: this.ranges[0].from,
1393
+ length: stack.pos - this.ranges[0].from,
1394
+ minRepeatType: this.parser.minRepeatTerm
1395
+ });
1396
+ }
1397
+ stackID(stack) {
1398
+ let id2 = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
1399
+ if (!id2)
1400
+ stackIDs.set(stack, id2 = String.fromCodePoint(this.nextStackID++));
1401
+ return id2 + stack;
1402
+ }
1403
+ }
1404
+ function pushStackDedup(stack, newStacks) {
1405
+ for (let i = 0; i < newStacks.length; i++) {
1406
+ let other = newStacks[i];
1407
+ if (other.pos == stack.pos && other.sameState(stack)) {
1408
+ if (newStacks[i].score < stack.score)
1409
+ newStacks[i] = stack;
1410
+ return;
1411
+ }
1412
+ }
1413
+ newStacks.push(stack);
1414
+ }
1415
+ class Dialect {
1416
+ constructor(source, flags, disabled) {
1417
+ this.source = source;
1418
+ this.flags = flags;
1419
+ this.disabled = disabled;
1420
+ }
1421
+ allows(term) {
1422
+ return !this.disabled || this.disabled[term] == 0;
1423
+ }
1424
+ }
1425
+ const id = (x) => x;
1426
+ class ContextTracker {
1427
+ /**
1428
+ Define a context tracker.
1429
+ */
1430
+ constructor(spec) {
1431
+ this.start = spec.start;
1432
+ this.shift = spec.shift || id;
1433
+ this.reduce = spec.reduce || id;
1434
+ this.reuse = spec.reuse || id;
1435
+ this.hash = spec.hash || (() => 0);
1436
+ this.strict = spec.strict !== false;
1437
+ }
1438
+ }
1439
+ class LRParser extends Parser {
1440
+ /**
1441
+ @internal
1442
+ */
1443
+ constructor(spec) {
1444
+ super();
1445
+ this.wrappers = [];
1446
+ if (spec.version != 14)
1447
+ throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);
1448
+ let nodeNames = spec.nodeNames.split(" ");
1449
+ this.minRepeatTerm = nodeNames.length;
1450
+ for (let i = 0; i < spec.repeatNodeCount; i++)
1451
+ nodeNames.push("");
1452
+ let topTerms = Object.keys(spec.topRules).map((r) => spec.topRules[r][1]);
1453
+ let nodeProps = [];
1454
+ for (let i = 0; i < nodeNames.length; i++)
1455
+ nodeProps.push([]);
1456
+ function setProp(nodeID, prop, value) {
1457
+ nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
1458
+ }
1459
+ if (spec.nodeProps)
1460
+ for (let propSpec of spec.nodeProps) {
1461
+ let prop = propSpec[0];
1462
+ if (typeof prop == "string")
1463
+ prop = NodeProp[prop];
1464
+ for (let i = 1; i < propSpec.length; ) {
1465
+ let next = propSpec[i++];
1466
+ if (next >= 0) {
1467
+ setProp(next, prop, propSpec[i++]);
1468
+ } else {
1469
+ let value = propSpec[i + -next];
1470
+ for (let j = -next; j > 0; j--)
1471
+ setProp(propSpec[i++], prop, value);
1472
+ i++;
1473
+ }
1474
+ }
1475
+ }
1476
+ this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
1477
+ name: i >= this.minRepeatTerm ? void 0 : name,
1478
+ id: i,
1479
+ props: nodeProps[i],
1480
+ top: topTerms.indexOf(i) > -1,
1481
+ error: i == 0,
1482
+ skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
1483
+ })));
1484
+ if (spec.propSources)
1485
+ this.nodeSet = this.nodeSet.extend(...spec.propSources);
1486
+ this.strict = false;
1487
+ this.bufferLength = DefaultBufferLength;
1488
+ let tokenArray = decodeArray(spec.tokenData);
1489
+ this.context = spec.context;
1490
+ this.specializerSpecs = spec.specialized || [];
1491
+ this.specialized = new Uint16Array(this.specializerSpecs.length);
1492
+ for (let i = 0; i < this.specializerSpecs.length; i++)
1493
+ this.specialized[i] = this.specializerSpecs[i].term;
1494
+ this.specializers = this.specializerSpecs.map(getSpecializer);
1495
+ this.states = decodeArray(spec.states, Uint32Array);
1496
+ this.data = decodeArray(spec.stateData);
1497
+ this.goto = decodeArray(spec.goto);
1498
+ this.maxTerm = spec.maxTerm;
1499
+ this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
1500
+ this.topRules = spec.topRules;
1501
+ this.dialects = spec.dialects || {};
1502
+ this.dynamicPrecedences = spec.dynamicPrecedences || null;
1503
+ this.tokenPrecTable = spec.tokenPrec;
1504
+ this.termNames = spec.termNames || null;
1505
+ this.maxNode = this.nodeSet.types.length - 1;
1506
+ this.dialect = this.parseDialect();
1507
+ this.top = this.topRules[Object.keys(this.topRules)[0]];
1508
+ }
1509
+ createParse(input, fragments, ranges) {
1510
+ let parse = new Parse(this, input, fragments, ranges);
1511
+ for (let w of this.wrappers)
1512
+ parse = w(parse, input, fragments, ranges);
1513
+ return parse;
1514
+ }
1515
+ /**
1516
+ Get a goto table entry @internal
1517
+ */
1518
+ getGoto(state, term, loose = false) {
1519
+ let table = this.goto;
1520
+ if (term >= table[0])
1521
+ return -1;
1522
+ for (let pos = table[term + 1]; ; ) {
1523
+ let groupTag = table[pos++], last = groupTag & 1;
1524
+ let target = table[pos++];
1525
+ if (last && loose)
1526
+ return target;
1527
+ for (let end = pos + (groupTag >> 1); pos < end; pos++)
1528
+ if (table[pos] == state)
1529
+ return target;
1530
+ if (last)
1531
+ return -1;
1532
+ }
1533
+ }
1534
+ /**
1535
+ Check if this state has an action for a given terminal @internal
1536
+ */
1537
+ hasAction(state, terminal) {
1538
+ let data = this.data;
1539
+ for (let set = 0; set < 2; set++) {
1540
+ for (let i = this.stateSlot(
1541
+ state,
1542
+ set ? 2 : 1
1543
+ /* ParseState.Actions */
1544
+ ), next; ; i += 3) {
1545
+ if ((next = data[i]) == 65535) {
1546
+ if (data[i + 1] == 1)
1547
+ next = data[i = pair(data, i + 2)];
1548
+ else if (data[i + 1] == 2)
1549
+ return pair(data, i + 2);
1550
+ else
1551
+ break;
1552
+ }
1553
+ if (next == terminal || next == 0)
1554
+ return pair(data, i + 1);
1555
+ }
1556
+ }
1557
+ return 0;
1558
+ }
1559
+ /**
1560
+ @internal
1561
+ */
1562
+ stateSlot(state, slot) {
1563
+ return this.states[state * 6 + slot];
1564
+ }
1565
+ /**
1566
+ @internal
1567
+ */
1568
+ stateFlag(state, flag) {
1569
+ return (this.stateSlot(
1570
+ state,
1571
+ 0
1572
+ /* ParseState.Flags */
1573
+ ) & flag) > 0;
1574
+ }
1575
+ /**
1576
+ @internal
1577
+ */
1578
+ validAction(state, action) {
1579
+ return !!this.allActions(state, (a) => a == action ? true : null);
1580
+ }
1581
+ /**
1582
+ @internal
1583
+ */
1584
+ allActions(state, action) {
1585
+ let deflt = this.stateSlot(
1586
+ state,
1587
+ 4
1588
+ /* ParseState.DefaultReduce */
1589
+ );
1590
+ let result = deflt ? action(deflt) : void 0;
1591
+ for (let i = this.stateSlot(
1592
+ state,
1593
+ 1
1594
+ /* ParseState.Actions */
1595
+ ); result == null; i += 3) {
1596
+ if (this.data[i] == 65535) {
1597
+ if (this.data[i + 1] == 1)
1598
+ i = pair(this.data, i + 2);
1599
+ else
1600
+ break;
1601
+ }
1602
+ result = action(pair(this.data, i + 1));
1603
+ }
1604
+ return result;
1605
+ }
1606
+ /**
1607
+ Get the states that can follow this one through shift actions or
1608
+ goto jumps. @internal
1609
+ */
1610
+ nextStates(state) {
1611
+ let result = [];
1612
+ for (let i = this.stateSlot(
1613
+ state,
1614
+ 1
1615
+ /* ParseState.Actions */
1616
+ ); ; i += 3) {
1617
+ if (this.data[i] == 65535) {
1618
+ if (this.data[i + 1] == 1)
1619
+ i = pair(this.data, i + 2);
1620
+ else
1621
+ break;
1622
+ }
1623
+ if ((this.data[i + 2] & 65536 >> 16) == 0) {
1624
+ let value = this.data[i + 1];
1625
+ if (!result.some((v, i2) => i2 & 1 && v == value))
1626
+ result.push(this.data[i], value);
1627
+ }
1628
+ }
1629
+ return result;
1630
+ }
1631
+ /**
1632
+ Configure the parser. Returns a new parser instance that has the
1633
+ given settings modified. Settings not provided in `config` are
1634
+ kept from the original parser.
1635
+ */
1636
+ configure(config) {
1637
+ let copy = Object.assign(Object.create(LRParser.prototype), this);
1638
+ if (config.props)
1639
+ copy.nodeSet = this.nodeSet.extend(...config.props);
1640
+ if (config.top) {
1641
+ let info = this.topRules[config.top];
1642
+ if (!info)
1643
+ throw new RangeError(`Invalid top rule name ${config.top}`);
1644
+ copy.top = info;
1645
+ }
1646
+ if (config.tokenizers)
1647
+ copy.tokenizers = this.tokenizers.map((t) => {
1648
+ let found = config.tokenizers.find((r) => r.from == t);
1649
+ return found ? found.to : t;
1650
+ });
1651
+ if (config.specializers) {
1652
+ copy.specializers = this.specializers.slice();
1653
+ copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
1654
+ let found = config.specializers.find((r) => r.from == s.external);
1655
+ if (!found)
1656
+ return s;
1657
+ let spec = Object.assign(Object.assign({}, s), { external: found.to });
1658
+ copy.specializers[i] = getSpecializer(spec);
1659
+ return spec;
1660
+ });
1661
+ }
1662
+ if (config.contextTracker)
1663
+ copy.context = config.contextTracker;
1664
+ if (config.dialect)
1665
+ copy.dialect = this.parseDialect(config.dialect);
1666
+ if (config.strict != null)
1667
+ copy.strict = config.strict;
1668
+ if (config.wrap)
1669
+ copy.wrappers = copy.wrappers.concat(config.wrap);
1670
+ if (config.bufferLength != null)
1671
+ copy.bufferLength = config.bufferLength;
1672
+ return copy;
1673
+ }
1674
+ /**
1675
+ Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
1676
+ are registered for this parser.
1677
+ */
1678
+ hasWrappers() {
1679
+ return this.wrappers.length > 0;
1680
+ }
1681
+ /**
1682
+ Returns the name associated with a given term. This will only
1683
+ work for all terms when the parser was generated with the
1684
+ `--names` option. By default, only the names of tagged terms are
1685
+ stored.
1686
+ */
1687
+ getName(term) {
1688
+ return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
1689
+ }
1690
+ /**
1691
+ The eof term id is always allocated directly after the node
1692
+ types. @internal
1693
+ */
1694
+ get eofTerm() {
1695
+ return this.maxNode + 1;
1696
+ }
1697
+ /**
1698
+ The type of top node produced by the parser.
1699
+ */
1700
+ get topNode() {
1701
+ return this.nodeSet.types[this.top[1]];
1702
+ }
1703
+ /**
1704
+ @internal
1705
+ */
1706
+ dynamicPrecedence(term) {
1707
+ let prec = this.dynamicPrecedences;
1708
+ return prec == null ? 0 : prec[term] || 0;
1709
+ }
1710
+ /**
1711
+ @internal
1712
+ */
1713
+ parseDialect(dialect) {
1714
+ let values = Object.keys(this.dialects), flags = values.map(() => false);
1715
+ if (dialect)
1716
+ for (let part of dialect.split(" ")) {
1717
+ let id2 = values.indexOf(part);
1718
+ if (id2 >= 0)
1719
+ flags[id2] = true;
1720
+ }
1721
+ let disabled = null;
1722
+ for (let i = 0; i < values.length; i++)
1723
+ if (!flags[i]) {
1724
+ for (let j = this.dialects[values[i]], id2; (id2 = this.data[j++]) != 65535; )
1725
+ (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id2] = 1;
1726
+ }
1727
+ return new Dialect(dialect, flags, disabled);
1728
+ }
1729
+ /**
1730
+ Used by the output of the parser generator. Not available to
1731
+ user code. @hide
1732
+ */
1733
+ static deserialize(spec) {
1734
+ return new LRParser(spec);
1735
+ }
1736
+ }
1737
+ function pair(data, off) {
1738
+ return data[off] | data[off + 1] << 16;
1739
+ }
1740
+ function findFinished(stacks) {
1741
+ let best = null;
1742
+ for (let stack of stacks) {
1743
+ let stopped = stack.p.stoppedAt;
1744
+ if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(
1745
+ stack.state,
1746
+ 2
1747
+ /* StateFlag.Accepting */
1748
+ ) && (!best || best.score < stack.score))
1749
+ best = stack;
1750
+ }
1751
+ return best;
1752
+ }
1753
+ function getSpecializer(spec) {
1754
+ if (spec.external) {
1755
+ let mask = spec.extend ? 1 : 0;
1756
+ return (value, stack) => spec.external(value, stack) << 1 | mask;
1757
+ }
1758
+ return spec.get;
1759
+ }
1760
+ export {
1761
+ ContextTracker as C,
1762
+ ExternalTokenizer as E,
1763
+ LRParser as L,
1764
+ LocalTokenGroup as a
1765
+ };