@maketribe/ms-app 3.1.0 → 3.1.2

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 (224) hide show
  1. package/dist/cjs/components/basic/code-editor/code-editor-options.d.ts +16 -0
  2. package/dist/cjs/components/basic/code-editor/code-editor-options.js +25 -0
  3. package/dist/cjs/components/basic/code-editor/code-editor-options.js.map +1 -0
  4. package/dist/cjs/components/basic/code-editor/code-editor.d.ts +27 -0
  5. package/dist/cjs/components/basic/code-editor/code-editor.js +31 -0
  6. package/dist/cjs/components/basic/code-editor/code-editor.js.map +1 -0
  7. package/dist/cjs/components/basic/code-editor/index.d.ts +27 -0
  8. package/dist/cjs/components/basic/code-editor/index.js +16 -0
  9. package/dist/cjs/components/basic/code-editor/index.js.map +1 -0
  10. package/dist/cjs/components/basic/data-table-select/data-table-select.js +1 -1
  11. package/dist/cjs/components/basic/data-table-select/data-table-select.js.map +1 -1
  12. package/dist/cjs/components/basic/index.d.ts +1 -0
  13. package/dist/cjs/components/basic/index.js +12 -10
  14. package/dist/cjs/components/basic/index.js.map +1 -1
  15. package/dist/cjs/components/basic/json-editor/json-editor-options.d.ts +1 -1
  16. package/dist/cjs/components/basic/json-editor/json-editor-options.js.map +1 -1
  17. package/dist/cjs/components/basic/json-editor/json-editor.js +5 -5
  18. package/dist/cjs/components/basic/json-editor/json-editor.js.map +1 -1
  19. package/dist/cjs/components/index.js +42 -40
  20. package/dist/cjs/components/index.js.map +1 -1
  21. package/dist/cjs/core/MSAppClient.js +2 -2
  22. package/dist/cjs/core/MSAppClient.js.map +1 -1
  23. package/dist/cjs/core/component/DataFormComponents.js +10 -0
  24. package/dist/cjs/core/component/DataFormComponents.js.map +1 -1
  25. package/dist/cjs/core/resolver/ITypeResolver.d.ts +1 -2
  26. package/dist/cjs/index.js +52 -50
  27. package/dist/cjs/index.js.map +1 -1
  28. package/dist/cjs/installer.js +1 -0
  29. package/dist/cjs/installer.js.map +1 -1
  30. package/dist/cjs/layouts/components/bar/index.js +1 -0
  31. package/dist/cjs/layouts/components/bar/index.js.map +1 -1
  32. package/dist/cjs/layouts/components/header/tools.js +1 -0
  33. package/dist/cjs/layouts/components/header/tools.js.map +1 -1
  34. package/dist/cjs/layouts/components/lock/lock.js +1 -0
  35. package/dist/cjs/layouts/components/lock/lock.js.map +1 -1
  36. package/dist/cjs/layouts/components/menu/menu-item.js +1 -0
  37. package/dist/cjs/layouts/components/menu/menu-item.js.map +1 -1
  38. package/dist/cjs/layouts/container/default.js +1 -0
  39. package/dist/cjs/layouts/container/default.js.map +1 -1
  40. package/dist/cjs/modules/cms/components/part-list/components/article-page/index.vue2.js +1 -2
  41. package/dist/cjs/modules/cms/components/part-list/components/article-page/index.vue2.js.map +1 -1
  42. package/dist/cjs/modules/cms/components/part-list/components/page-container/index.vue2.js +1 -0
  43. package/dist/cjs/modules/cms/components/part-list/components/page-container/index.vue2.js.map +1 -1
  44. package/dist/cjs/modules/cms/components/part-list/components/part-page/index.vue2.js +1 -2
  45. package/dist/cjs/modules/cms/components/part-list/components/part-page/index.vue2.js.map +1 -1
  46. package/dist/cjs/modules/cms/dataviews/cms-articles/CmsArticlesForm.js +3 -3
  47. package/dist/cjs/modules/cms/dataviews/cms-articles/CmsArticlesForm.js.map +1 -1
  48. package/dist/cjs/modules/cms/dataviews/cms-parts/CmsPartForm.js +5 -4
  49. package/dist/cjs/modules/cms/dataviews/cms-parts/CmsPartForm.js.map +1 -1
  50. package/dist/cjs/modules/cms/pages/cms-article/index.vue2.js +1 -0
  51. package/dist/cjs/modules/cms/pages/cms-article/index.vue2.js.map +1 -1
  52. package/dist/cjs/modules/ms/dataviews/ms-config/MsConfigForm.d.ts +1 -1
  53. package/dist/cjs/modules/ms/dataviews/ms-config/MsConfigForm.js +11 -8
  54. package/dist/cjs/modules/ms/dataviews/ms-config/MsConfigForm.js.map +1 -1
  55. package/dist/cjs/modules/ms/dataviews/ms-material/MsMaterialTable.d.ts +1 -1
  56. package/dist/cjs/modules/ms/dataviews/ms-material/MsMaterialTable.js +4 -4
  57. package/dist/cjs/modules/ms/dataviews/ms-material/MsMaterialTable.js.map +1 -1
  58. package/dist/cjs/modules/ms/dataviews/ms-member/MsMemberTable.js +15 -4
  59. package/dist/cjs/modules/ms/dataviews/ms-member/MsMemberTable.js.map +1 -1
  60. package/dist/cjs/modules/ms/pages/local-log/index.vue2.js +1 -0
  61. package/dist/cjs/modules/ms/pages/local-log/index.vue2.js.map +1 -1
  62. package/dist/cjs/modules/ms/pages/ms-material/index.vue2.js +1 -0
  63. package/dist/cjs/modules/ms/pages/ms-material/index.vue2.js.map +1 -1
  64. package/dist/cjs/modules/ms/pages/ms-member/index.vue2.js +1 -0
  65. package/dist/cjs/modules/ms/pages/ms-member/index.vue2.js.map +1 -1
  66. package/dist/cjs/node_modules/.pnpm/@codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm/node_modules/@codemirror/autocomplete/dist/index.js +276 -0
  67. package/dist/cjs/node_modules/.pnpm/@codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -1
  68. package/dist/cjs/node_modules/.pnpm/@codemirror_lang-css@6.2.1_@codemirror_view@6.26.1/node_modules/@codemirror/lang-css/dist/index.js +263 -0
  69. package/dist/cjs/node_modules/.pnpm/@codemirror_lang-css@6.2.1_@codemirror_view@6.26.1/node_modules/@codemirror/lang-css/dist/index.js.map +1 -0
  70. package/dist/cjs/node_modules/.pnpm/@codemirror_lang-html@6.4.9/node_modules/@codemirror/lang-html/dist/index.js +667 -0
  71. package/dist/cjs/node_modules/.pnpm/@codemirror_lang-html@6.4.9/node_modules/@codemirror/lang-html/dist/index.js.map +1 -0
  72. package/dist/cjs/node_modules/.pnpm/@codemirror_lang-javascript@6.2.2/node_modules/@codemirror/lang-javascript/dist/index.js +342 -0
  73. package/dist/cjs/node_modules/.pnpm/@codemirror_lang-javascript@6.2.2/node_modules/@codemirror/lang-javascript/dist/index.js.map +1 -0
  74. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js +21 -0
  75. package/dist/cjs/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js.map +1 -1
  76. package/dist/cjs/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js +510 -1
  77. package/dist/cjs/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js.map +1 -1
  78. package/dist/cjs/node_modules/.pnpm/@lezer_css@1.1.8/node_modules/@lezer/css/dist/index.js +127 -0
  79. package/dist/cjs/node_modules/.pnpm/@lezer_css@1.1.8/node_modules/@lezer/css/dist/index.js.map +1 -0
  80. package/dist/cjs/node_modules/.pnpm/@lezer_html@1.3.10/node_modules/@lezer/html/dist/index.js +360 -0
  81. package/dist/cjs/node_modules/.pnpm/@lezer_html@1.3.10/node_modules/@lezer/html/dist/index.js.map +1 -0
  82. package/dist/cjs/node_modules/.pnpm/@lezer_javascript@1.4.17/node_modules/@lezer/javascript/dist/index.js +189 -0
  83. package/dist/cjs/node_modules/.pnpm/@lezer_javascript@1.4.17/node_modules/@lezer/javascript/dist/index.js.map +1 -0
  84. package/dist/cjs/node_modules/.pnpm/@lezer_lr@1.4.0/node_modules/@lezer/lr/dist/index.js +1879 -0
  85. package/dist/cjs/node_modules/.pnpm/@lezer_lr@1.4.0/node_modules/@lezer/lr/dist/index.js.map +1 -0
  86. package/dist/cjs/node_modules/.pnpm/vue-codemirror@6.1.1_codemirror@6.0.1_@lezer_common@1.2.1__vue@3.3.4/node_modules/vue-codemirror/dist/vue-codemirror.esm.js.map +1 -0
  87. package/dist/cjs/page/index/dv/default/add.vue2.js +1 -0
  88. package/dist/cjs/page/index/dv/default/add.vue2.js.map +1 -1
  89. package/dist/cjs/page/index/dv/default/edit.vue2.js +1 -0
  90. package/dist/cjs/page/index/dv/default/edit.vue2.js.map +1 -1
  91. package/dist/cjs/page/index/dv/default/single/list/dialog.vue2.js +1 -0
  92. package/dist/cjs/page/index/dv/default/single/list/dialog.vue2.js.map +1 -1
  93. package/dist/cjs/page/index/dv/default/single/list/normal.vue2.js +1 -0
  94. package/dist/cjs/page/index/dv/default/single/list/normal.vue2.js.map +1 -1
  95. package/dist/cjs/page/index/dv/default/single/table-tree/dialog.vue2.js +1 -0
  96. package/dist/cjs/page/index/dv/default/single/table-tree/dialog.vue2.js.map +1 -1
  97. package/dist/cjs/page/index/dv/default/single/table-tree/normal.vue2.js +1 -0
  98. package/dist/cjs/page/index/dv/default/single/table-tree/normal.vue2.js.map +1 -1
  99. package/dist/cjs/page/index/dv/default/single/tree/dialog.vue2.js +1 -0
  100. package/dist/cjs/page/index/dv/default/single/tree/dialog.vue2.js.map +1 -1
  101. package/dist/cjs/page/index/dv/default/table.vue2.js +1 -0
  102. package/dist/cjs/page/index/dv/default/table.vue2.js.map +1 -1
  103. package/dist/cjs/page/login/index.vue2.js +1 -0
  104. package/dist/cjs/page/login/index.vue2.js.map +1 -1
  105. package/dist/cjs/page/signup/index.vue2.js +1 -0
  106. package/dist/cjs/page/signup/index.vue2.js.map +1 -1
  107. package/dist/esm/components/basic/code-editor/code-editor-options.d.ts +16 -0
  108. package/dist/esm/components/basic/code-editor/code-editor-options.js +22 -0
  109. package/dist/esm/components/basic/code-editor/code-editor-options.js.map +1 -0
  110. package/dist/esm/components/basic/code-editor/code-editor.d.ts +27 -0
  111. package/dist/esm/components/basic/code-editor/code-editor.js +29 -0
  112. package/dist/esm/components/basic/code-editor/code-editor.js.map +1 -0
  113. package/dist/esm/components/basic/code-editor/index.d.ts +27 -0
  114. package/dist/esm/components/basic/code-editor/index.js +9 -0
  115. package/dist/esm/components/basic/code-editor/index.js.map +1 -0
  116. package/dist/esm/components/basic/data-table-select/data-table-select.js +1 -1
  117. package/dist/esm/components/basic/data-table-select/data-table-select.js.map +1 -1
  118. package/dist/esm/components/basic/index.d.ts +1 -0
  119. package/dist/esm/components/basic/index.js +1 -0
  120. package/dist/esm/components/basic/index.js.map +1 -1
  121. package/dist/esm/components/basic/json-editor/json-editor-options.d.ts +1 -1
  122. package/dist/esm/components/basic/json-editor/json-editor-options.js.map +1 -1
  123. package/dist/esm/components/basic/json-editor/json-editor.js +3 -3
  124. package/dist/esm/components/basic/json-editor/json-editor.js.map +1 -1
  125. package/dist/esm/components/index.js +1 -0
  126. package/dist/esm/components/index.js.map +1 -1
  127. package/dist/esm/core/MSAppClient.js +2 -2
  128. package/dist/esm/core/MSAppClient.js.map +1 -1
  129. package/dist/esm/core/component/DataFormComponents.js +10 -0
  130. package/dist/esm/core/component/DataFormComponents.js.map +1 -1
  131. package/dist/esm/core/resolver/ITypeResolver.d.ts +1 -2
  132. package/dist/esm/index.js +1 -0
  133. package/dist/esm/index.js.map +1 -1
  134. package/dist/esm/installer.js +1 -0
  135. package/dist/esm/installer.js.map +1 -1
  136. package/dist/esm/layouts/components/bar/index.js +1 -0
  137. package/dist/esm/layouts/components/bar/index.js.map +1 -1
  138. package/dist/esm/layouts/components/header/tools.js +1 -0
  139. package/dist/esm/layouts/components/header/tools.js.map +1 -1
  140. package/dist/esm/layouts/components/lock/lock.js +1 -0
  141. package/dist/esm/layouts/components/lock/lock.js.map +1 -1
  142. package/dist/esm/layouts/components/menu/menu-item.js +1 -0
  143. package/dist/esm/layouts/components/menu/menu-item.js.map +1 -1
  144. package/dist/esm/layouts/container/default.js +1 -0
  145. package/dist/esm/layouts/container/default.js.map +1 -1
  146. package/dist/esm/modules/cms/components/part-list/components/article-page/index.vue2.js +1 -2
  147. package/dist/esm/modules/cms/components/part-list/components/article-page/index.vue2.js.map +1 -1
  148. package/dist/esm/modules/cms/components/part-list/components/page-container/index.vue2.js +1 -0
  149. package/dist/esm/modules/cms/components/part-list/components/page-container/index.vue2.js.map +1 -1
  150. package/dist/esm/modules/cms/components/part-list/components/part-page/index.vue2.js +1 -2
  151. package/dist/esm/modules/cms/components/part-list/components/part-page/index.vue2.js.map +1 -1
  152. package/dist/esm/modules/cms/dataviews/cms-articles/CmsArticlesForm.js +3 -3
  153. package/dist/esm/modules/cms/dataviews/cms-articles/CmsArticlesForm.js.map +1 -1
  154. package/dist/esm/modules/cms/dataviews/cms-parts/CmsPartForm.js +5 -4
  155. package/dist/esm/modules/cms/dataviews/cms-parts/CmsPartForm.js.map +1 -1
  156. package/dist/esm/modules/cms/pages/cms-article/index.vue2.js +1 -0
  157. package/dist/esm/modules/cms/pages/cms-article/index.vue2.js.map +1 -1
  158. package/dist/esm/modules/ms/dataviews/ms-config/MsConfigForm.d.ts +1 -1
  159. package/dist/esm/modules/ms/dataviews/ms-config/MsConfigForm.js +11 -8
  160. package/dist/esm/modules/ms/dataviews/ms-config/MsConfigForm.js.map +1 -1
  161. package/dist/esm/modules/ms/dataviews/ms-material/MsMaterialTable.d.ts +1 -1
  162. package/dist/esm/modules/ms/dataviews/ms-material/MsMaterialTable.js +4 -4
  163. package/dist/esm/modules/ms/dataviews/ms-material/MsMaterialTable.js.map +1 -1
  164. package/dist/esm/modules/ms/dataviews/ms-member/MsMemberTable.js +15 -4
  165. package/dist/esm/modules/ms/dataviews/ms-member/MsMemberTable.js.map +1 -1
  166. package/dist/esm/modules/ms/pages/local-log/index.vue2.js +1 -0
  167. package/dist/esm/modules/ms/pages/local-log/index.vue2.js.map +1 -1
  168. package/dist/esm/modules/ms/pages/ms-material/index.vue2.js +1 -0
  169. package/dist/esm/modules/ms/pages/ms-material/index.vue2.js.map +1 -1
  170. package/dist/esm/modules/ms/pages/ms-member/index.vue2.js +1 -0
  171. package/dist/esm/modules/ms/pages/ms-member/index.vue2.js.map +1 -1
  172. package/dist/esm/node_modules/.pnpm/@codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm/node_modules/@codemirror/autocomplete/dist/index.js +273 -4
  173. package/dist/esm/node_modules/.pnpm/@codemirror_autocomplete@6.15.0_@codemirror_language@6.10.1_@codemirror_state@6.4.1_@codemirr_djjyqdn7bhwopzrz2h2s2bwhzm/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -1
  174. package/dist/esm/node_modules/.pnpm/@codemirror_lang-css@6.2.1_@codemirror_view@6.26.1/node_modules/@codemirror/lang-css/dist/index.js +258 -0
  175. package/dist/esm/node_modules/.pnpm/@codemirror_lang-css@6.2.1_@codemirror_view@6.26.1/node_modules/@codemirror/lang-css/dist/index.js.map +1 -0
  176. package/dist/esm/node_modules/.pnpm/@codemirror_lang-html@6.4.9/node_modules/@codemirror/lang-html/dist/index.js +661 -0
  177. package/dist/esm/node_modules/.pnpm/@codemirror_lang-html@6.4.9/node_modules/@codemirror/lang-html/dist/index.js.map +1 -0
  178. package/dist/esm/node_modules/.pnpm/@codemirror_lang-javascript@6.2.2/node_modules/@codemirror/lang-javascript/dist/index.js +332 -0
  179. package/dist/esm/node_modules/.pnpm/@codemirror_lang-javascript@6.2.2/node_modules/@codemirror/lang-javascript/dist/index.js.map +1 -0
  180. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js +20 -1
  181. package/dist/esm/node_modules/.pnpm/@codemirror_language@6.10.1/node_modules/@codemirror/language/dist/index.js.map +1 -1
  182. package/dist/esm/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js +508 -2
  183. package/dist/esm/node_modules/.pnpm/@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js.map +1 -1
  184. package/dist/esm/node_modules/.pnpm/@lezer_css@1.1.8/node_modules/@lezer/css/dist/index.js +125 -0
  185. package/dist/esm/node_modules/.pnpm/@lezer_css@1.1.8/node_modules/@lezer/css/dist/index.js.map +1 -0
  186. package/dist/esm/node_modules/.pnpm/@lezer_html@1.3.10/node_modules/@lezer/html/dist/index.js +357 -0
  187. package/dist/esm/node_modules/.pnpm/@lezer_html@1.3.10/node_modules/@lezer/html/dist/index.js.map +1 -0
  188. package/dist/esm/node_modules/.pnpm/@lezer_javascript@1.4.17/node_modules/@lezer/javascript/dist/index.js +187 -0
  189. package/dist/esm/node_modules/.pnpm/@lezer_javascript@1.4.17/node_modules/@lezer/javascript/dist/index.js.map +1 -0
  190. package/dist/esm/node_modules/.pnpm/@lezer_lr@1.4.0/node_modules/@lezer/lr/dist/index.js +1872 -0
  191. package/dist/esm/node_modules/.pnpm/@lezer_lr@1.4.0/node_modules/@lezer/lr/dist/index.js.map +1 -0
  192. package/dist/esm/node_modules/.pnpm/vue-codemirror@6.1.1_codemirror@6.0.1_@lezer_common@1.2.1__vue@3.3.4/node_modules/vue-codemirror/dist/vue-codemirror.esm.js.map +1 -0
  193. package/dist/esm/page/index/dv/default/add.vue2.js +1 -0
  194. package/dist/esm/page/index/dv/default/add.vue2.js.map +1 -1
  195. package/dist/esm/page/index/dv/default/edit.vue2.js +1 -0
  196. package/dist/esm/page/index/dv/default/edit.vue2.js.map +1 -1
  197. package/dist/esm/page/index/dv/default/single/list/dialog.vue2.js +1 -0
  198. package/dist/esm/page/index/dv/default/single/list/dialog.vue2.js.map +1 -1
  199. package/dist/esm/page/index/dv/default/single/list/normal.vue2.js +1 -0
  200. package/dist/esm/page/index/dv/default/single/list/normal.vue2.js.map +1 -1
  201. package/dist/esm/page/index/dv/default/single/table-tree/dialog.vue2.js +1 -0
  202. package/dist/esm/page/index/dv/default/single/table-tree/dialog.vue2.js.map +1 -1
  203. package/dist/esm/page/index/dv/default/single/table-tree/normal.vue2.js +1 -0
  204. package/dist/esm/page/index/dv/default/single/table-tree/normal.vue2.js.map +1 -1
  205. package/dist/esm/page/index/dv/default/single/tree/dialog.vue2.js +1 -0
  206. package/dist/esm/page/index/dv/default/single/tree/dialog.vue2.js.map +1 -1
  207. package/dist/esm/page/index/dv/default/table.vue2.js +1 -0
  208. package/dist/esm/page/index/dv/default/table.vue2.js.map +1 -1
  209. package/dist/esm/page/login/index.vue2.js +1 -0
  210. package/dist/esm/page/login/index.vue2.js.map +1 -1
  211. package/dist/esm/page/signup/index.vue2.js +1 -0
  212. package/dist/esm/page/signup/index.vue2.js.map +1 -1
  213. package/dist/style/components/code-editor.css +1 -0
  214. package/dist/style/components/index.css +1 -1
  215. package/dist/style/index.css +1 -1
  216. package/dist/style/src/components/code-editor.scss +7 -0
  217. package/dist/style/src/components/index.scss +1 -1
  218. package/package.json +2 -1
  219. package/dist/cjs/node_modules/.pnpm/vue-codemirror@6.1.1_codemirror@6.0.1_vue@3.3.4/node_modules/vue-codemirror/dist/vue-codemirror.esm.js.map +0 -1
  220. package/dist/esm/node_modules/.pnpm/vue-codemirror@6.1.1_codemirror@6.0.1_vue@3.3.4/node_modules/vue-codemirror/dist/vue-codemirror.esm.js.map +0 -1
  221. package/dist/style/components/json-editor.css +0 -1
  222. package/dist/style/src/components/json-editor.scss +0 -7
  223. /package/dist/cjs/node_modules/.pnpm/{vue-codemirror@6.1.1_codemirror@6.0.1_vue@3.3.4 → vue-codemirror@6.1.1_codemirror@6.0.1_@lezer_common@1.2.1__vue@3.3.4}/node_modules/vue-codemirror/dist/vue-codemirror.esm.js +0 -0
  224. /package/dist/esm/node_modules/.pnpm/{vue-codemirror@6.1.1_codemirror@6.0.1_vue@3.3.4 → vue-codemirror@6.1.1_codemirror@6.0.1_@lezer_common@1.2.1__vue@3.3.4}/node_modules/vue-codemirror/dist/vue-codemirror.esm.js +0 -0
@@ -0,0 +1,1872 @@
1
+ import { Parser, NodeSet, NodeType, DefaultBufferLength, NodeProp, Tree, IterMode } from '../../../../../@lezer_common@1.2.1/node_modules/@lezer/common/dist/index.js';
2
+
3
+ /**
4
+ A parse stack. These are used internally by the parser to track
5
+ parsing progress. They also provide some properties and methods
6
+ that external code such as a tokenizer can use to get information
7
+ about the parse state.
8
+ */
9
+ class Stack {
10
+ /**
11
+ @internal
12
+ */
13
+ constructor(
14
+ /**
15
+ The parse that this stack is part of @internal
16
+ */
17
+ p,
18
+ /**
19
+ Holds state, input pos, buffer index triplets for all but the
20
+ top state @internal
21
+ */
22
+ stack,
23
+ /**
24
+ The current parse state @internal
25
+ */
26
+ state,
27
+ // The position at which the next reduce should take place. This
28
+ // can be less than `this.pos` when skipped expressions have been
29
+ // added to the stack (which should be moved outside of the next
30
+ // reduction)
31
+ /**
32
+ @internal
33
+ */
34
+ reducePos,
35
+ /**
36
+ The input position up to which this stack has parsed.
37
+ */
38
+ pos,
39
+ /**
40
+ The dynamic score of the stack, including dynamic precedence
41
+ and error-recovery penalties
42
+ @internal
43
+ */
44
+ score,
45
+ // The output buffer. Holds (type, start, end, size) quads
46
+ // representing nodes created by the parser, where `size` is
47
+ // amount of buffer array entries covered by this node.
48
+ /**
49
+ @internal
50
+ */
51
+ buffer,
52
+ // The base offset of the buffer. When stacks are split, the split
53
+ // instance shared the buffer history with its parent up to
54
+ // `bufferBase`, which is the absolute offset (including the
55
+ // offset of previous splits) into the buffer at which this stack
56
+ // starts writing.
57
+ /**
58
+ @internal
59
+ */
60
+ bufferBase,
61
+ /**
62
+ @internal
63
+ */
64
+ curContext,
65
+ /**
66
+ @internal
67
+ */
68
+ lookAhead = 0,
69
+ // A parent stack from which this was split off, if any. This is
70
+ // set up so that it always points to a stack that has some
71
+ // additional buffer content, never to a stack with an equal
72
+ // `bufferBase`.
73
+ /**
74
+ @internal
75
+ */
76
+ parent) {
77
+ this.p = p;
78
+ this.stack = stack;
79
+ this.state = state;
80
+ this.reducePos = reducePos;
81
+ this.pos = pos;
82
+ this.score = score;
83
+ this.buffer = buffer;
84
+ this.bufferBase = bufferBase;
85
+ this.curContext = curContext;
86
+ this.lookAhead = lookAhead;
87
+ this.parent = parent;
88
+ }
89
+ /**
90
+ @internal
91
+ */
92
+ toString() {
93
+ return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
94
+ }
95
+ // Start an empty stack
96
+ /**
97
+ @internal
98
+ */
99
+ static start(p, state, pos = 0) {
100
+ let cx = p.parser.context;
101
+ return new Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null);
102
+ }
103
+ /**
104
+ The stack's current [context](#lr.ContextTracker) value, if
105
+ any. Its type will depend on the context tracker's type
106
+ parameter, or it will be `null` if there is no context
107
+ tracker.
108
+ */
109
+ get context() { return this.curContext ? this.curContext.context : null; }
110
+ // Push a state onto the stack, tracking its start position as well
111
+ // as the buffer base at that point.
112
+ /**
113
+ @internal
114
+ */
115
+ pushState(state, start) {
116
+ this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
117
+ this.state = state;
118
+ }
119
+ // Apply a reduce action
120
+ /**
121
+ @internal
122
+ */
123
+ reduce(action) {
124
+ var _a;
125
+ let depth = action >> 19 /* Action.ReduceDepthShift */, type = action & 65535 /* Action.ValueMask */;
126
+ let { parser } = this.p;
127
+ let dPrec = parser.dynamicPrecedence(type);
128
+ if (dPrec)
129
+ this.score += dPrec;
130
+ if (depth == 0) {
131
+ this.pushState(parser.getGoto(this.state, type, true), this.reducePos);
132
+ // Zero-depth reductions are a special case—they add stuff to
133
+ // the stack without popping anything off.
134
+ if (type < parser.minRepeatTerm)
135
+ this.storeNode(type, this.reducePos, this.reducePos, 4, true);
136
+ this.reduceContext(type, this.reducePos);
137
+ return;
138
+ }
139
+ // Find the base index into `this.stack`, content after which will
140
+ // be dropped. Note that with `StayFlag` reductions we need to
141
+ // consume two extra frames (the dummy parent node for the skipped
142
+ // expression and the state that we'll be staying in, which should
143
+ // be moved to `this.state`).
144
+ let base = this.stack.length - ((depth - 1) * 3) - (action & 262144 /* Action.StayFlag */ ? 6 : 0);
145
+ let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
146
+ // This is a kludge to try and detect overly deep left-associative
147
+ // trees, which will not increase the parse stack depth and thus
148
+ // won't be caught by the regular stack-depth limit check.
149
+ if (size >= 2000 /* Recover.MinBigReduction */ && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
150
+ if (start == this.p.lastBigReductionStart) {
151
+ this.p.bigReductionCount++;
152
+ this.p.lastBigReductionSize = size;
153
+ }
154
+ else if (this.p.lastBigReductionSize < size) {
155
+ this.p.bigReductionCount = 1;
156
+ this.p.lastBigReductionStart = start;
157
+ this.p.lastBigReductionSize = size;
158
+ }
159
+ }
160
+ let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
161
+ // Store normal terms or `R -> R R` repeat reductions
162
+ if (type < parser.minRepeatTerm || (action & 131072 /* Action.RepeatFlag */)) {
163
+ let pos = parser.stateFlag(this.state, 1 /* StateFlag.Skipped */) ? this.pos : this.reducePos;
164
+ this.storeNode(type, start, pos, count + 4, true);
165
+ }
166
+ if (action & 262144 /* Action.StayFlag */) {
167
+ this.state = this.stack[base];
168
+ }
169
+ else {
170
+ let baseStateID = this.stack[base - 3];
171
+ this.state = parser.getGoto(baseStateID, type, true);
172
+ }
173
+ while (this.stack.length > base)
174
+ this.stack.pop();
175
+ this.reduceContext(type, start);
176
+ }
177
+ // Shift a value into the buffer
178
+ /**
179
+ @internal
180
+ */
181
+ storeNode(term, start, end, size = 4, isReduce = false) {
182
+ if (term == 0 /* Term.Err */ &&
183
+ (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
184
+ // Try to omit/merge adjacent error nodes
185
+ let cur = this, top = this.buffer.length;
186
+ if (top == 0 && cur.parent) {
187
+ top = cur.bufferBase - cur.parent.bufferBase;
188
+ cur = cur.parent;
189
+ }
190
+ if (top > 0 && cur.buffer[top - 4] == 0 /* Term.Err */ && cur.buffer[top - 1] > -1) {
191
+ if (start == end)
192
+ return;
193
+ if (cur.buffer[top - 2] >= start) {
194
+ cur.buffer[top - 2] = end;
195
+ return;
196
+ }
197
+ }
198
+ }
199
+ if (!isReduce || this.pos == end) { // Simple case, just append
200
+ this.buffer.push(term, start, end, size);
201
+ }
202
+ else { // There may be skipped nodes that have to be moved forward
203
+ let index = this.buffer.length;
204
+ if (index > 0 && this.buffer[index - 4] != 0 /* Term.Err */)
205
+ while (index > 0 && this.buffer[index - 2] > end) {
206
+ // Move this record forward
207
+ this.buffer[index] = this.buffer[index - 4];
208
+ this.buffer[index + 1] = this.buffer[index - 3];
209
+ this.buffer[index + 2] = this.buffer[index - 2];
210
+ this.buffer[index + 3] = this.buffer[index - 1];
211
+ index -= 4;
212
+ if (size > 4)
213
+ size -= 4;
214
+ }
215
+ this.buffer[index] = term;
216
+ this.buffer[index + 1] = start;
217
+ this.buffer[index + 2] = end;
218
+ this.buffer[index + 3] = size;
219
+ }
220
+ }
221
+ // Apply a shift action
222
+ /**
223
+ @internal
224
+ */
225
+ shift(action, type, start, end) {
226
+ if (action & 131072 /* Action.GotoFlag */) {
227
+ this.pushState(action & 65535 /* Action.ValueMask */, this.pos);
228
+ }
229
+ else if ((action & 262144 /* Action.StayFlag */) == 0) { // Regular shift
230
+ let nextState = action, { parser } = this.p;
231
+ if (end > this.pos || type <= parser.maxNode) {
232
+ this.pos = end;
233
+ if (!parser.stateFlag(nextState, 1 /* StateFlag.Skipped */))
234
+ this.reducePos = end;
235
+ }
236
+ this.pushState(nextState, start);
237
+ this.shiftContext(type, start);
238
+ if (type <= parser.maxNode)
239
+ this.buffer.push(type, start, end, 4);
240
+ }
241
+ else { // Shift-and-stay, which means this is a skipped token
242
+ this.pos = end;
243
+ this.shiftContext(type, start);
244
+ if (type <= this.p.parser.maxNode)
245
+ this.buffer.push(type, start, end, 4);
246
+ }
247
+ }
248
+ // Apply an action
249
+ /**
250
+ @internal
251
+ */
252
+ apply(action, next, nextStart, nextEnd) {
253
+ if (action & 65536 /* Action.ReduceFlag */)
254
+ this.reduce(action);
255
+ else
256
+ this.shift(action, next, nextStart, nextEnd);
257
+ }
258
+ // Add a prebuilt (reused) node into the buffer.
259
+ /**
260
+ @internal
261
+ */
262
+ useNode(value, next) {
263
+ let index = this.p.reused.length - 1;
264
+ if (index < 0 || this.p.reused[index] != value) {
265
+ this.p.reused.push(value);
266
+ index++;
267
+ }
268
+ let start = this.pos;
269
+ this.reducePos = this.pos = start + value.length;
270
+ this.pushState(next, start);
271
+ this.buffer.push(index, start, this.reducePos, -1 /* size == -1 means this is a reused value */);
272
+ if (this.curContext)
273
+ this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
274
+ }
275
+ // Split the stack. Due to the buffer sharing and the fact
276
+ // that `this.stack` tends to stay quite shallow, this isn't very
277
+ // expensive.
278
+ /**
279
+ @internal
280
+ */
281
+ split() {
282
+ let parent = this;
283
+ let off = parent.buffer.length;
284
+ // Because the top of the buffer (after this.pos) may be mutated
285
+ // to reorder reductions and skipped tokens, and shared buffers
286
+ // should be immutable, this copies any outstanding skipped tokens
287
+ // to the new buffer, and puts the base pointer before them.
288
+ while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
289
+ off -= 4;
290
+ let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
291
+ // Make sure parent points to an actual parent with content, if there is such a parent.
292
+ while (parent && base == parent.bufferBase)
293
+ parent = parent.parent;
294
+ return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
295
+ }
296
+ // Try to recover from an error by 'deleting' (ignoring) one token.
297
+ /**
298
+ @internal
299
+ */
300
+ recoverByDelete(next, nextEnd) {
301
+ let isNode = next <= this.p.parser.maxNode;
302
+ if (isNode)
303
+ this.storeNode(next, this.pos, nextEnd, 4);
304
+ this.storeNode(0 /* Term.Err */, this.pos, nextEnd, isNode ? 8 : 4);
305
+ this.pos = this.reducePos = nextEnd;
306
+ this.score -= 190 /* Recover.Delete */;
307
+ }
308
+ /**
309
+ Check if the given term would be able to be shifted (optionally
310
+ after some reductions) on this stack. This can be useful for
311
+ external tokenizers that want to make sure they only provide a
312
+ given token when it applies.
313
+ */
314
+ canShift(term) {
315
+ for (let sim = new SimulatedStack(this);;) {
316
+ let action = this.p.parser.stateSlot(sim.state, 4 /* ParseState.DefaultReduce */) || this.p.parser.hasAction(sim.state, term);
317
+ if (action == 0)
318
+ return false;
319
+ if ((action & 65536 /* Action.ReduceFlag */) == 0)
320
+ return true;
321
+ sim.reduce(action);
322
+ }
323
+ }
324
+ // Apply up to Recover.MaxNext recovery actions that conceptually
325
+ // inserts some missing token or rule.
326
+ /**
327
+ @internal
328
+ */
329
+ recoverByInsert(next) {
330
+ if (this.stack.length >= 300 /* Recover.MaxInsertStackDepth */)
331
+ return [];
332
+ let nextStates = this.p.parser.nextStates(this.state);
333
+ if (nextStates.length > 4 /* Recover.MaxNext */ << 1 || this.stack.length >= 120 /* Recover.DampenInsertStackDepth */) {
334
+ let best = [];
335
+ for (let i = 0, s; i < nextStates.length; i += 2) {
336
+ if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
337
+ best.push(nextStates[i], s);
338
+ }
339
+ if (this.stack.length < 120 /* Recover.DampenInsertStackDepth */)
340
+ for (let i = 0; best.length < 4 /* Recover.MaxNext */ << 1 && i < nextStates.length; i += 2) {
341
+ let s = nextStates[i + 1];
342
+ if (!best.some((v, i) => (i & 1) && v == s))
343
+ best.push(nextStates[i], s);
344
+ }
345
+ nextStates = best;
346
+ }
347
+ let result = [];
348
+ for (let i = 0; i < nextStates.length && result.length < 4 /* Recover.MaxNext */; i += 2) {
349
+ let s = nextStates[i + 1];
350
+ if (s == this.state)
351
+ continue;
352
+ let stack = this.split();
353
+ stack.pushState(s, this.pos);
354
+ stack.storeNode(0 /* Term.Err */, stack.pos, stack.pos, 4, true);
355
+ stack.shiftContext(nextStates[i], this.pos);
356
+ stack.reducePos = this.pos;
357
+ stack.score -= 200 /* Recover.Insert */;
358
+ result.push(stack);
359
+ }
360
+ return result;
361
+ }
362
+ // Force a reduce, if possible. Return false if that can't
363
+ // be done.
364
+ /**
365
+ @internal
366
+ */
367
+ forceReduce() {
368
+ let { parser } = this.p;
369
+ let reduce = parser.stateSlot(this.state, 5 /* ParseState.ForcedReduce */);
370
+ if ((reduce & 65536 /* Action.ReduceFlag */) == 0)
371
+ return false;
372
+ if (!parser.validAction(this.state, reduce)) {
373
+ let depth = reduce >> 19 /* Action.ReduceDepthShift */, term = reduce & 65535 /* Action.ValueMask */;
374
+ let target = this.stack.length - depth * 3;
375
+ if (target < 0 || parser.getGoto(this.stack[target], term, false) < 0) {
376
+ let backup = this.findForcedReduction();
377
+ if (backup == null)
378
+ return false;
379
+ reduce = backup;
380
+ }
381
+ this.storeNode(0 /* Term.Err */, this.pos, this.pos, 4, true);
382
+ this.score -= 100 /* Recover.Reduce */;
383
+ }
384
+ this.reducePos = this.pos;
385
+ this.reduce(reduce);
386
+ return true;
387
+ }
388
+ /**
389
+ Try to scan through the automaton to find some kind of reduction
390
+ that can be applied. Used when the regular ForcedReduce field
391
+ isn't a valid action. @internal
392
+ */
393
+ findForcedReduction() {
394
+ let { parser } = this.p, seen = [];
395
+ let explore = (state, depth) => {
396
+ if (seen.includes(state))
397
+ return;
398
+ seen.push(state);
399
+ return parser.allActions(state, (action) => {
400
+ if (action & (262144 /* Action.StayFlag */ | 131072 /* Action.GotoFlag */)) ;
401
+ else if (action & 65536 /* Action.ReduceFlag */) {
402
+ let rDepth = (action >> 19 /* Action.ReduceDepthShift */) - depth;
403
+ if (rDepth > 1) {
404
+ let term = action & 65535 /* Action.ValueMask */, target = this.stack.length - rDepth * 3;
405
+ if (target >= 0 && parser.getGoto(this.stack[target], term, false) >= 0)
406
+ return (rDepth << 19 /* Action.ReduceDepthShift */) | 65536 /* Action.ReduceFlag */ | term;
407
+ }
408
+ }
409
+ else {
410
+ let found = explore(action, depth + 1);
411
+ if (found != null)
412
+ return found;
413
+ }
414
+ });
415
+ };
416
+ return explore(this.state, 0);
417
+ }
418
+ /**
419
+ @internal
420
+ */
421
+ forceAll() {
422
+ while (!this.p.parser.stateFlag(this.state, 2 /* StateFlag.Accepting */)) {
423
+ if (!this.forceReduce()) {
424
+ this.storeNode(0 /* Term.Err */, this.pos, this.pos, 4, true);
425
+ break;
426
+ }
427
+ }
428
+ return this;
429
+ }
430
+ /**
431
+ Check whether this state has no further actions (assumed to be a direct descendant of the
432
+ top state, since any other states must be able to continue
433
+ somehow). @internal
434
+ */
435
+ get deadEnd() {
436
+ if (this.stack.length != 3)
437
+ return false;
438
+ let { parser } = this.p;
439
+ return parser.data[parser.stateSlot(this.state, 1 /* ParseState.Actions */)] == 65535 /* Seq.End */ &&
440
+ !parser.stateSlot(this.state, 4 /* ParseState.DefaultReduce */);
441
+ }
442
+ /**
443
+ Restart the stack (put it back in its start state). Only safe
444
+ when this.stack.length == 3 (state is directly below the top
445
+ state). @internal
446
+ */
447
+ restart() {
448
+ this.storeNode(0 /* Term.Err */, this.pos, this.pos, 4, true);
449
+ this.state = this.stack[0];
450
+ this.stack.length = 0;
451
+ }
452
+ /**
453
+ @internal
454
+ */
455
+ sameState(other) {
456
+ if (this.state != other.state || this.stack.length != other.stack.length)
457
+ return false;
458
+ for (let i = 0; i < this.stack.length; i += 3)
459
+ if (this.stack[i] != other.stack[i])
460
+ return false;
461
+ return true;
462
+ }
463
+ /**
464
+ Get the parser used by this stack.
465
+ */
466
+ get parser() { return this.p.parser; }
467
+ /**
468
+ Test whether a given dialect (by numeric ID, as exported from
469
+ the terms file) is enabled.
470
+ */
471
+ dialectEnabled(dialectID) { return this.p.parser.dialect.flags[dialectID]; }
472
+ shiftContext(term, start) {
473
+ if (this.curContext)
474
+ this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
475
+ }
476
+ reduceContext(term, start) {
477
+ if (this.curContext)
478
+ this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
479
+ }
480
+ /**
481
+ @internal
482
+ */
483
+ emitContext() {
484
+ let last = this.buffer.length - 1;
485
+ if (last < 0 || this.buffer[last] != -3)
486
+ this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
487
+ }
488
+ /**
489
+ @internal
490
+ */
491
+ emitLookAhead() {
492
+ let last = this.buffer.length - 1;
493
+ if (last < 0 || this.buffer[last] != -4)
494
+ this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
495
+ }
496
+ updateContext(context) {
497
+ if (context != this.curContext.context) {
498
+ let newCx = new StackContext(this.curContext.tracker, context);
499
+ if (newCx.hash != this.curContext.hash)
500
+ this.emitContext();
501
+ this.curContext = newCx;
502
+ }
503
+ }
504
+ /**
505
+ @internal
506
+ */
507
+ setLookAhead(lookAhead) {
508
+ if (lookAhead > this.lookAhead) {
509
+ this.emitLookAhead();
510
+ this.lookAhead = lookAhead;
511
+ }
512
+ }
513
+ /**
514
+ @internal
515
+ */
516
+ close() {
517
+ if (this.curContext && this.curContext.tracker.strict)
518
+ this.emitContext();
519
+ if (this.lookAhead > 0)
520
+ this.emitLookAhead();
521
+ }
522
+ }
523
+ class StackContext {
524
+ constructor(tracker, context) {
525
+ this.tracker = tracker;
526
+ this.context = context;
527
+ this.hash = tracker.strict ? tracker.hash(context) : 0;
528
+ }
529
+ }
530
+ // Used to cheaply run some reductions to scan ahead without mutating
531
+ // an entire stack
532
+ class SimulatedStack {
533
+ constructor(start) {
534
+ this.start = start;
535
+ this.state = start.state;
536
+ this.stack = start.stack;
537
+ this.base = this.stack.length;
538
+ }
539
+ reduce(action) {
540
+ let term = action & 65535 /* Action.ValueMask */, depth = action >> 19 /* Action.ReduceDepthShift */;
541
+ if (depth == 0) {
542
+ if (this.stack == this.start.stack)
543
+ this.stack = this.stack.slice();
544
+ this.stack.push(this.state, 0, 0);
545
+ this.base += 3;
546
+ }
547
+ else {
548
+ this.base -= (depth - 1) * 3;
549
+ }
550
+ let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
551
+ this.state = goto;
552
+ }
553
+ }
554
+ // This is given to `Tree.build` to build a buffer, and encapsulates
555
+ // the parent-stack-walking necessary to read the nodes.
556
+ class StackBufferCursor {
557
+ constructor(stack, pos, index) {
558
+ this.stack = stack;
559
+ this.pos = pos;
560
+ this.index = index;
561
+ this.buffer = stack.buffer;
562
+ if (this.index == 0)
563
+ this.maybeNext();
564
+ }
565
+ static create(stack, pos = stack.bufferBase + stack.buffer.length) {
566
+ return new StackBufferCursor(stack, pos, pos - stack.bufferBase);
567
+ }
568
+ maybeNext() {
569
+ let next = this.stack.parent;
570
+ if (next != null) {
571
+ this.index = this.stack.bufferBase - next.bufferBase;
572
+ this.stack = next;
573
+ this.buffer = next.buffer;
574
+ }
575
+ }
576
+ get id() { return this.buffer[this.index - 4]; }
577
+ get start() { return this.buffer[this.index - 3]; }
578
+ get end() { return this.buffer[this.index - 2]; }
579
+ get size() { return this.buffer[this.index - 1]; }
580
+ next() {
581
+ this.index -= 4;
582
+ this.pos -= 4;
583
+ if (this.index == 0)
584
+ this.maybeNext();
585
+ }
586
+ fork() {
587
+ return new StackBufferCursor(this.stack, this.pos, this.index);
588
+ }
589
+ }
590
+
591
+ // See lezer-generator/src/encode.ts for comments about the encoding
592
+ // used here
593
+ function decodeArray(input, Type = Uint16Array) {
594
+ if (typeof input != "string")
595
+ return input;
596
+ let array = null;
597
+ for (let pos = 0, out = 0; pos < input.length;) {
598
+ let value = 0;
599
+ for (;;) {
600
+ let next = input.charCodeAt(pos++), stop = false;
601
+ if (next == 126 /* Encode.BigValCode */) {
602
+ value = 65535 /* Encode.BigVal */;
603
+ break;
604
+ }
605
+ if (next >= 92 /* Encode.Gap2 */)
606
+ next--;
607
+ if (next >= 34 /* Encode.Gap1 */)
608
+ next--;
609
+ let digit = next - 32 /* Encode.Start */;
610
+ if (digit >= 46 /* Encode.Base */) {
611
+ digit -= 46 /* Encode.Base */;
612
+ stop = true;
613
+ }
614
+ value += digit;
615
+ if (stop)
616
+ break;
617
+ value *= 46 /* Encode.Base */;
618
+ }
619
+ if (array)
620
+ array[out++] = value;
621
+ else
622
+ array = new Type(value);
623
+ }
624
+ return array;
625
+ }
626
+
627
+ class CachedToken {
628
+ constructor() {
629
+ this.start = -1;
630
+ this.value = -1;
631
+ this.end = -1;
632
+ this.extended = -1;
633
+ this.lookAhead = 0;
634
+ this.mask = 0;
635
+ this.context = 0;
636
+ }
637
+ }
638
+ const nullToken = new CachedToken;
639
+ /**
640
+ [Tokenizers](#lr.ExternalTokenizer) interact with the input
641
+ through this interface. It presents the input as a stream of
642
+ characters, tracking lookahead and hiding the complexity of
643
+ [ranges](#common.Parser.parse^ranges) from tokenizer code.
644
+ */
645
+ class InputStream {
646
+ /**
647
+ @internal
648
+ */
649
+ constructor(
650
+ /**
651
+ @internal
652
+ */
653
+ input,
654
+ /**
655
+ @internal
656
+ */
657
+ ranges) {
658
+ this.input = input;
659
+ this.ranges = ranges;
660
+ /**
661
+ @internal
662
+ */
663
+ this.chunk = "";
664
+ /**
665
+ @internal
666
+ */
667
+ this.chunkOff = 0;
668
+ /**
669
+ Backup chunk
670
+ */
671
+ this.chunk2 = "";
672
+ this.chunk2Pos = 0;
673
+ /**
674
+ The character code of the next code unit in the input, or -1
675
+ when the stream is at the end of the input.
676
+ */
677
+ this.next = -1;
678
+ /**
679
+ @internal
680
+ */
681
+ this.token = nullToken;
682
+ this.rangeIndex = 0;
683
+ this.pos = this.chunkPos = ranges[0].from;
684
+ this.range = ranges[0];
685
+ this.end = ranges[ranges.length - 1].to;
686
+ this.readNext();
687
+ }
688
+ /**
689
+ @internal
690
+ */
691
+ resolveOffset(offset, assoc) {
692
+ let range = this.range, index = this.rangeIndex;
693
+ let pos = this.pos + offset;
694
+ while (pos < range.from) {
695
+ if (!index)
696
+ return null;
697
+ let next = this.ranges[--index];
698
+ pos -= range.from - next.to;
699
+ range = next;
700
+ }
701
+ while (assoc < 0 ? pos > range.to : pos >= range.to) {
702
+ if (index == this.ranges.length - 1)
703
+ return null;
704
+ let next = this.ranges[++index];
705
+ pos += next.from - range.to;
706
+ range = next;
707
+ }
708
+ return pos;
709
+ }
710
+ /**
711
+ @internal
712
+ */
713
+ clipPos(pos) {
714
+ if (pos >= this.range.from && pos < this.range.to)
715
+ return pos;
716
+ for (let range of this.ranges)
717
+ if (range.to > pos)
718
+ return Math.max(pos, range.from);
719
+ return this.end;
720
+ }
721
+ /**
722
+ Look at a code unit near the stream position. `.peek(0)` equals
723
+ `.next`, `.peek(-1)` gives you the previous character, and so
724
+ on.
725
+
726
+ Note that looking around during tokenizing creates dependencies
727
+ on potentially far-away content, which may reduce the
728
+ effectiveness incremental parsing—when looking forward—or even
729
+ cause invalid reparses when looking backward more than 25 code
730
+ units, since the library does not track lookbehind.
731
+ */
732
+ peek(offset) {
733
+ let idx = this.chunkOff + offset, pos, result;
734
+ if (idx >= 0 && idx < this.chunk.length) {
735
+ pos = this.pos + offset;
736
+ result = this.chunk.charCodeAt(idx);
737
+ }
738
+ else {
739
+ let resolved = this.resolveOffset(offset, 1);
740
+ if (resolved == null)
741
+ return -1;
742
+ pos = resolved;
743
+ if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
744
+ result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
745
+ }
746
+ else {
747
+ let i = this.rangeIndex, range = this.range;
748
+ while (range.to <= pos)
749
+ range = this.ranges[++i];
750
+ this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
751
+ if (pos + this.chunk2.length > range.to)
752
+ this.chunk2 = this.chunk2.slice(0, range.to - pos);
753
+ result = this.chunk2.charCodeAt(0);
754
+ }
755
+ }
756
+ if (pos >= this.token.lookAhead)
757
+ this.token.lookAhead = pos + 1;
758
+ return result;
759
+ }
760
+ /**
761
+ Accept a token. By default, the end of the token is set to the
762
+ current stream position, but you can pass an offset (relative to
763
+ the stream position) to change that.
764
+ */
765
+ acceptToken(token, endOffset = 0) {
766
+ let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
767
+ if (end == null || end < this.token.start)
768
+ throw new RangeError("Token end out of bounds");
769
+ this.token.value = token;
770
+ this.token.end = end;
771
+ }
772
+ /**
773
+ Accept a token ending at a specific given position.
774
+ */
775
+ acceptTokenTo(token, endPos) {
776
+ this.token.value = token;
777
+ this.token.end = endPos;
778
+ }
779
+ getChunk() {
780
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
781
+ let { chunk, chunkPos } = this;
782
+ this.chunk = this.chunk2;
783
+ this.chunkPos = this.chunk2Pos;
784
+ this.chunk2 = chunk;
785
+ this.chunk2Pos = chunkPos;
786
+ this.chunkOff = this.pos - this.chunkPos;
787
+ }
788
+ else {
789
+ this.chunk2 = this.chunk;
790
+ this.chunk2Pos = this.chunkPos;
791
+ let nextChunk = this.input.chunk(this.pos);
792
+ let end = this.pos + nextChunk.length;
793
+ this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
794
+ this.chunkPos = this.pos;
795
+ this.chunkOff = 0;
796
+ }
797
+ }
798
+ readNext() {
799
+ if (this.chunkOff >= this.chunk.length) {
800
+ this.getChunk();
801
+ if (this.chunkOff == this.chunk.length)
802
+ return this.next = -1;
803
+ }
804
+ return this.next = this.chunk.charCodeAt(this.chunkOff);
805
+ }
806
+ /**
807
+ Move the stream forward N (defaults to 1) code units. Returns
808
+ the new value of [`next`](#lr.InputStream.next).
809
+ */
810
+ advance(n = 1) {
811
+ this.chunkOff += n;
812
+ while (this.pos + n >= this.range.to) {
813
+ if (this.rangeIndex == this.ranges.length - 1)
814
+ return this.setDone();
815
+ n -= this.range.to - this.pos;
816
+ this.range = this.ranges[++this.rangeIndex];
817
+ this.pos = this.range.from;
818
+ }
819
+ this.pos += n;
820
+ if (this.pos >= this.token.lookAhead)
821
+ this.token.lookAhead = this.pos + 1;
822
+ return this.readNext();
823
+ }
824
+ setDone() {
825
+ this.pos = this.chunkPos = this.end;
826
+ this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
827
+ this.chunk = "";
828
+ return this.next = -1;
829
+ }
830
+ /**
831
+ @internal
832
+ */
833
+ reset(pos, token) {
834
+ if (token) {
835
+ this.token = token;
836
+ token.start = pos;
837
+ token.lookAhead = pos + 1;
838
+ token.value = token.extended = -1;
839
+ }
840
+ else {
841
+ this.token = nullToken;
842
+ }
843
+ if (this.pos != pos) {
844
+ this.pos = pos;
845
+ if (pos == this.end) {
846
+ this.setDone();
847
+ return this;
848
+ }
849
+ while (pos < this.range.from)
850
+ this.range = this.ranges[--this.rangeIndex];
851
+ while (pos >= this.range.to)
852
+ this.range = this.ranges[++this.rangeIndex];
853
+ if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
854
+ this.chunkOff = pos - this.chunkPos;
855
+ }
856
+ else {
857
+ this.chunk = "";
858
+ this.chunkOff = 0;
859
+ }
860
+ this.readNext();
861
+ }
862
+ return this;
863
+ }
864
+ /**
865
+ @internal
866
+ */
867
+ read(from, to) {
868
+ if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
869
+ return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
870
+ if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
871
+ return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
872
+ if (from >= this.range.from && to <= this.range.to)
873
+ return this.input.read(from, to);
874
+ let result = "";
875
+ for (let r of this.ranges) {
876
+ if (r.from >= to)
877
+ break;
878
+ if (r.to > from)
879
+ result += this.input.read(Math.max(r.from, from), Math.min(r.to, to));
880
+ }
881
+ return result;
882
+ }
883
+ }
884
+ /**
885
+ @internal
886
+ */
887
+ class TokenGroup {
888
+ constructor(data, id) {
889
+ this.data = data;
890
+ this.id = id;
891
+ }
892
+ token(input, stack) {
893
+ let { parser } = stack.p;
894
+ readToken(this.data, input, stack, this.id, parser.data, parser.tokenPrecTable);
895
+ }
896
+ }
897
+ TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
898
+ /**
899
+ @hide
900
+ */
901
+ class LocalTokenGroup {
902
+ constructor(data, precTable, elseToken) {
903
+ this.precTable = precTable;
904
+ this.elseToken = elseToken;
905
+ this.data = typeof data == "string" ? decodeArray(data) : data;
906
+ }
907
+ token(input, stack) {
908
+ let start = input.pos, skipped = 0;
909
+ for (;;) {
910
+ let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1);
911
+ readToken(this.data, input, stack, 0, this.data, this.precTable);
912
+ if (input.token.value > -1)
913
+ break;
914
+ if (this.elseToken == null)
915
+ return;
916
+ if (!atEof)
917
+ skipped++;
918
+ if (nextPos == null)
919
+ break;
920
+ input.reset(nextPos, input.token);
921
+ }
922
+ if (skipped) {
923
+ input.reset(start, input.token);
924
+ input.acceptToken(this.elseToken, skipped);
925
+ }
926
+ }
927
+ }
928
+ LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
929
+ /**
930
+ `@external tokens` declarations in the grammar should resolve to
931
+ an instance of this class.
932
+ */
933
+ class ExternalTokenizer {
934
+ /**
935
+ Create a tokenizer. The first argument is the function that,
936
+ given an input stream, scans for the types of tokens it
937
+ recognizes at the stream's position, and calls
938
+ [`acceptToken`](#lr.InputStream.acceptToken) when it finds
939
+ one.
940
+ */
941
+ constructor(
942
+ /**
943
+ @internal
944
+ */
945
+ token, options = {}) {
946
+ this.token = token;
947
+ this.contextual = !!options.contextual;
948
+ this.fallback = !!options.fallback;
949
+ this.extend = !!options.extend;
950
+ }
951
+ }
952
+ // Tokenizer data is stored a big uint16 array containing, for each
953
+ // state:
954
+ //
955
+ // - A group bitmask, indicating what token groups are reachable from
956
+ // this state, so that paths that can only lead to tokens not in
957
+ // any of the current groups can be cut off early.
958
+ //
959
+ // - The position of the end of the state's sequence of accepting
960
+ // tokens
961
+ //
962
+ // - The number of outgoing edges for the state
963
+ //
964
+ // - The accepting tokens, as (token id, group mask) pairs
965
+ //
966
+ // - The outgoing edges, as (start character, end character, state
967
+ // index) triples, with end character being exclusive
968
+ //
969
+ // This function interprets that data, running through a stream as
970
+ // long as new states with the a matching group mask can be reached,
971
+ // and updating `input.token` when it matches a token.
972
+ function readToken(data, input, stack, group, precTable, precOffset) {
973
+ let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
974
+ scan: for (;;) {
975
+ if ((groupMask & data[state]) == 0)
976
+ break;
977
+ let accEnd = data[state + 1];
978
+ // Check whether this state can lead to a token in the current group
979
+ // Accept tokens in this state, possibly overwriting
980
+ // lower-precedence / shorter tokens
981
+ for (let i = state + 3; i < accEnd; i += 2)
982
+ if ((data[i + 1] & groupMask) > 0) {
983
+ let term = data[i];
984
+ if (dialect.allows(term) &&
985
+ (input.token.value == -1 || input.token.value == term ||
986
+ overrides(term, input.token.value, precTable, precOffset))) {
987
+ input.acceptToken(term);
988
+ break;
989
+ }
990
+ }
991
+ let next = input.next, low = 0, high = data[state + 2];
992
+ // Special case for EOF
993
+ if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535 /* Seq.End */) {
994
+ state = data[accEnd + high * 3 - 1];
995
+ continue scan;
996
+ }
997
+ // Do a binary search on the state's edges
998
+ for (; low < high;) {
999
+ let mid = (low + high) >> 1;
1000
+ let index = accEnd + mid + (mid << 1);
1001
+ let from = data[index], to = data[index + 1] || 0x10000;
1002
+ if (next < from)
1003
+ high = mid;
1004
+ else if (next >= to)
1005
+ low = mid + 1;
1006
+ else {
1007
+ state = data[index + 2];
1008
+ input.advance();
1009
+ continue scan;
1010
+ }
1011
+ }
1012
+ break;
1013
+ }
1014
+ }
1015
+ function findOffset(data, start, term) {
1016
+ for (let i = start, next; (next = data[i]) != 65535 /* Seq.End */; i++)
1017
+ if (next == term)
1018
+ return i - start;
1019
+ return -1;
1020
+ }
1021
+ function overrides(token, prev, tableData, tableOffset) {
1022
+ let iPrev = findOffset(tableData, tableOffset, prev);
1023
+ return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
1024
+ }
1025
+
1026
+ // Environment variable used to control console output
1027
+ const verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
1028
+ let stackIDs = null;
1029
+ function cutAt(tree, pos, side) {
1030
+ let cursor = tree.cursor(IterMode.IncludeAnonymous);
1031
+ cursor.moveTo(pos);
1032
+ for (;;) {
1033
+ if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
1034
+ for (;;) {
1035
+ if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
1036
+ return side < 0 ? Math.max(0, Math.min(cursor.to - 1, pos - 25 /* Safety.Margin */))
1037
+ : Math.min(tree.length, Math.max(cursor.from + 1, pos + 25 /* Safety.Margin */));
1038
+ if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
1039
+ break;
1040
+ if (!cursor.parent())
1041
+ return side < 0 ? 0 : tree.length;
1042
+ }
1043
+ }
1044
+ }
1045
+ class FragmentCursor {
1046
+ constructor(fragments, nodeSet) {
1047
+ this.fragments = fragments;
1048
+ this.nodeSet = nodeSet;
1049
+ this.i = 0;
1050
+ this.fragment = null;
1051
+ this.safeFrom = -1;
1052
+ this.safeTo = -1;
1053
+ this.trees = [];
1054
+ this.start = [];
1055
+ this.index = [];
1056
+ this.nextFragment();
1057
+ }
1058
+ nextFragment() {
1059
+ let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
1060
+ if (fr) {
1061
+ this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
1062
+ this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
1063
+ while (this.trees.length) {
1064
+ this.trees.pop();
1065
+ this.start.pop();
1066
+ this.index.pop();
1067
+ }
1068
+ this.trees.push(fr.tree);
1069
+ this.start.push(-fr.offset);
1070
+ this.index.push(0);
1071
+ this.nextStart = this.safeFrom;
1072
+ }
1073
+ else {
1074
+ this.nextStart = 1e9;
1075
+ }
1076
+ }
1077
+ // `pos` must be >= any previously given `pos` for this cursor
1078
+ nodeAt(pos) {
1079
+ if (pos < this.nextStart)
1080
+ return null;
1081
+ while (this.fragment && this.safeTo <= pos)
1082
+ this.nextFragment();
1083
+ if (!this.fragment)
1084
+ return null;
1085
+ for (;;) {
1086
+ let last = this.trees.length - 1;
1087
+ if (last < 0) { // End of tree
1088
+ this.nextFragment();
1089
+ return null;
1090
+ }
1091
+ let top = this.trees[last], index = this.index[last];
1092
+ if (index == top.children.length) {
1093
+ this.trees.pop();
1094
+ this.start.pop();
1095
+ this.index.pop();
1096
+ continue;
1097
+ }
1098
+ let next = top.children[index];
1099
+ let start = this.start[last] + top.positions[index];
1100
+ if (start > pos) {
1101
+ this.nextStart = start;
1102
+ return null;
1103
+ }
1104
+ if (next instanceof Tree) {
1105
+ if (start == pos) {
1106
+ if (start < this.safeFrom)
1107
+ return null;
1108
+ let end = start + next.length;
1109
+ if (end <= this.safeTo) {
1110
+ let lookAhead = next.prop(NodeProp.lookAhead);
1111
+ if (!lookAhead || end + lookAhead < this.fragment.to)
1112
+ return next;
1113
+ }
1114
+ }
1115
+ this.index[last]++;
1116
+ if (start + next.length >= Math.max(this.safeFrom, pos)) { // Enter this node
1117
+ this.trees.push(next);
1118
+ this.start.push(start);
1119
+ this.index.push(0);
1120
+ }
1121
+ }
1122
+ else {
1123
+ this.index[last]++;
1124
+ this.nextStart = start + next.length;
1125
+ }
1126
+ }
1127
+ }
1128
+ }
1129
+ class TokenCache {
1130
+ constructor(parser, stream) {
1131
+ this.stream = stream;
1132
+ this.tokens = [];
1133
+ this.mainToken = null;
1134
+ this.actions = [];
1135
+ this.tokens = parser.tokenizers.map(_ => new CachedToken);
1136
+ }
1137
+ getActions(stack) {
1138
+ let actionIndex = 0;
1139
+ let main = null;
1140
+ let { parser } = stack.p, { tokenizers } = parser;
1141
+ let mask = parser.stateSlot(stack.state, 3 /* ParseState.TokenizerMask */);
1142
+ let context = stack.curContext ? stack.curContext.hash : 0;
1143
+ let lookAhead = 0;
1144
+ for (let i = 0; i < tokenizers.length; i++) {
1145
+ if (((1 << i) & mask) == 0)
1146
+ continue;
1147
+ let tokenizer = tokenizers[i], token = this.tokens[i];
1148
+ if (main && !tokenizer.fallback)
1149
+ continue;
1150
+ if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
1151
+ this.updateCachedToken(token, tokenizer, stack);
1152
+ token.mask = mask;
1153
+ token.context = context;
1154
+ }
1155
+ if (token.lookAhead > token.end + 25 /* Safety.Margin */)
1156
+ lookAhead = Math.max(token.lookAhead, lookAhead);
1157
+ if (token.value != 0 /* Term.Err */) {
1158
+ let startIndex = actionIndex;
1159
+ if (token.extended > -1)
1160
+ actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
1161
+ actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
1162
+ if (!tokenizer.extend) {
1163
+ main = token;
1164
+ if (actionIndex > startIndex)
1165
+ break;
1166
+ }
1167
+ }
1168
+ }
1169
+ while (this.actions.length > actionIndex)
1170
+ this.actions.pop();
1171
+ if (lookAhead)
1172
+ stack.setLookAhead(lookAhead);
1173
+ if (!main && stack.pos == this.stream.end) {
1174
+ main = new CachedToken;
1175
+ main.value = stack.p.parser.eofTerm;
1176
+ main.start = main.end = stack.pos;
1177
+ actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
1178
+ }
1179
+ this.mainToken = main;
1180
+ return this.actions;
1181
+ }
1182
+ getMainToken(stack) {
1183
+ if (this.mainToken)
1184
+ return this.mainToken;
1185
+ let main = new CachedToken, { pos, p } = stack;
1186
+ main.start = pos;
1187
+ main.end = Math.min(pos + 1, p.stream.end);
1188
+ main.value = pos == p.stream.end ? p.parser.eofTerm : 0 /* Term.Err */;
1189
+ return main;
1190
+ }
1191
+ updateCachedToken(token, tokenizer, stack) {
1192
+ let start = this.stream.clipPos(stack.pos);
1193
+ tokenizer.token(this.stream.reset(start, token), stack);
1194
+ if (token.value > -1) {
1195
+ let { parser } = stack.p;
1196
+ for (let i = 0; i < parser.specialized.length; i++)
1197
+ if (parser.specialized[i] == token.value) {
1198
+ let result = parser.specializers[i](this.stream.read(token.start, token.end), stack);
1199
+ if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
1200
+ if ((result & 1) == 0 /* Specialize.Specialize */)
1201
+ token.value = result >> 1;
1202
+ else
1203
+ token.extended = result >> 1;
1204
+ break;
1205
+ }
1206
+ }
1207
+ }
1208
+ else {
1209
+ token.value = 0 /* Term.Err */;
1210
+ token.end = this.stream.clipPos(start + 1);
1211
+ }
1212
+ }
1213
+ putAction(action, token, end, index) {
1214
+ // Don't add duplicate actions
1215
+ for (let i = 0; i < index; i += 3)
1216
+ if (this.actions[i] == action)
1217
+ return index;
1218
+ this.actions[index++] = action;
1219
+ this.actions[index++] = token;
1220
+ this.actions[index++] = end;
1221
+ return index;
1222
+ }
1223
+ addActions(stack, token, end, index) {
1224
+ let { state } = stack, { parser } = stack.p, { data } = parser;
1225
+ for (let set = 0; set < 2; set++) {
1226
+ for (let i = parser.stateSlot(state, set ? 2 /* ParseState.Skip */ : 1 /* ParseState.Actions */);; i += 3) {
1227
+ if (data[i] == 65535 /* Seq.End */) {
1228
+ if (data[i + 1] == 1 /* Seq.Next */) {
1229
+ i = pair(data, i + 2);
1230
+ }
1231
+ else {
1232
+ if (index == 0 && data[i + 1] == 2 /* Seq.Other */)
1233
+ index = this.putAction(pair(data, i + 2), token, end, index);
1234
+ break;
1235
+ }
1236
+ }
1237
+ if (data[i] == token)
1238
+ index = this.putAction(pair(data, i + 1), token, end, index);
1239
+ }
1240
+ }
1241
+ return index;
1242
+ }
1243
+ }
1244
+ class Parse {
1245
+ constructor(parser, input, fragments, ranges) {
1246
+ this.parser = parser;
1247
+ this.input = input;
1248
+ this.ranges = ranges;
1249
+ this.recovering = 0;
1250
+ this.nextStackID = 0x2654; // ♔, ♕, ♖, ♗, ♘, ♙, ♠, ♡, ♢, ♣, ♤, ♥, ♦, ♧
1251
+ this.minStackPos = 0;
1252
+ this.reused = [];
1253
+ this.stoppedAt = null;
1254
+ this.lastBigReductionStart = -1;
1255
+ this.lastBigReductionSize = 0;
1256
+ this.bigReductionCount = 0;
1257
+ this.stream = new InputStream(input, ranges);
1258
+ this.tokens = new TokenCache(parser, this.stream);
1259
+ this.topTerm = parser.top[1];
1260
+ let { from } = ranges[0];
1261
+ this.stacks = [Stack.start(this, parser.top[0], from)];
1262
+ this.fragments = fragments.length && this.stream.end - from > parser.bufferLength * 4
1263
+ ? new FragmentCursor(fragments, parser.nodeSet) : null;
1264
+ }
1265
+ get parsedPos() {
1266
+ return this.minStackPos;
1267
+ }
1268
+ // Move the parser forward. This will process all parse stacks at
1269
+ // `this.pos` and try to advance them to a further position. If no
1270
+ // stack for such a position is found, it'll start error-recovery.
1271
+ //
1272
+ // When the parse is finished, this will return a syntax tree. When
1273
+ // not, it returns `null`.
1274
+ advance() {
1275
+ let stacks = this.stacks, pos = this.minStackPos;
1276
+ // This will hold stacks beyond `pos`.
1277
+ let newStacks = this.stacks = [];
1278
+ let stopped, stoppedTokens;
1279
+ // If a large amount of reductions happened with the same start
1280
+ // position, force the stack out of that production in order to
1281
+ // avoid creating a tree too deep to recurse through.
1282
+ // (This is an ugly kludge, because unfortunately there is no
1283
+ // straightforward, cheap way to check for this happening, due to
1284
+ // the history of reductions only being available in an
1285
+ // expensive-to-access format in the stack buffers.)
1286
+ if (this.bigReductionCount > 300 /* Rec.MaxLeftAssociativeReductionCount */ && stacks.length == 1) {
1287
+ let [s] = stacks;
1288
+ while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) { }
1289
+ this.bigReductionCount = this.lastBigReductionSize = 0;
1290
+ }
1291
+ // Keep advancing any stacks at `pos` until they either move
1292
+ // forward or can't be advanced. Gather stacks that can't be
1293
+ // advanced further in `stopped`.
1294
+ for (let i = 0; i < stacks.length; i++) {
1295
+ let stack = stacks[i];
1296
+ for (;;) {
1297
+ this.tokens.mainToken = null;
1298
+ if (stack.pos > pos) {
1299
+ newStacks.push(stack);
1300
+ }
1301
+ else if (this.advanceStack(stack, newStacks, stacks)) {
1302
+ continue;
1303
+ }
1304
+ else {
1305
+ if (!stopped) {
1306
+ stopped = [];
1307
+ stoppedTokens = [];
1308
+ }
1309
+ stopped.push(stack);
1310
+ let tok = this.tokens.getMainToken(stack);
1311
+ stoppedTokens.push(tok.value, tok.end);
1312
+ }
1313
+ break;
1314
+ }
1315
+ }
1316
+ if (!newStacks.length) {
1317
+ let finished = stopped && findFinished(stopped);
1318
+ if (finished) {
1319
+ if (verbose)
1320
+ console.log("Finish with " + this.stackID(finished));
1321
+ return this.stackToTree(finished);
1322
+ }
1323
+ if (this.parser.strict) {
1324
+ if (verbose && stopped)
1325
+ console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
1326
+ throw new SyntaxError("No parse at " + pos);
1327
+ }
1328
+ if (!this.recovering)
1329
+ this.recovering = 5 /* Rec.Distance */;
1330
+ }
1331
+ if (this.recovering && stopped) {
1332
+ let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0]
1333
+ : this.runRecovery(stopped, stoppedTokens, newStacks);
1334
+ if (finished) {
1335
+ if (verbose)
1336
+ console.log("Force-finish " + this.stackID(finished));
1337
+ return this.stackToTree(finished.forceAll());
1338
+ }
1339
+ }
1340
+ if (this.recovering) {
1341
+ let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3 /* Rec.MaxRemainingPerStep */;
1342
+ if (newStacks.length > maxRemaining) {
1343
+ newStacks.sort((a, b) => b.score - a.score);
1344
+ while (newStacks.length > maxRemaining)
1345
+ newStacks.pop();
1346
+ }
1347
+ if (newStacks.some(s => s.reducePos > pos))
1348
+ this.recovering--;
1349
+ }
1350
+ else if (newStacks.length > 1) {
1351
+ // Prune stacks that are in the same state, or that have been
1352
+ // running without splitting for a while, to avoid getting stuck
1353
+ // with multiple successful stacks running endlessly on.
1354
+ outer: for (let i = 0; i < newStacks.length - 1; i++) {
1355
+ let stack = newStacks[i];
1356
+ for (let j = i + 1; j < newStacks.length; j++) {
1357
+ let other = newStacks[j];
1358
+ if (stack.sameState(other) ||
1359
+ stack.buffer.length > 500 /* Rec.MinBufferLengthPrune */ && other.buffer.length > 500 /* Rec.MinBufferLengthPrune */) {
1360
+ if (((stack.score - other.score) || (stack.buffer.length - other.buffer.length)) > 0) {
1361
+ newStacks.splice(j--, 1);
1362
+ }
1363
+ else {
1364
+ newStacks.splice(i--, 1);
1365
+ continue outer;
1366
+ }
1367
+ }
1368
+ }
1369
+ }
1370
+ if (newStacks.length > 12 /* Rec.MaxStackCount */)
1371
+ newStacks.splice(12 /* Rec.MaxStackCount */, newStacks.length - 12 /* Rec.MaxStackCount */);
1372
+ }
1373
+ this.minStackPos = newStacks[0].pos;
1374
+ for (let i = 1; i < newStacks.length; i++)
1375
+ if (newStacks[i].pos < this.minStackPos)
1376
+ this.minStackPos = newStacks[i].pos;
1377
+ return null;
1378
+ }
1379
+ stopAt(pos) {
1380
+ if (this.stoppedAt != null && this.stoppedAt < pos)
1381
+ throw new RangeError("Can't move stoppedAt forward");
1382
+ this.stoppedAt = pos;
1383
+ }
1384
+ // Returns an updated version of the given stack, or null if the
1385
+ // stack can't advance normally. When `split` and `stacks` are
1386
+ // given, stacks split off by ambiguous operations will be pushed to
1387
+ // `split`, or added to `stacks` if they move `pos` forward.
1388
+ advanceStack(stack, stacks, split) {
1389
+ let start = stack.pos, { parser } = this;
1390
+ let base = verbose ? this.stackID(stack) + " -> " : "";
1391
+ if (this.stoppedAt != null && start > this.stoppedAt)
1392
+ return stack.forceReduce() ? stack : null;
1393
+ if (this.fragments) {
1394
+ let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
1395
+ for (let cached = this.fragments.nodeAt(start); cached;) {
1396
+ let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser.getGoto(stack.state, cached.type.id) : -1;
1397
+ if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
1398
+ stack.useNode(cached, match);
1399
+ if (verbose)
1400
+ console.log(base + this.stackID(stack) + ` (via reuse of ${parser.getName(cached.type.id)})`);
1401
+ return true;
1402
+ }
1403
+ if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
1404
+ break;
1405
+ let inner = cached.children[0];
1406
+ if (inner instanceof Tree && cached.positions[0] == 0)
1407
+ cached = inner;
1408
+ else
1409
+ break;
1410
+ }
1411
+ }
1412
+ let defaultReduce = parser.stateSlot(stack.state, 4 /* ParseState.DefaultReduce */);
1413
+ if (defaultReduce > 0) {
1414
+ stack.reduce(defaultReduce);
1415
+ if (verbose)
1416
+ console.log(base + this.stackID(stack) + ` (via always-reduce ${parser.getName(defaultReduce & 65535 /* Action.ValueMask */)})`);
1417
+ return true;
1418
+ }
1419
+ if (stack.stack.length >= 8400 /* Rec.CutDepth */) {
1420
+ while (stack.stack.length > 6000 /* Rec.CutTo */ && stack.forceReduce()) { }
1421
+ }
1422
+ let actions = this.tokens.getActions(stack);
1423
+ for (let i = 0; i < actions.length;) {
1424
+ let action = actions[i++], term = actions[i++], end = actions[i++];
1425
+ let last = i == actions.length || !split;
1426
+ let localStack = last ? stack : stack.split();
1427
+ let main = this.tokens.mainToken;
1428
+ localStack.apply(action, term, main ? main.start : localStack.pos, end);
1429
+ if (verbose)
1430
+ console.log(base + this.stackID(localStack) + ` (via ${(action & 65536 /* Action.ReduceFlag */) == 0 ? "shift"
1431
+ : `reduce of ${parser.getName(action & 65535 /* Action.ValueMask */)}`} for ${parser.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
1432
+ if (last)
1433
+ return true;
1434
+ else if (localStack.pos > start)
1435
+ stacks.push(localStack);
1436
+ else
1437
+ split.push(localStack);
1438
+ }
1439
+ return false;
1440
+ }
1441
+ // Advance a given stack forward as far as it will go. Returns the
1442
+ // (possibly updated) stack if it got stuck, or null if it moved
1443
+ // forward and was given to `pushStackDedup`.
1444
+ advanceFully(stack, newStacks) {
1445
+ let pos = stack.pos;
1446
+ for (;;) {
1447
+ if (!this.advanceStack(stack, null, null))
1448
+ return false;
1449
+ if (stack.pos > pos) {
1450
+ pushStackDedup(stack, newStacks);
1451
+ return true;
1452
+ }
1453
+ }
1454
+ }
1455
+ runRecovery(stacks, tokens, newStacks) {
1456
+ let finished = null, restarted = false;
1457
+ for (let i = 0; i < stacks.length; i++) {
1458
+ let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
1459
+ let base = verbose ? this.stackID(stack) + " -> " : "";
1460
+ if (stack.deadEnd) {
1461
+ if (restarted)
1462
+ continue;
1463
+ restarted = true;
1464
+ stack.restart();
1465
+ if (verbose)
1466
+ console.log(base + this.stackID(stack) + " (restarted)");
1467
+ let done = this.advanceFully(stack, newStacks);
1468
+ if (done)
1469
+ continue;
1470
+ }
1471
+ let force = stack.split(), forceBase = base;
1472
+ for (let j = 0; force.forceReduce() && j < 10 /* Rec.ForceReduceLimit */; j++) {
1473
+ if (verbose)
1474
+ console.log(forceBase + this.stackID(force) + " (via force-reduce)");
1475
+ let done = this.advanceFully(force, newStacks);
1476
+ if (done)
1477
+ break;
1478
+ if (verbose)
1479
+ forceBase = this.stackID(force) + " -> ";
1480
+ }
1481
+ for (let insert of stack.recoverByInsert(token)) {
1482
+ if (verbose)
1483
+ console.log(base + this.stackID(insert) + " (via recover-insert)");
1484
+ this.advanceFully(insert, newStacks);
1485
+ }
1486
+ if (this.stream.end > stack.pos) {
1487
+ if (tokenEnd == stack.pos) {
1488
+ tokenEnd++;
1489
+ token = 0 /* Term.Err */;
1490
+ }
1491
+ stack.recoverByDelete(token, tokenEnd);
1492
+ if (verbose)
1493
+ console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
1494
+ pushStackDedup(stack, newStacks);
1495
+ }
1496
+ else if (!finished || finished.score < stack.score) {
1497
+ finished = stack;
1498
+ }
1499
+ }
1500
+ return finished;
1501
+ }
1502
+ // Convert the stack's buffer to a syntax tree.
1503
+ stackToTree(stack) {
1504
+ stack.close();
1505
+ return Tree.build({ buffer: StackBufferCursor.create(stack),
1506
+ nodeSet: this.parser.nodeSet,
1507
+ topID: this.topTerm,
1508
+ maxBufferLength: this.parser.bufferLength,
1509
+ reused: this.reused,
1510
+ start: this.ranges[0].from,
1511
+ length: stack.pos - this.ranges[0].from,
1512
+ minRepeatType: this.parser.minRepeatTerm });
1513
+ }
1514
+ stackID(stack) {
1515
+ let id = (stackIDs || (stackIDs = new WeakMap)).get(stack);
1516
+ if (!id)
1517
+ stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
1518
+ return id + stack;
1519
+ }
1520
+ }
1521
+ function pushStackDedup(stack, newStacks) {
1522
+ for (let i = 0; i < newStacks.length; i++) {
1523
+ let other = newStacks[i];
1524
+ if (other.pos == stack.pos && other.sameState(stack)) {
1525
+ if (newStacks[i].score < stack.score)
1526
+ newStacks[i] = stack;
1527
+ return;
1528
+ }
1529
+ }
1530
+ newStacks.push(stack);
1531
+ }
1532
+ class Dialect {
1533
+ constructor(source, flags, disabled) {
1534
+ this.source = source;
1535
+ this.flags = flags;
1536
+ this.disabled = disabled;
1537
+ }
1538
+ allows(term) { return !this.disabled || this.disabled[term] == 0; }
1539
+ }
1540
+ const id = x => x;
1541
+ /**
1542
+ Context trackers are used to track stateful context (such as
1543
+ indentation in the Python grammar, or parent elements in the XML
1544
+ grammar) needed by external tokenizers. You declare them in a
1545
+ grammar file as `@context exportName from "module"`.
1546
+
1547
+ Context values should be immutable, and can be updated (replaced)
1548
+ on shift or reduce actions.
1549
+
1550
+ The export used in a `@context` declaration should be of this
1551
+ type.
1552
+ */
1553
+ class ContextTracker {
1554
+ /**
1555
+ Define a context tracker.
1556
+ */
1557
+ constructor(spec) {
1558
+ this.start = spec.start;
1559
+ this.shift = spec.shift || id;
1560
+ this.reduce = spec.reduce || id;
1561
+ this.reuse = spec.reuse || id;
1562
+ this.hash = spec.hash || (() => 0);
1563
+ this.strict = spec.strict !== false;
1564
+ }
1565
+ }
1566
+ /**
1567
+ Holds the parse tables for a given grammar, as generated by
1568
+ `lezer-generator`, and provides [methods](#common.Parser) to parse
1569
+ content with.
1570
+ */
1571
+ class LRParser extends Parser {
1572
+ /**
1573
+ @internal
1574
+ */
1575
+ constructor(spec) {
1576
+ super();
1577
+ /**
1578
+ @internal
1579
+ */
1580
+ this.wrappers = [];
1581
+ if (spec.version != 14 /* File.Version */)
1582
+ throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14 /* File.Version */})`);
1583
+ let nodeNames = spec.nodeNames.split(" ");
1584
+ this.minRepeatTerm = nodeNames.length;
1585
+ for (let i = 0; i < spec.repeatNodeCount; i++)
1586
+ nodeNames.push("");
1587
+ let topTerms = Object.keys(spec.topRules).map(r => spec.topRules[r][1]);
1588
+ let nodeProps = [];
1589
+ for (let i = 0; i < nodeNames.length; i++)
1590
+ nodeProps.push([]);
1591
+ function setProp(nodeID, prop, value) {
1592
+ nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
1593
+ }
1594
+ if (spec.nodeProps)
1595
+ for (let propSpec of spec.nodeProps) {
1596
+ let prop = propSpec[0];
1597
+ if (typeof prop == "string")
1598
+ prop = NodeProp[prop];
1599
+ for (let i = 1; i < propSpec.length;) {
1600
+ let next = propSpec[i++];
1601
+ if (next >= 0) {
1602
+ setProp(next, prop, propSpec[i++]);
1603
+ }
1604
+ else {
1605
+ let value = propSpec[i + -next];
1606
+ for (let j = -next; j > 0; j--)
1607
+ setProp(propSpec[i++], prop, value);
1608
+ i++;
1609
+ }
1610
+ }
1611
+ }
1612
+ this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
1613
+ name: i >= this.minRepeatTerm ? undefined : name,
1614
+ id: i,
1615
+ props: nodeProps[i],
1616
+ top: topTerms.indexOf(i) > -1,
1617
+ error: i == 0,
1618
+ skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
1619
+ })));
1620
+ if (spec.propSources)
1621
+ this.nodeSet = this.nodeSet.extend(...spec.propSources);
1622
+ this.strict = false;
1623
+ this.bufferLength = DefaultBufferLength;
1624
+ let tokenArray = decodeArray(spec.tokenData);
1625
+ this.context = spec.context;
1626
+ this.specializerSpecs = spec.specialized || [];
1627
+ this.specialized = new Uint16Array(this.specializerSpecs.length);
1628
+ for (let i = 0; i < this.specializerSpecs.length; i++)
1629
+ this.specialized[i] = this.specializerSpecs[i].term;
1630
+ this.specializers = this.specializerSpecs.map(getSpecializer);
1631
+ this.states = decodeArray(spec.states, Uint32Array);
1632
+ this.data = decodeArray(spec.stateData);
1633
+ this.goto = decodeArray(spec.goto);
1634
+ this.maxTerm = spec.maxTerm;
1635
+ this.tokenizers = spec.tokenizers.map(value => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
1636
+ this.topRules = spec.topRules;
1637
+ this.dialects = spec.dialects || {};
1638
+ this.dynamicPrecedences = spec.dynamicPrecedences || null;
1639
+ this.tokenPrecTable = spec.tokenPrec;
1640
+ this.termNames = spec.termNames || null;
1641
+ this.maxNode = this.nodeSet.types.length - 1;
1642
+ this.dialect = this.parseDialect();
1643
+ this.top = this.topRules[Object.keys(this.topRules)[0]];
1644
+ }
1645
+ createParse(input, fragments, ranges) {
1646
+ let parse = new Parse(this, input, fragments, ranges);
1647
+ for (let w of this.wrappers)
1648
+ parse = w(parse, input, fragments, ranges);
1649
+ return parse;
1650
+ }
1651
+ /**
1652
+ Get a goto table entry @internal
1653
+ */
1654
+ getGoto(state, term, loose = false) {
1655
+ let table = this.goto;
1656
+ if (term >= table[0])
1657
+ return -1;
1658
+ for (let pos = table[term + 1];;) {
1659
+ let groupTag = table[pos++], last = groupTag & 1;
1660
+ let target = table[pos++];
1661
+ if (last && loose)
1662
+ return target;
1663
+ for (let end = pos + (groupTag >> 1); pos < end; pos++)
1664
+ if (table[pos] == state)
1665
+ return target;
1666
+ if (last)
1667
+ return -1;
1668
+ }
1669
+ }
1670
+ /**
1671
+ Check if this state has an action for a given terminal @internal
1672
+ */
1673
+ hasAction(state, terminal) {
1674
+ let data = this.data;
1675
+ for (let set = 0; set < 2; set++) {
1676
+ for (let i = this.stateSlot(state, set ? 2 /* ParseState.Skip */ : 1 /* ParseState.Actions */), next;; i += 3) {
1677
+ if ((next = data[i]) == 65535 /* Seq.End */) {
1678
+ if (data[i + 1] == 1 /* Seq.Next */)
1679
+ next = data[i = pair(data, i + 2)];
1680
+ else if (data[i + 1] == 2 /* Seq.Other */)
1681
+ return pair(data, i + 2);
1682
+ else
1683
+ break;
1684
+ }
1685
+ if (next == terminal || next == 0 /* Term.Err */)
1686
+ return pair(data, i + 1);
1687
+ }
1688
+ }
1689
+ return 0;
1690
+ }
1691
+ /**
1692
+ @internal
1693
+ */
1694
+ stateSlot(state, slot) {
1695
+ return this.states[(state * 6 /* ParseState.Size */) + slot];
1696
+ }
1697
+ /**
1698
+ @internal
1699
+ */
1700
+ stateFlag(state, flag) {
1701
+ return (this.stateSlot(state, 0 /* ParseState.Flags */) & flag) > 0;
1702
+ }
1703
+ /**
1704
+ @internal
1705
+ */
1706
+ validAction(state, action) {
1707
+ return !!this.allActions(state, a => a == action ? true : null);
1708
+ }
1709
+ /**
1710
+ @internal
1711
+ */
1712
+ allActions(state, action) {
1713
+ let deflt = this.stateSlot(state, 4 /* ParseState.DefaultReduce */);
1714
+ let result = deflt ? action(deflt) : undefined;
1715
+ for (let i = this.stateSlot(state, 1 /* ParseState.Actions */); result == null; i += 3) {
1716
+ if (this.data[i] == 65535 /* Seq.End */) {
1717
+ if (this.data[i + 1] == 1 /* Seq.Next */)
1718
+ i = pair(this.data, i + 2);
1719
+ else
1720
+ break;
1721
+ }
1722
+ result = action(pair(this.data, i + 1));
1723
+ }
1724
+ return result;
1725
+ }
1726
+ /**
1727
+ Get the states that can follow this one through shift actions or
1728
+ goto jumps. @internal
1729
+ */
1730
+ nextStates(state) {
1731
+ let result = [];
1732
+ for (let i = this.stateSlot(state, 1 /* ParseState.Actions */);; i += 3) {
1733
+ if (this.data[i] == 65535 /* Seq.End */) {
1734
+ if (this.data[i + 1] == 1 /* Seq.Next */)
1735
+ i = pair(this.data, i + 2);
1736
+ else
1737
+ break;
1738
+ }
1739
+ if ((this.data[i + 2] & (65536 /* Action.ReduceFlag */ >> 16)) == 0) {
1740
+ let value = this.data[i + 1];
1741
+ if (!result.some((v, i) => (i & 1) && v == value))
1742
+ result.push(this.data[i], value);
1743
+ }
1744
+ }
1745
+ return result;
1746
+ }
1747
+ /**
1748
+ Configure the parser. Returns a new parser instance that has the
1749
+ given settings modified. Settings not provided in `config` are
1750
+ kept from the original parser.
1751
+ */
1752
+ configure(config) {
1753
+ // Hideous reflection-based kludge to make it easy to create a
1754
+ // slightly modified copy of a parser.
1755
+ let copy = Object.assign(Object.create(LRParser.prototype), this);
1756
+ if (config.props)
1757
+ copy.nodeSet = this.nodeSet.extend(...config.props);
1758
+ if (config.top) {
1759
+ let info = this.topRules[config.top];
1760
+ if (!info)
1761
+ throw new RangeError(`Invalid top rule name ${config.top}`);
1762
+ copy.top = info;
1763
+ }
1764
+ if (config.tokenizers)
1765
+ copy.tokenizers = this.tokenizers.map(t => {
1766
+ let found = config.tokenizers.find(r => r.from == t);
1767
+ return found ? found.to : t;
1768
+ });
1769
+ if (config.specializers) {
1770
+ copy.specializers = this.specializers.slice();
1771
+ copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
1772
+ let found = config.specializers.find(r => r.from == s.external);
1773
+ if (!found)
1774
+ return s;
1775
+ let spec = Object.assign(Object.assign({}, s), { external: found.to });
1776
+ copy.specializers[i] = getSpecializer(spec);
1777
+ return spec;
1778
+ });
1779
+ }
1780
+ if (config.contextTracker)
1781
+ copy.context = config.contextTracker;
1782
+ if (config.dialect)
1783
+ copy.dialect = this.parseDialect(config.dialect);
1784
+ if (config.strict != null)
1785
+ copy.strict = config.strict;
1786
+ if (config.wrap)
1787
+ copy.wrappers = copy.wrappers.concat(config.wrap);
1788
+ if (config.bufferLength != null)
1789
+ copy.bufferLength = config.bufferLength;
1790
+ return copy;
1791
+ }
1792
+ /**
1793
+ Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
1794
+ are registered for this parser.
1795
+ */
1796
+ hasWrappers() {
1797
+ return this.wrappers.length > 0;
1798
+ }
1799
+ /**
1800
+ Returns the name associated with a given term. This will only
1801
+ work for all terms when the parser was generated with the
1802
+ `--names` option. By default, only the names of tagged terms are
1803
+ stored.
1804
+ */
1805
+ getName(term) {
1806
+ return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
1807
+ }
1808
+ /**
1809
+ The eof term id is always allocated directly after the node
1810
+ types. @internal
1811
+ */
1812
+ get eofTerm() { return this.maxNode + 1; }
1813
+ /**
1814
+ The type of top node produced by the parser.
1815
+ */
1816
+ get topNode() { return this.nodeSet.types[this.top[1]]; }
1817
+ /**
1818
+ @internal
1819
+ */
1820
+ dynamicPrecedence(term) {
1821
+ let prec = this.dynamicPrecedences;
1822
+ return prec == null ? 0 : prec[term] || 0;
1823
+ }
1824
+ /**
1825
+ @internal
1826
+ */
1827
+ parseDialect(dialect) {
1828
+ let values = Object.keys(this.dialects), flags = values.map(() => false);
1829
+ if (dialect)
1830
+ for (let part of dialect.split(" ")) {
1831
+ let id = values.indexOf(part);
1832
+ if (id >= 0)
1833
+ flags[id] = true;
1834
+ }
1835
+ let disabled = null;
1836
+ for (let i = 0; i < values.length; i++)
1837
+ if (!flags[i]) {
1838
+ for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535 /* Seq.End */;)
1839
+ (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
1840
+ }
1841
+ return new Dialect(dialect, flags, disabled);
1842
+ }
1843
+ /**
1844
+ Used by the output of the parser generator. Not available to
1845
+ user code. @hide
1846
+ */
1847
+ static deserialize(spec) {
1848
+ return new LRParser(spec);
1849
+ }
1850
+ }
1851
+ function pair(data, off) { return data[off] | (data[off + 1] << 16); }
1852
+ function findFinished(stacks) {
1853
+ let best = null;
1854
+ for (let stack of stacks) {
1855
+ let stopped = stack.p.stoppedAt;
1856
+ if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) &&
1857
+ stack.p.parser.stateFlag(stack.state, 2 /* StateFlag.Accepting */) &&
1858
+ (!best || best.score < stack.score))
1859
+ best = stack;
1860
+ }
1861
+ return best;
1862
+ }
1863
+ function getSpecializer(spec) {
1864
+ if (spec.external) {
1865
+ let mask = spec.extend ? 1 /* Specialize.Extend */ : 0 /* Specialize.Specialize */;
1866
+ return (value, stack) => (spec.external(value, stack) << 1) | mask;
1867
+ }
1868
+ return spec.get;
1869
+ }
1870
+
1871
+ export { ContextTracker, ExternalTokenizer, InputStream, LRParser, LocalTokenGroup, Stack };
1872
+ //# sourceMappingURL=index.js.map