@milkdown/crepe 7.3.3

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 (241) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/lib/apl-p0IPP13W.js +76 -0
  4. package/lib/asciiarmor-lJsBxlJJ.js +34 -0
  5. package/lib/asn1-Q9v1zIy5.js +102 -0
  6. package/lib/asterisk-foNkeTjy.js +273 -0
  7. package/lib/brainfuck-0XqyXpNS.js +35 -0
  8. package/lib/clike-ak6Z6Yhe.js +639 -0
  9. package/lib/clojure-iYO8U8Sg.js +810 -0
  10. package/lib/clsx-7d8NmkQq.js +21 -0
  11. package/lib/cmake-SVzjkxV_.js +28 -0
  12. package/lib/cobol-APHEnAOX.js +74 -0
  13. package/lib/coffeescript-KqQa0SYG.js +182 -0
  14. package/lib/commonlisp-bwqNqR5V.js +79 -0
  15. package/lib/core/crepe.d.ts +21 -0
  16. package/lib/core/crepe.d.ts.map +1 -0
  17. package/lib/core/index.d.ts +3 -0
  18. package/lib/core/index.d.ts.map +1 -0
  19. package/lib/core/slice.d.ts +12 -0
  20. package/lib/core/slice.d.ts.map +1 -0
  21. package/lib/crystal-BViWuDpA.js +217 -0
  22. package/lib/css-KHXHXfXg.js +1572 -0
  23. package/lib/cypher-XpTt4zQ3.js +69 -0
  24. package/lib/d-fLig6yqY.js +139 -0
  25. package/lib/diff-WoKGLpy6.js +18 -0
  26. package/lib/dockerfile-u6f6Vw2s.js +194 -0
  27. package/lib/dtd-SIJRUW6K.js +91 -0
  28. package/lib/dylan-4HCLhpWP.js +238 -0
  29. package/lib/ebnf-h_0lged5.js +77 -0
  30. package/lib/ecl-Lf4FF0lf.js +133 -0
  31. package/lib/eiffel-qlw8KUyf.js +112 -0
  32. package/lib/elm-QRnB3zXs.js +108 -0
  33. package/lib/erlang-fyVKb7eK.js +488 -0
  34. package/lib/factor-BEeN4upY.js +65 -0
  35. package/lib/fcl-lRek3hEb.js +106 -0
  36. package/lib/feature/block-edit/handle/component.d.ts +9 -0
  37. package/lib/feature/block-edit/handle/component.d.ts.map +1 -0
  38. package/lib/feature/block-edit/handle/index.d.ts +12 -0
  39. package/lib/feature/block-edit/handle/index.d.ts.map +1 -0
  40. package/lib/feature/block-edit/index.d.ts +3 -0
  41. package/lib/feature/block-edit/index.d.ts.map +1 -0
  42. package/lib/feature/block-edit/menu/component.d.ts +14 -0
  43. package/lib/feature/block-edit/menu/component.d.ts.map +1 -0
  44. package/lib/feature/block-edit/menu/config.d.ts +21 -0
  45. package/lib/feature/block-edit/menu/config.d.ts.map +1 -0
  46. package/lib/feature/block-edit/menu/icons.d.ts +14 -0
  47. package/lib/feature/block-edit/menu/icons.d.ts.map +1 -0
  48. package/lib/feature/block-edit/menu/index.d.ts +9 -0
  49. package/lib/feature/block-edit/menu/index.d.ts.map +1 -0
  50. package/lib/feature/code-mirror/index.d.ts +3 -0
  51. package/lib/feature/code-mirror/index.d.ts.map +1 -0
  52. package/lib/feature/gap-cursor/index.d.ts +3 -0
  53. package/lib/feature/gap-cursor/index.d.ts.map +1 -0
  54. package/lib/feature/image-block/index.d.ts +3 -0
  55. package/lib/feature/image-block/index.d.ts.map +1 -0
  56. package/lib/feature/index.d.ts +18 -0
  57. package/lib/feature/index.d.ts.map +1 -0
  58. package/lib/feature/link-tooltip/consts.d.ts +5 -0
  59. package/lib/feature/link-tooltip/consts.d.ts.map +1 -0
  60. package/lib/feature/link-tooltip/index.d.ts +3 -0
  61. package/lib/feature/link-tooltip/index.d.ts.map +1 -0
  62. package/lib/feature/list-item/consts.d.ts +2 -0
  63. package/lib/feature/list-item/consts.d.ts.map +1 -0
  64. package/lib/feature/list-item/index.d.ts +3 -0
  65. package/lib/feature/list-item/index.d.ts.map +1 -0
  66. package/lib/feature/placeholder/index.d.ts +10 -0
  67. package/lib/feature/placeholder/index.d.ts.map +1 -0
  68. package/lib/feature/shared.d.ts +3 -0
  69. package/lib/feature/shared.d.ts.map +1 -0
  70. package/lib/feature/toolbar/component.d.ts +13 -0
  71. package/lib/feature/toolbar/component.d.ts.map +1 -0
  72. package/lib/feature/toolbar/consts.d.ts +5 -0
  73. package/lib/feature/toolbar/consts.d.ts.map +1 -0
  74. package/lib/feature/toolbar/index.d.ts +3 -0
  75. package/lib/feature/toolbar/index.d.ts.map +1 -0
  76. package/lib/forth-ua2bRd8T.js +60 -0
  77. package/lib/fortran-WnF7znuN.js +443 -0
  78. package/lib/gas-wowve1o7.js +183 -0
  79. package/lib/gherkin-m7GIChu3.js +34 -0
  80. package/lib/go-th443Dhb.js +158 -0
  81. package/lib/groovy-tR4RiZnc.js +161 -0
  82. package/lib/haskell-jxVBofv5.js +375 -0
  83. package/lib/haxe-kWPI2tq3.js +390 -0
  84. package/lib/hooks-82sqkbtE.js +21 -0
  85. package/lib/http-3GIFWUlG.js +45 -0
  86. package/lib/icons-HYkfuR-O.js +50 -0
  87. package/lib/idl-PvpMZg-l.js +947 -0
  88. package/lib/index-0RbcZMbq.js +8 -0
  89. package/lib/index-4afXjFMY.js +517 -0
  90. package/lib/index-7MeyepDG.js +78 -0
  91. package/lib/index-7QgQq3x3.js +551 -0
  92. package/lib/index-7pgP6qYs.js +107 -0
  93. package/lib/index-8DvtgRVa.js +19511 -0
  94. package/lib/index-8Gg-jEP4.js +288 -0
  95. package/lib/index-8S8qcncB.js +507 -0
  96. package/lib/index-9A_GmGh4.js +1039 -0
  97. package/lib/index-EJJfYLzA.js +928 -0
  98. package/lib/index-Eg39w5kL.js +984 -0
  99. package/lib/index-FIk_7oPb.js +168 -0
  100. package/lib/index-LlbrXb_n.js +368 -0
  101. package/lib/index-MovKtgMG.js +121 -0
  102. package/lib/index-N9GtIS4X.js +64 -0
  103. package/lib/index-Pwn25-kf.js +8 -0
  104. package/lib/index-SdFSDosa.js +1295 -0
  105. package/lib/index-W5Th22-Z.js +1744 -0
  106. package/lib/index-XiXSFLmI.js +20975 -0
  107. package/lib/index-bknOViGv.js +47 -0
  108. package/lib/index-bkuIUPFS.js +275 -0
  109. package/lib/index-jPA8J9Eo.js +8 -0
  110. package/lib/index-lsG76a9s.js +552 -0
  111. package/lib/index-oTRzPo3B.js +146 -0
  112. package/lib/index-rrf6_6DC.js +317 -0
  113. package/lib/index-vJbZIHYF.js +81 -0
  114. package/lib/index-vPRh55CO.js +137 -0
  115. package/lib/index-vxy63hib.js +323 -0
  116. package/lib/index-wn1_LgCS.js +99 -0
  117. package/lib/index-xHADmDT3.js +12 -0
  118. package/lib/index-yt2EpMtv.js +141 -0
  119. package/lib/index.d.ts +4 -0
  120. package/lib/index.d.ts.map +1 -0
  121. package/lib/index.es.js +7 -0
  122. package/lib/javascript-8ZHqHagw.js +758 -0
  123. package/lib/jinja2-vsOFe0qD.js +154 -0
  124. package/lib/julia-dlp_pbN1.js +241 -0
  125. package/lib/livescript-Gf5R-LT6.js +273 -0
  126. package/lib/lua-c5Y_JsBp.js +221 -0
  127. package/lib/mathematica-iiGTGmUs.js +35 -0
  128. package/lib/mbox-ZJh86H8B.js +78 -0
  129. package/lib/meta-tAGyVRPE.js +511 -0
  130. package/lib/mirc-i0qkCa0y.js +73 -0
  131. package/lib/mllike-Dy551fZW.js +275 -0
  132. package/lib/modelica-n6tGqUT9.js +94 -0
  133. package/lib/mscgen-aKSbB7D9.js +104 -0
  134. package/lib/mumps-lNiKA6sp.js +25 -0
  135. package/lib/nginx--YmuCfDj.js +93 -0
  136. package/lib/nsis-zhS8iA09.js +62 -0
  137. package/lib/ntriples-E3jQl3MC.js +79 -0
  138. package/lib/octave-EQvkGIeG.js +144 -0
  139. package/lib/oz-W2cpqFf6.js +152 -0
  140. package/lib/pascal-lCh6ouNZ.js +79 -0
  141. package/lib/perl-PxEQBX0B.js +915 -0
  142. package/lib/pig-Y_bNcrzS.js +56 -0
  143. package/lib/powershell-GaQP-TZr.js +249 -0
  144. package/lib/properties-mbRyn54L.js +26 -0
  145. package/lib/prosemirror-noTDkx-k.js +4 -0
  146. package/lib/protobuf-8CJideyJ.js +49 -0
  147. package/lib/puppet-ABBaChNZ.js +45 -0
  148. package/lib/python-sKdHg3Ka.js +321 -0
  149. package/lib/q-_1yG40Nm.js +89 -0
  150. package/lib/r-Ziz56bHT.js +108 -0
  151. package/lib/rpm-ORjGOHaQ.js +57 -0
  152. package/lib/ruby-jlbYq0dT.js +233 -0
  153. package/lib/sas-2n7xeUuO.js +107 -0
  154. package/lib/schema-tKk3m1fu.js +62 -0
  155. package/lib/scheme-XCs-NPeU.js +126 -0
  156. package/lib/shell-0_1Um7Dq.js +184 -0
  157. package/lib/sieve-7uyJD1x1.js +73 -0
  158. package/lib/simple-mode--HIzBxba.js +95 -0
  159. package/lib/smalltalk-PEFzrlQ-.js +48 -0
  160. package/lib/solr-BLBaHahN.js +41 -0
  161. package/lib/sparql-4F9ZWf1b.js +204 -0
  162. package/lib/spreadsheet-SGSo6blj.js +49 -0
  163. package/lib/sql-tebLBzN0.js +291 -0
  164. package/lib/stex-SFJcFGOO.js +130 -0
  165. package/lib/stylus-rwwWYWFm.js +256 -0
  166. package/lib/swift-eorJ0tCv.js +238 -0
  167. package/lib/tcl-IwXMB8U4.js +82 -0
  168. package/lib/textile-ok2VyjwC.js +299 -0
  169. package/lib/theme/classic/index.d.ts +3 -0
  170. package/lib/theme/classic/index.d.ts.map +1 -0
  171. package/lib/theme/classic-dark/index.d.ts +3 -0
  172. package/lib/theme/classic-dark/index.d.ts.map +1 -0
  173. package/lib/theme/headless/index.d.ts +3 -0
  174. package/lib/theme/headless/index.d.ts.map +1 -0
  175. package/lib/theme/index.d.ts +8 -0
  176. package/lib/theme/index.d.ts.map +1 -0
  177. package/lib/theme/shared.d.ts +3 -0
  178. package/lib/theme/shared.d.ts.map +1 -0
  179. package/lib/tiddlywiki-DLhz8_pc.js +156 -0
  180. package/lib/tiki-DFAqFElY.js +183 -0
  181. package/lib/tippy.esm-MZ2vxByW.js +1813 -0
  182. package/lib/toml-ryxpTZEV.js +49 -0
  183. package/lib/tooltip-plugin-gcwyQdiT.js +119 -0
  184. package/lib/troff-ZzZyvNct.js +36 -0
  185. package/lib/ttcn-6gvkqqpW.js +136 -0
  186. package/lib/ttcn-cfg-oSu-Dq5C.js +98 -0
  187. package/lib/turtle-10ofr5au.js +87 -0
  188. package/lib/use-css-light-dom-EKWZDmbJ.js +82 -0
  189. package/lib/utils/index.d.ts +4 -0
  190. package/lib/utils/index.d.ts.map +1 -0
  191. package/lib/vb-a6n6fzrD.js +74 -0
  192. package/lib/vbscript-dgvo8jPt.js +324 -0
  193. package/lib/velocity-CBncCrwO.js +97 -0
  194. package/lib/verilog-KlcACt6C.js +271 -0
  195. package/lib/vhdl-NMd7Gf35.js +117 -0
  196. package/lib/webidl-z1UE5DN_.js +160 -0
  197. package/lib/xquery-hDt5jWTp.js +431 -0
  198. package/lib/yacas-ftgh_qwr.js +74 -0
  199. package/lib/yaml-DnNTfjXK.js +53 -0
  200. package/lib/z80-dA1PqWe1.js +62 -0
  201. package/package.json +87 -0
  202. package/src/core/crepe.ts +98 -0
  203. package/src/core/index.ts +4 -0
  204. package/src/core/slice.ts +44 -0
  205. package/src/feature/block-edit/handle/component.ts +68 -0
  206. package/src/feature/block-edit/handle/index.ts +81 -0
  207. package/src/feature/block-edit/index.ts +17 -0
  208. package/src/feature/block-edit/menu/component.ts +210 -0
  209. package/src/feature/block-edit/menu/config.ts +335 -0
  210. package/src/feature/block-edit/menu/icons.ts +171 -0
  211. package/src/feature/block-edit/menu/index.ts +113 -0
  212. package/src/feature/block-edit/style.css +126 -0
  213. package/src/feature/code-mirror/index.ts +60 -0
  214. package/src/feature/code-mirror/style.css +159 -0
  215. package/src/feature/gap-cursor/index.ts +31 -0
  216. package/src/feature/image-block/index.ts +59 -0
  217. package/src/feature/image-block/style.css +215 -0
  218. package/src/feature/index.ts +66 -0
  219. package/src/feature/link-tooltip/consts.ts +47 -0
  220. package/src/feature/link-tooltip/index.ts +22 -0
  221. package/src/feature/link-tooltip/style.css +107 -0
  222. package/src/feature/list-item/consts.ts +15 -0
  223. package/src/feature/list-item/index.ts +30 -0
  224. package/src/feature/list-item/style.css +23 -0
  225. package/src/feature/placeholder/index.ts +87 -0
  226. package/src/feature/placeholder/style.css +9 -0
  227. package/src/feature/shared.ts +4 -0
  228. package/src/feature/toolbar/component.ts +101 -0
  229. package/src/feature/toolbar/consts.ts +26 -0
  230. package/src/feature/toolbar/index.ts +92 -0
  231. package/src/feature/toolbar/style.css +37 -0
  232. package/src/index.ts +5 -0
  233. package/src/theme/classic/index.ts +12 -0
  234. package/src/theme/classic/style.css +192 -0
  235. package/src/theme/classic-dark/index.ts +12 -0
  236. package/src/theme/classic-dark/style.css +197 -0
  237. package/src/theme/headless/index.ts +9 -0
  238. package/src/theme/index.ts +26 -0
  239. package/src/theme/shared.ts +4 -0
  240. package/src/utils/index.ts +12 -0
  241. package/src/vite-env.d.ts +2 -0
@@ -0,0 +1,1295 @@
1
+ import { P as L, l as M, N as $, G as E, k as y, m as S, I as j } from "./index-8DvtgRVa.js";
2
+ class v {
3
+ /**
4
+ @internal
5
+ */
6
+ constructor(t, e, s, i, h, r, n, o, a, u = 0, f) {
7
+ this.p = t, this.stack = e, this.state = s, this.reducePos = i, this.pos = h, this.score = r, this.buffer = n, this.bufferBase = o, this.curContext = a, this.lookAhead = u, this.parent = f;
8
+ }
9
+ /**
10
+ @internal
11
+ */
12
+ toString() {
13
+ return `[${this.stack.filter((t, e) => e % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
14
+ }
15
+ // Start an empty stack
16
+ /**
17
+ @internal
18
+ */
19
+ static start(t, e, s = 0) {
20
+ let i = t.parser.context;
21
+ return new v(t, [], e, s, s, 0, [], 0, i ? new N(i, i.start) : null, 0, null);
22
+ }
23
+ /**
24
+ The stack's current [context](#lr.ContextTracker) value, if
25
+ any. Its type will depend on the context tracker's type
26
+ parameter, or it will be `null` if there is no context
27
+ tracker.
28
+ */
29
+ get context() {
30
+ return this.curContext ? this.curContext.context : null;
31
+ }
32
+ // Push a state onto the stack, tracking its start position as well
33
+ // as the buffer base at that point.
34
+ /**
35
+ @internal
36
+ */
37
+ pushState(t, e) {
38
+ this.stack.push(this.state, e, this.bufferBase + this.buffer.length), this.state = t;
39
+ }
40
+ // Apply a reduce action
41
+ /**
42
+ @internal
43
+ */
44
+ reduce(t) {
45
+ var e;
46
+ let s = t >> 19, i = t & 65535, { parser: h } = this.p, r = h.dynamicPrecedence(i);
47
+ if (r && (this.score += r), s == 0) {
48
+ this.pushState(h.getGoto(this.state, i, !0), this.reducePos), i < h.minRepeatTerm && this.storeNode(i, this.reducePos, this.reducePos, 4, !0), this.reduceContext(i, this.reducePos);
49
+ return;
50
+ }
51
+ let n = this.stack.length - (s - 1) * 3 - (t & 262144 ? 6 : 0), o = n ? this.stack[n - 2] : this.p.ranges[0].from, a = this.reducePos - o;
52
+ a >= 2e3 && !(!((e = this.p.parser.nodeSet.types[i]) === null || e === void 0) && e.isAnonymous) && (o == this.p.lastBigReductionStart ? (this.p.bigReductionCount++, this.p.lastBigReductionSize = a) : this.p.lastBigReductionSize < a && (this.p.bigReductionCount = 1, this.p.lastBigReductionStart = o, this.p.lastBigReductionSize = a));
53
+ let u = n ? this.stack[n - 1] : 0, f = this.bufferBase + this.buffer.length - u;
54
+ if (i < h.minRepeatTerm || t & 131072) {
55
+ let c = h.stateFlag(
56
+ this.state,
57
+ 1
58
+ /* StateFlag.Skipped */
59
+ ) ? this.pos : this.reducePos;
60
+ this.storeNode(i, o, c, f + 4, !0);
61
+ }
62
+ if (t & 262144)
63
+ this.state = this.stack[n];
64
+ else {
65
+ let c = this.stack[n - 3];
66
+ this.state = h.getGoto(c, i, !0);
67
+ }
68
+ for (; this.stack.length > n; )
69
+ this.stack.pop();
70
+ this.reduceContext(i, o);
71
+ }
72
+ // Shift a value into the buffer
73
+ /**
74
+ @internal
75
+ */
76
+ storeNode(t, e, s, i = 4, h = !1) {
77
+ if (t == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
78
+ let r = this, n = this.buffer.length;
79
+ if (n == 0 && r.parent && (n = r.bufferBase - r.parent.bufferBase, r = r.parent), n > 0 && r.buffer[n - 4] == 0 && r.buffer[n - 1] > -1) {
80
+ if (e == s)
81
+ return;
82
+ if (r.buffer[n - 2] >= e) {
83
+ r.buffer[n - 2] = s;
84
+ return;
85
+ }
86
+ }
87
+ }
88
+ if (!h || this.pos == s)
89
+ this.buffer.push(t, e, s, i);
90
+ else {
91
+ let r = this.buffer.length;
92
+ if (r > 0 && this.buffer[r - 4] != 0)
93
+ for (; r > 0 && this.buffer[r - 2] > s; )
94
+ this.buffer[r] = this.buffer[r - 4], this.buffer[r + 1] = this.buffer[r - 3], this.buffer[r + 2] = this.buffer[r - 2], this.buffer[r + 3] = this.buffer[r - 1], r -= 4, i > 4 && (i -= 4);
95
+ this.buffer[r] = t, this.buffer[r + 1] = e, this.buffer[r + 2] = s, this.buffer[r + 3] = i;
96
+ }
97
+ }
98
+ // Apply a shift action
99
+ /**
100
+ @internal
101
+ */
102
+ shift(t, e, s, i) {
103
+ if (t & 131072)
104
+ this.pushState(t & 65535, this.pos);
105
+ else if (t & 262144)
106
+ this.pos = i, this.shiftContext(e, s), e <= this.p.parser.maxNode && this.buffer.push(e, s, i, 4);
107
+ else {
108
+ let h = t, { parser: r } = this.p;
109
+ (i > this.pos || e <= r.maxNode) && (this.pos = i, r.stateFlag(
110
+ h,
111
+ 1
112
+ /* StateFlag.Skipped */
113
+ ) || (this.reducePos = i)), this.pushState(h, s), this.shiftContext(e, s), e <= r.maxNode && this.buffer.push(e, s, i, 4);
114
+ }
115
+ }
116
+ // Apply an action
117
+ /**
118
+ @internal
119
+ */
120
+ apply(t, e, s, i) {
121
+ t & 65536 ? this.reduce(t) : this.shift(t, e, s, i);
122
+ }
123
+ // Add a prebuilt (reused) node into the buffer.
124
+ /**
125
+ @internal
126
+ */
127
+ useNode(t, e) {
128
+ let s = this.p.reused.length - 1;
129
+ (s < 0 || this.p.reused[s] != t) && (this.p.reused.push(t), s++);
130
+ let i = this.pos;
131
+ this.reducePos = this.pos = i + t.length, this.pushState(e, i), this.buffer.push(
132
+ s,
133
+ i,
134
+ this.reducePos,
135
+ -1
136
+ /* size == -1 means this is a reused value */
137
+ ), this.curContext && this.updateContext(this.curContext.tracker.reuse(this.curContext.context, t, this, this.p.stream.reset(this.pos - t.length)));
138
+ }
139
+ // Split the stack. Due to the buffer sharing and the fact
140
+ // that `this.stack` tends to stay quite shallow, this isn't very
141
+ // expensive.
142
+ /**
143
+ @internal
144
+ */
145
+ split() {
146
+ let t = this, e = t.buffer.length;
147
+ for (; e > 0 && t.buffer[e - 2] > t.reducePos; )
148
+ e -= 4;
149
+ let s = t.buffer.slice(e), i = t.bufferBase + e;
150
+ for (; t && i == t.bufferBase; )
151
+ t = t.parent;
152
+ return new v(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, s, i, this.curContext, this.lookAhead, t);
153
+ }
154
+ // Try to recover from an error by 'deleting' (ignoring) one token.
155
+ /**
156
+ @internal
157
+ */
158
+ recoverByDelete(t, e) {
159
+ let s = t <= this.p.parser.maxNode;
160
+ s && this.storeNode(t, this.pos, e, 4), this.storeNode(0, this.pos, e, s ? 8 : 4), this.pos = this.reducePos = e, this.score -= 190;
161
+ }
162
+ /**
163
+ Check if the given term would be able to be shifted (optionally
164
+ after some reductions) on this stack. This can be useful for
165
+ external tokenizers that want to make sure they only provide a
166
+ given token when it applies.
167
+ */
168
+ canShift(t) {
169
+ for (let e = new G(this); ; ) {
170
+ let s = this.p.parser.stateSlot(
171
+ e.state,
172
+ 4
173
+ /* ParseState.DefaultReduce */
174
+ ) || this.p.parser.hasAction(e.state, t);
175
+ if (s == 0)
176
+ return !1;
177
+ if (!(s & 65536))
178
+ return !0;
179
+ e.reduce(s);
180
+ }
181
+ }
182
+ // Apply up to Recover.MaxNext recovery actions that conceptually
183
+ // inserts some missing token or rule.
184
+ /**
185
+ @internal
186
+ */
187
+ recoverByInsert(t) {
188
+ if (this.stack.length >= 300)
189
+ return [];
190
+ let e = this.p.parser.nextStates(this.state);
191
+ if (e.length > 8 || this.stack.length >= 120) {
192
+ let i = [];
193
+ for (let h = 0, r; h < e.length; h += 2)
194
+ (r = e[h + 1]) != this.state && this.p.parser.hasAction(r, t) && i.push(e[h], r);
195
+ if (this.stack.length < 120)
196
+ for (let h = 0; i.length < 8 && h < e.length; h += 2) {
197
+ let r = e[h + 1];
198
+ i.some((n, o) => o & 1 && n == r) || i.push(e[h], r);
199
+ }
200
+ e = i;
201
+ }
202
+ let s = [];
203
+ for (let i = 0; i < e.length && s.length < 4; i += 2) {
204
+ let h = e[i + 1];
205
+ if (h == this.state)
206
+ continue;
207
+ let r = this.split();
208
+ r.pushState(h, this.pos), r.storeNode(0, r.pos, r.pos, 4, !0), r.shiftContext(e[i], this.pos), r.reducePos = this.pos, r.score -= 200, s.push(r);
209
+ }
210
+ return s;
211
+ }
212
+ // Force a reduce, if possible. Return false if that can't
213
+ // be done.
214
+ /**
215
+ @internal
216
+ */
217
+ forceReduce() {
218
+ let { parser: t } = this.p, e = t.stateSlot(
219
+ this.state,
220
+ 5
221
+ /* ParseState.ForcedReduce */
222
+ );
223
+ if (!(e & 65536))
224
+ return !1;
225
+ if (!t.validAction(this.state, e)) {
226
+ let s = e >> 19, i = e & 65535, h = this.stack.length - s * 3;
227
+ if (h < 0 || t.getGoto(this.stack[h], i, !1) < 0) {
228
+ let r = this.findForcedReduction();
229
+ if (r == null)
230
+ return !1;
231
+ e = r;
232
+ }
233
+ this.storeNode(0, this.pos, this.pos, 4, !0), this.score -= 100;
234
+ }
235
+ return this.reducePos = this.pos, this.reduce(e), !0;
236
+ }
237
+ /**
238
+ Try to scan through the automaton to find some kind of reduction
239
+ that can be applied. Used when the regular ForcedReduce field
240
+ isn't a valid action. @internal
241
+ */
242
+ findForcedReduction() {
243
+ let { parser: t } = this.p, e = [], s = (i, h) => {
244
+ if (!e.includes(i))
245
+ return e.push(i), t.allActions(i, (r) => {
246
+ if (!(r & 393216))
247
+ if (r & 65536) {
248
+ let n = (r >> 19) - h;
249
+ if (n > 1) {
250
+ let o = r & 65535, a = this.stack.length - n * 3;
251
+ if (a >= 0 && t.getGoto(this.stack[a], o, !1) >= 0)
252
+ return n << 19 | 65536 | o;
253
+ }
254
+ } else {
255
+ let n = s(r, h + 1);
256
+ if (n != null)
257
+ return n;
258
+ }
259
+ });
260
+ };
261
+ return s(this.state, 0);
262
+ }
263
+ /**
264
+ @internal
265
+ */
266
+ forceAll() {
267
+ for (; !this.p.parser.stateFlag(
268
+ this.state,
269
+ 2
270
+ /* StateFlag.Accepting */
271
+ ); )
272
+ if (!this.forceReduce()) {
273
+ this.storeNode(0, this.pos, this.pos, 4, !0);
274
+ break;
275
+ }
276
+ return this;
277
+ }
278
+ /**
279
+ Check whether this state has no further actions (assumed to be a direct descendant of the
280
+ top state, since any other states must be able to continue
281
+ somehow). @internal
282
+ */
283
+ get deadEnd() {
284
+ if (this.stack.length != 3)
285
+ return !1;
286
+ let { parser: t } = this.p;
287
+ return t.data[t.stateSlot(
288
+ this.state,
289
+ 1
290
+ /* ParseState.Actions */
291
+ )] == 65535 && !t.stateSlot(
292
+ this.state,
293
+ 4
294
+ /* ParseState.DefaultReduce */
295
+ );
296
+ }
297
+ /**
298
+ Restart the stack (put it back in its start state). Only safe
299
+ when this.stack.length == 3 (state is directly below the top
300
+ state). @internal
301
+ */
302
+ restart() {
303
+ this.storeNode(0, this.pos, this.pos, 4, !0), this.state = this.stack[0], this.stack.length = 0;
304
+ }
305
+ /**
306
+ @internal
307
+ */
308
+ sameState(t) {
309
+ if (this.state != t.state || this.stack.length != t.stack.length)
310
+ return !1;
311
+ for (let e = 0; e < this.stack.length; e += 3)
312
+ if (this.stack[e] != t.stack[e])
313
+ return !1;
314
+ return !0;
315
+ }
316
+ /**
317
+ Get the parser used by this stack.
318
+ */
319
+ get parser() {
320
+ return this.p.parser;
321
+ }
322
+ /**
323
+ Test whether a given dialect (by numeric ID, as exported from
324
+ the terms file) is enabled.
325
+ */
326
+ dialectEnabled(t) {
327
+ return this.p.parser.dialect.flags[t];
328
+ }
329
+ shiftContext(t, e) {
330
+ this.curContext && this.updateContext(this.curContext.tracker.shift(this.curContext.context, t, this, this.p.stream.reset(e)));
331
+ }
332
+ reduceContext(t, e) {
333
+ this.curContext && this.updateContext(this.curContext.tracker.reduce(this.curContext.context, t, this, this.p.stream.reset(e)));
334
+ }
335
+ /**
336
+ @internal
337
+ */
338
+ emitContext() {
339
+ let t = this.buffer.length - 1;
340
+ (t < 0 || this.buffer[t] != -3) && this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
341
+ }
342
+ /**
343
+ @internal
344
+ */
345
+ emitLookAhead() {
346
+ let t = this.buffer.length - 1;
347
+ (t < 0 || this.buffer[t] != -4) && this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
348
+ }
349
+ updateContext(t) {
350
+ if (t != this.curContext.context) {
351
+ let e = new N(this.curContext.tracker, t);
352
+ e.hash != this.curContext.hash && this.emitContext(), this.curContext = e;
353
+ }
354
+ }
355
+ /**
356
+ @internal
357
+ */
358
+ setLookAhead(t) {
359
+ t > this.lookAhead && (this.emitLookAhead(), this.lookAhead = t);
360
+ }
361
+ /**
362
+ @internal
363
+ */
364
+ close() {
365
+ this.curContext && this.curContext.tracker.strict && this.emitContext(), this.lookAhead > 0 && this.emitLookAhead();
366
+ }
367
+ }
368
+ class N {
369
+ constructor(t, e) {
370
+ this.tracker = t, this.context = e, this.hash = t.strict ? t.hash(e) : 0;
371
+ }
372
+ }
373
+ class G {
374
+ constructor(t) {
375
+ this.start = t, this.state = t.state, this.stack = t.stack, this.base = this.stack.length;
376
+ }
377
+ reduce(t) {
378
+ let e = t & 65535, s = t >> 19;
379
+ s == 0 ? (this.stack == this.start.stack && (this.stack = this.stack.slice()), this.stack.push(this.state, 0, 0), this.base += 3) : this.base -= (s - 1) * 3;
380
+ let i = this.start.p.parser.getGoto(this.stack[this.base - 3], e, !0);
381
+ this.state = i;
382
+ }
383
+ }
384
+ class A {
385
+ constructor(t, e, s) {
386
+ this.stack = t, this.pos = e, this.index = s, this.buffer = t.buffer, this.index == 0 && this.maybeNext();
387
+ }
388
+ static create(t, e = t.bufferBase + t.buffer.length) {
389
+ return new A(t, e, e - t.bufferBase);
390
+ }
391
+ maybeNext() {
392
+ let t = this.stack.parent;
393
+ t != null && (this.index = this.stack.bufferBase - t.bufferBase, this.stack = t, this.buffer = t.buffer);
394
+ }
395
+ get id() {
396
+ return this.buffer[this.index - 4];
397
+ }
398
+ get start() {
399
+ return this.buffer[this.index - 3];
400
+ }
401
+ get end() {
402
+ return this.buffer[this.index - 2];
403
+ }
404
+ get size() {
405
+ return this.buffer[this.index - 1];
406
+ }
407
+ next() {
408
+ this.index -= 4, this.pos -= 4, this.index == 0 && this.maybeNext();
409
+ }
410
+ fork() {
411
+ return new A(this.stack, this.pos, this.index);
412
+ }
413
+ }
414
+ function x(l, t = Uint16Array) {
415
+ if (typeof l != "string")
416
+ return l;
417
+ let e = null;
418
+ for (let s = 0, i = 0; s < l.length; ) {
419
+ let h = 0;
420
+ for (; ; ) {
421
+ let r = l.charCodeAt(s++), n = !1;
422
+ if (r == 126) {
423
+ h = 65535;
424
+ break;
425
+ }
426
+ r >= 92 && r--, r >= 34 && r--;
427
+ let o = r - 32;
428
+ if (o >= 46 && (o -= 46, n = !0), h += o, n)
429
+ break;
430
+ h *= 46;
431
+ }
432
+ e ? e[i++] = h : e = new t(h);
433
+ }
434
+ return e;
435
+ }
436
+ class P {
437
+ constructor() {
438
+ this.start = -1, this.value = -1, this.end = -1, this.extended = -1, this.lookAhead = 0, this.mask = 0, this.context = 0;
439
+ }
440
+ }
441
+ const R = new P();
442
+ class U {
443
+ /**
444
+ @internal
445
+ */
446
+ constructor(t, e) {
447
+ this.input = t, this.ranges = e, this.chunk = "", this.chunkOff = 0, this.chunk2 = "", this.chunk2Pos = 0, this.next = -1, this.token = R, this.rangeIndex = 0, this.pos = this.chunkPos = e[0].from, this.range = e[0], this.end = e[e.length - 1].to, this.readNext();
448
+ }
449
+ /**
450
+ @internal
451
+ */
452
+ resolveOffset(t, e) {
453
+ let s = this.range, i = this.rangeIndex, h = this.pos + t;
454
+ for (; h < s.from; ) {
455
+ if (!i)
456
+ return null;
457
+ let r = this.ranges[--i];
458
+ h -= s.from - r.to, s = r;
459
+ }
460
+ for (; e < 0 ? h > s.to : h >= s.to; ) {
461
+ if (i == this.ranges.length - 1)
462
+ return null;
463
+ let r = this.ranges[++i];
464
+ h += r.from - s.to, s = r;
465
+ }
466
+ return h;
467
+ }
468
+ /**
469
+ @internal
470
+ */
471
+ clipPos(t) {
472
+ if (t >= this.range.from && t < this.range.to)
473
+ return t;
474
+ for (let e of this.ranges)
475
+ if (e.to > t)
476
+ return Math.max(t, e.from);
477
+ return this.end;
478
+ }
479
+ /**
480
+ Look at a code unit near the stream position. `.peek(0)` equals
481
+ `.next`, `.peek(-1)` gives you the previous character, and so
482
+ on.
483
+
484
+ Note that looking around during tokenizing creates dependencies
485
+ on potentially far-away content, which may reduce the
486
+ effectiveness incremental parsing—when looking forward—or even
487
+ cause invalid reparses when looking backward more than 25 code
488
+ units, since the library does not track lookbehind.
489
+ */
490
+ peek(t) {
491
+ let e = this.chunkOff + t, s, i;
492
+ if (e >= 0 && e < this.chunk.length)
493
+ s = this.pos + t, i = this.chunk.charCodeAt(e);
494
+ else {
495
+ let h = this.resolveOffset(t, 1);
496
+ if (h == null)
497
+ return -1;
498
+ if (s = h, s >= this.chunk2Pos && s < this.chunk2Pos + this.chunk2.length)
499
+ i = this.chunk2.charCodeAt(s - this.chunk2Pos);
500
+ else {
501
+ let r = this.rangeIndex, n = this.range;
502
+ for (; n.to <= s; )
503
+ n = this.ranges[++r];
504
+ this.chunk2 = this.input.chunk(this.chunk2Pos = s), s + this.chunk2.length > n.to && (this.chunk2 = this.chunk2.slice(0, n.to - s)), i = this.chunk2.charCodeAt(0);
505
+ }
506
+ }
507
+ return s >= this.token.lookAhead && (this.token.lookAhead = s + 1), i;
508
+ }
509
+ /**
510
+ Accept a token. By default, the end of the token is set to the
511
+ current stream position, but you can pass an offset (relative to
512
+ the stream position) to change that.
513
+ */
514
+ acceptToken(t, e = 0) {
515
+ let s = e ? this.resolveOffset(e, -1) : this.pos;
516
+ if (s == null || s < this.token.start)
517
+ throw new RangeError("Token end out of bounds");
518
+ this.token.value = t, this.token.end = s;
519
+ }
520
+ getChunk() {
521
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
522
+ let { chunk: t, chunkPos: e } = this;
523
+ this.chunk = this.chunk2, this.chunkPos = this.chunk2Pos, this.chunk2 = t, this.chunk2Pos = e, this.chunkOff = this.pos - this.chunkPos;
524
+ } else {
525
+ this.chunk2 = this.chunk, this.chunk2Pos = this.chunkPos;
526
+ let t = this.input.chunk(this.pos), e = this.pos + t.length;
527
+ this.chunk = e > this.range.to ? t.slice(0, this.range.to - this.pos) : t, this.chunkPos = this.pos, this.chunkOff = 0;
528
+ }
529
+ }
530
+ readNext() {
531
+ return this.chunkOff >= this.chunk.length && (this.getChunk(), this.chunkOff == this.chunk.length) ? this.next = -1 : this.next = this.chunk.charCodeAt(this.chunkOff);
532
+ }
533
+ /**
534
+ Move the stream forward N (defaults to 1) code units. Returns
535
+ the new value of [`next`](#lr.InputStream.next).
536
+ */
537
+ advance(t = 1) {
538
+ for (this.chunkOff += t; this.pos + t >= this.range.to; ) {
539
+ if (this.rangeIndex == this.ranges.length - 1)
540
+ return this.setDone();
541
+ t -= this.range.to - this.pos, this.range = this.ranges[++this.rangeIndex], this.pos = this.range.from;
542
+ }
543
+ return this.pos += t, this.pos >= this.token.lookAhead && (this.token.lookAhead = this.pos + 1), this.readNext();
544
+ }
545
+ setDone() {
546
+ return this.pos = this.chunkPos = this.end, this.range = this.ranges[this.rangeIndex = this.ranges.length - 1], this.chunk = "", this.next = -1;
547
+ }
548
+ /**
549
+ @internal
550
+ */
551
+ reset(t, e) {
552
+ if (e ? (this.token = e, e.start = t, e.lookAhead = t + 1, e.value = e.extended = -1) : this.token = R, this.pos != t) {
553
+ if (this.pos = t, t == this.end)
554
+ return this.setDone(), this;
555
+ for (; t < this.range.from; )
556
+ this.range = this.ranges[--this.rangeIndex];
557
+ for (; t >= this.range.to; )
558
+ this.range = this.ranges[++this.rangeIndex];
559
+ t >= this.chunkPos && t < this.chunkPos + this.chunk.length ? this.chunkOff = t - this.chunkPos : (this.chunk = "", this.chunkOff = 0), this.readNext();
560
+ }
561
+ return this;
562
+ }
563
+ /**
564
+ @internal
565
+ */
566
+ read(t, e) {
567
+ if (t >= this.chunkPos && e <= this.chunkPos + this.chunk.length)
568
+ return this.chunk.slice(t - this.chunkPos, e - this.chunkPos);
569
+ if (t >= this.chunk2Pos && e <= this.chunk2Pos + this.chunk2.length)
570
+ return this.chunk2.slice(t - this.chunk2Pos, e - this.chunk2Pos);
571
+ if (t >= this.range.from && e <= this.range.to)
572
+ return this.input.read(t, e);
573
+ let s = "";
574
+ for (let i of this.ranges) {
575
+ if (i.from >= e)
576
+ break;
577
+ i.to > t && (s += this.input.read(Math.max(i.from, t), Math.min(i.to, e)));
578
+ }
579
+ return s;
580
+ }
581
+ }
582
+ class m {
583
+ constructor(t, e) {
584
+ this.data = t, this.id = e;
585
+ }
586
+ token(t, e) {
587
+ let { parser: s } = e.p;
588
+ F(this.data, t, e, this.id, s.data, s.tokenPrecTable);
589
+ }
590
+ }
591
+ m.prototype.contextual = m.prototype.fallback = m.prototype.extend = !1;
592
+ class H {
593
+ constructor(t, e, s) {
594
+ this.precTable = e, this.elseToken = s, this.data = typeof t == "string" ? x(t) : t;
595
+ }
596
+ token(t, e) {
597
+ let s = t.pos, i = 0;
598
+ for (; ; ) {
599
+ let h = t.next < 0, r = t.resolveOffset(1, 1);
600
+ if (F(this.data, t, e, 0, this.data, this.precTable), t.token.value > -1)
601
+ break;
602
+ if (this.elseToken == null)
603
+ return;
604
+ if (h || i++, r == null)
605
+ break;
606
+ t.reset(r, t.token);
607
+ }
608
+ i && (t.reset(s, t.token), t.acceptToken(this.elseToken, i));
609
+ }
610
+ }
611
+ H.prototype.contextual = m.prototype.fallback = m.prototype.extend = !1;
612
+ class Y {
613
+ /**
614
+ Create a tokenizer. The first argument is the function that,
615
+ given an input stream, scans for the types of tokens it
616
+ recognizes at the stream's position, and calls
617
+ [`acceptToken`](#lr.InputStream.acceptToken) when it finds
618
+ one.
619
+ */
620
+ constructor(t, e = {}) {
621
+ this.token = t, this.contextual = !!e.contextual, this.fallback = !!e.fallback, this.extend = !!e.extend;
622
+ }
623
+ }
624
+ function F(l, t, e, s, i, h) {
625
+ let r = 0, n = 1 << s, { dialect: o } = e.p.parser;
626
+ t:
627
+ for (; n & l[r]; ) {
628
+ let a = l[r + 1];
629
+ for (let p = r + 3; p < a; p += 2)
630
+ if ((l[p + 1] & n) > 0) {
631
+ let d = l[p];
632
+ if (o.allows(d) && (t.token.value == -1 || t.token.value == d || W(d, t.token.value, i, h))) {
633
+ t.acceptToken(d);
634
+ break;
635
+ }
636
+ }
637
+ let u = t.next, f = 0, c = l[r + 2];
638
+ if (t.next < 0 && c > f && l[a + c * 3 - 3] == 65535) {
639
+ r = l[a + c * 3 - 1];
640
+ continue t;
641
+ }
642
+ for (; f < c; ) {
643
+ let p = f + c >> 1, d = a + p + (p << 1), b = l[d], O = l[d + 1] || 65536;
644
+ if (u < b)
645
+ c = p;
646
+ else if (u >= O)
647
+ f = p + 1;
648
+ else {
649
+ r = l[d + 2], t.advance();
650
+ continue t;
651
+ }
652
+ }
653
+ break;
654
+ }
655
+ }
656
+ function z(l, t, e) {
657
+ for (let s = t, i; (i = l[s]) != 65535; s++)
658
+ if (i == e)
659
+ return s - t;
660
+ return -1;
661
+ }
662
+ function W(l, t, e, s) {
663
+ let i = z(e, s, t);
664
+ return i < 0 || z(e, s, l) < i;
665
+ }
666
+ const g = typeof process < "u" && process.env && /\bparse\b/.test(process.env.LOG);
667
+ let C = null;
668
+ function I(l, t, e) {
669
+ let s = l.cursor(j.IncludeAnonymous);
670
+ for (s.moveTo(t); ; )
671
+ if (!(e < 0 ? s.childBefore(t) : s.childAfter(t)))
672
+ for (; ; ) {
673
+ if ((e < 0 ? s.to < t : s.from > t) && !s.type.isError)
674
+ return e < 0 ? Math.max(0, Math.min(
675
+ s.to - 1,
676
+ t - 25
677
+ /* Safety.Margin */
678
+ )) : Math.min(l.length, Math.max(
679
+ s.from + 1,
680
+ t + 25
681
+ /* Safety.Margin */
682
+ ));
683
+ if (e < 0 ? s.prevSibling() : s.nextSibling())
684
+ break;
685
+ if (!s.parent())
686
+ return e < 0 ? 0 : l.length;
687
+ }
688
+ }
689
+ class q {
690
+ constructor(t, e) {
691
+ this.fragments = t, this.nodeSet = e, this.i = 0, this.fragment = null, this.safeFrom = -1, this.safeTo = -1, this.trees = [], this.start = [], this.index = [], this.nextFragment();
692
+ }
693
+ nextFragment() {
694
+ let t = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
695
+ if (t) {
696
+ for (this.safeFrom = t.openStart ? I(t.tree, t.from + t.offset, 1) - t.offset : t.from, this.safeTo = t.openEnd ? I(t.tree, t.to + t.offset, -1) - t.offset : t.to; this.trees.length; )
697
+ this.trees.pop(), this.start.pop(), this.index.pop();
698
+ this.trees.push(t.tree), this.start.push(-t.offset), this.index.push(0), this.nextStart = this.safeFrom;
699
+ } else
700
+ this.nextStart = 1e9;
701
+ }
702
+ // `pos` must be >= any previously given `pos` for this cursor
703
+ nodeAt(t) {
704
+ if (t < this.nextStart)
705
+ return null;
706
+ for (; this.fragment && this.safeTo <= t; )
707
+ this.nextFragment();
708
+ if (!this.fragment)
709
+ return null;
710
+ for (; ; ) {
711
+ let e = this.trees.length - 1;
712
+ if (e < 0)
713
+ return this.nextFragment(), null;
714
+ let s = this.trees[e], i = this.index[e];
715
+ if (i == s.children.length) {
716
+ this.trees.pop(), this.start.pop(), this.index.pop();
717
+ continue;
718
+ }
719
+ let h = s.children[i], r = this.start[e] + s.positions[i];
720
+ if (r > t)
721
+ return this.nextStart = r, null;
722
+ if (h instanceof S) {
723
+ if (r == t) {
724
+ if (r < this.safeFrom)
725
+ return null;
726
+ let n = r + h.length;
727
+ if (n <= this.safeTo) {
728
+ let o = h.prop(y.lookAhead);
729
+ if (!o || n + o < this.fragment.to)
730
+ return h;
731
+ }
732
+ }
733
+ this.index[e]++, r + h.length >= Math.max(this.safeFrom, t) && (this.trees.push(h), this.start.push(r), this.index.push(0));
734
+ } else
735
+ this.index[e]++, this.nextStart = r + h.length;
736
+ }
737
+ }
738
+ }
739
+ class J {
740
+ constructor(t, e) {
741
+ this.stream = e, this.tokens = [], this.mainToken = null, this.actions = [], this.tokens = t.tokenizers.map((s) => new P());
742
+ }
743
+ getActions(t) {
744
+ let e = 0, s = null, { parser: i } = t.p, { tokenizers: h } = i, r = i.stateSlot(
745
+ t.state,
746
+ 3
747
+ /* ParseState.TokenizerMask */
748
+ ), n = t.curContext ? t.curContext.hash : 0, o = 0;
749
+ for (let a = 0; a < h.length; a++) {
750
+ if (!(1 << a & r))
751
+ continue;
752
+ let u = h[a], f = this.tokens[a];
753
+ if (!(s && !u.fallback) && ((u.contextual || f.start != t.pos || f.mask != r || f.context != n) && (this.updateCachedToken(f, u, t), f.mask = r, f.context = n), f.lookAhead > f.end + 25 && (o = Math.max(f.lookAhead, o)), f.value != 0)) {
754
+ let c = e;
755
+ if (f.extended > -1 && (e = this.addActions(t, f.extended, f.end, e)), e = this.addActions(t, f.value, f.end, e), !u.extend && (s = f, e > c))
756
+ break;
757
+ }
758
+ }
759
+ for (; this.actions.length > e; )
760
+ this.actions.pop();
761
+ return o && t.setLookAhead(o), !s && t.pos == this.stream.end && (s = new P(), s.value = t.p.parser.eofTerm, s.start = s.end = t.pos, e = this.addActions(t, s.value, s.end, e)), this.mainToken = s, this.actions;
762
+ }
763
+ getMainToken(t) {
764
+ if (this.mainToken)
765
+ return this.mainToken;
766
+ let e = new P(), { pos: s, p: i } = t;
767
+ return e.start = s, e.end = Math.min(s + 1, i.stream.end), e.value = s == i.stream.end ? i.parser.eofTerm : 0, e;
768
+ }
769
+ updateCachedToken(t, e, s) {
770
+ let i = this.stream.clipPos(s.pos);
771
+ if (e.token(this.stream.reset(i, t), s), t.value > -1) {
772
+ let { parser: h } = s.p;
773
+ for (let r = 0; r < h.specialized.length; r++)
774
+ if (h.specialized[r] == t.value) {
775
+ let n = h.specializers[r](this.stream.read(t.start, t.end), s);
776
+ if (n >= 0 && s.p.parser.dialect.allows(n >> 1)) {
777
+ n & 1 ? t.extended = n >> 1 : t.value = n >> 1;
778
+ break;
779
+ }
780
+ }
781
+ } else
782
+ t.value = 0, t.end = this.stream.clipPos(i + 1);
783
+ }
784
+ putAction(t, e, s, i) {
785
+ for (let h = 0; h < i; h += 3)
786
+ if (this.actions[h] == t)
787
+ return i;
788
+ return this.actions[i++] = t, this.actions[i++] = e, this.actions[i++] = s, i;
789
+ }
790
+ addActions(t, e, s, i) {
791
+ let { state: h } = t, { parser: r } = t.p, { data: n } = r;
792
+ for (let o = 0; o < 2; o++)
793
+ for (let a = r.stateSlot(
794
+ h,
795
+ o ? 2 : 1
796
+ /* ParseState.Actions */
797
+ ); ; a += 3) {
798
+ if (n[a] == 65535)
799
+ if (n[a + 1] == 1)
800
+ a = k(n, a + 2);
801
+ else {
802
+ i == 0 && n[a + 1] == 2 && (i = this.putAction(k(n, a + 2), e, s, i));
803
+ break;
804
+ }
805
+ n[a] == e && (i = this.putAction(k(n, a + 1), e, s, i));
806
+ }
807
+ return i;
808
+ }
809
+ }
810
+ class K {
811
+ constructor(t, e, s, i) {
812
+ this.parser = t, this.input = e, this.ranges = i, this.recovering = 0, this.nextStackID = 9812, this.minStackPos = 0, this.reused = [], this.stoppedAt = null, this.lastBigReductionStart = -1, this.lastBigReductionSize = 0, this.bigReductionCount = 0, this.stream = new U(e, i), this.tokens = new J(t, this.stream), this.topTerm = t.top[1];
813
+ let { from: h } = i[0];
814
+ this.stacks = [v.start(this, t.top[0], h)], this.fragments = s.length && this.stream.end - h > t.bufferLength * 4 ? new q(s, t.nodeSet) : null;
815
+ }
816
+ get parsedPos() {
817
+ return this.minStackPos;
818
+ }
819
+ // Move the parser forward. This will process all parse stacks at
820
+ // `this.pos` and try to advance them to a further position. If no
821
+ // stack for such a position is found, it'll start error-recovery.
822
+ //
823
+ // When the parse is finished, this will return a syntax tree. When
824
+ // not, it returns `null`.
825
+ advance() {
826
+ let t = this.stacks, e = this.minStackPos, s = this.stacks = [], i, h;
827
+ if (this.bigReductionCount > 300 && t.length == 1) {
828
+ let [r] = t;
829
+ for (; r.forceReduce() && r.stack.length && r.stack[r.stack.length - 2] >= this.lastBigReductionStart; )
830
+ ;
831
+ this.bigReductionCount = this.lastBigReductionSize = 0;
832
+ }
833
+ for (let r = 0; r < t.length; r++) {
834
+ let n = t[r];
835
+ for (; ; ) {
836
+ if (this.tokens.mainToken = null, n.pos > e)
837
+ s.push(n);
838
+ else {
839
+ if (this.advanceStack(n, s, t))
840
+ continue;
841
+ {
842
+ i || (i = [], h = []), i.push(n);
843
+ let o = this.tokens.getMainToken(n);
844
+ h.push(o.value, o.end);
845
+ }
846
+ }
847
+ break;
848
+ }
849
+ }
850
+ if (!s.length) {
851
+ let r = i && V(i);
852
+ if (r)
853
+ return g && console.log("Finish with " + this.stackID(r)), this.stackToTree(r);
854
+ if (this.parser.strict)
855
+ throw g && i && console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none")), new SyntaxError("No parse at " + e);
856
+ this.recovering || (this.recovering = 5);
857
+ }
858
+ if (this.recovering && i) {
859
+ let r = this.stoppedAt != null && i[0].pos > this.stoppedAt ? i[0] : this.runRecovery(i, h, s);
860
+ if (r)
861
+ return g && console.log("Force-finish " + this.stackID(r)), this.stackToTree(r.forceAll());
862
+ }
863
+ if (this.recovering) {
864
+ let r = this.recovering == 1 ? 1 : this.recovering * 3;
865
+ if (s.length > r)
866
+ for (s.sort((n, o) => o.score - n.score); s.length > r; )
867
+ s.pop();
868
+ s.some((n) => n.reducePos > e) && this.recovering--;
869
+ } else if (s.length > 1) {
870
+ t:
871
+ for (let r = 0; r < s.length - 1; r++) {
872
+ let n = s[r];
873
+ for (let o = r + 1; o < s.length; o++) {
874
+ let a = s[o];
875
+ if (n.sameState(a) || n.buffer.length > 500 && a.buffer.length > 500)
876
+ if ((n.score - a.score || n.buffer.length - a.buffer.length) > 0)
877
+ s.splice(o--, 1);
878
+ else {
879
+ s.splice(r--, 1);
880
+ continue t;
881
+ }
882
+ }
883
+ }
884
+ s.length > 12 && s.splice(
885
+ 12,
886
+ s.length - 12
887
+ /* Rec.MaxStackCount */
888
+ );
889
+ }
890
+ this.minStackPos = s[0].pos;
891
+ for (let r = 1; r < s.length; r++)
892
+ s[r].pos < this.minStackPos && (this.minStackPos = s[r].pos);
893
+ return null;
894
+ }
895
+ stopAt(t) {
896
+ if (this.stoppedAt != null && this.stoppedAt < t)
897
+ throw new RangeError("Can't move stoppedAt forward");
898
+ this.stoppedAt = t;
899
+ }
900
+ // Returns an updated version of the given stack, or null if the
901
+ // stack can't advance normally. When `split` and `stacks` are
902
+ // given, stacks split off by ambiguous operations will be pushed to
903
+ // `split`, or added to `stacks` if they move `pos` forward.
904
+ advanceStack(t, e, s) {
905
+ let i = t.pos, { parser: h } = this, r = g ? this.stackID(t) + " -> " : "";
906
+ if (this.stoppedAt != null && i > this.stoppedAt)
907
+ return t.forceReduce() ? t : null;
908
+ if (this.fragments) {
909
+ let a = t.curContext && t.curContext.tracker.strict, u = a ? t.curContext.hash : 0;
910
+ for (let f = this.fragments.nodeAt(i); f; ) {
911
+ let c = this.parser.nodeSet.types[f.type.id] == f.type ? h.getGoto(t.state, f.type.id) : -1;
912
+ if (c > -1 && f.length && (!a || (f.prop(y.contextHash) || 0) == u))
913
+ return t.useNode(f, c), g && console.log(r + this.stackID(t) + ` (via reuse of ${h.getName(f.type.id)})`), !0;
914
+ if (!(f instanceof S) || f.children.length == 0 || f.positions[0] > 0)
915
+ break;
916
+ let p = f.children[0];
917
+ if (p instanceof S && f.positions[0] == 0)
918
+ f = p;
919
+ else
920
+ break;
921
+ }
922
+ }
923
+ let n = h.stateSlot(
924
+ t.state,
925
+ 4
926
+ /* ParseState.DefaultReduce */
927
+ );
928
+ if (n > 0)
929
+ return t.reduce(n), g && console.log(r + this.stackID(t) + ` (via always-reduce ${h.getName(
930
+ n & 65535
931
+ /* Action.ValueMask */
932
+ )})`), !0;
933
+ if (t.stack.length >= 8400)
934
+ for (; t.stack.length > 6e3 && t.forceReduce(); )
935
+ ;
936
+ let o = this.tokens.getActions(t);
937
+ for (let a = 0; a < o.length; ) {
938
+ let u = o[a++], f = o[a++], c = o[a++], p = a == o.length || !s, d = p ? t : t.split(), b = this.tokens.mainToken;
939
+ if (d.apply(u, f, b ? b.start : d.pos, c), g && console.log(r + this.stackID(d) + ` (via ${u & 65536 ? `reduce of ${h.getName(
940
+ u & 65535
941
+ /* Action.ValueMask */
942
+ )}` : "shift"} for ${h.getName(f)} @ ${i}${d == t ? "" : ", split"})`), p)
943
+ return !0;
944
+ d.pos > i ? e.push(d) : s.push(d);
945
+ }
946
+ return !1;
947
+ }
948
+ // Advance a given stack forward as far as it will go. Returns the
949
+ // (possibly updated) stack if it got stuck, or null if it moved
950
+ // forward and was given to `pushStackDedup`.
951
+ advanceFully(t, e) {
952
+ let s = t.pos;
953
+ for (; ; ) {
954
+ if (!this.advanceStack(t, null, null))
955
+ return !1;
956
+ if (t.pos > s)
957
+ return D(t, e), !0;
958
+ }
959
+ }
960
+ runRecovery(t, e, s) {
961
+ let i = null, h = !1;
962
+ for (let r = 0; r < t.length; r++) {
963
+ let n = t[r], o = e[r << 1], a = e[(r << 1) + 1], u = g ? this.stackID(n) + " -> " : "";
964
+ if (n.deadEnd && (h || (h = !0, n.restart(), g && console.log(u + this.stackID(n) + " (restarted)"), this.advanceFully(n, s))))
965
+ continue;
966
+ let f = n.split(), c = u;
967
+ for (let p = 0; f.forceReduce() && p < 10 && (g && console.log(c + this.stackID(f) + " (via force-reduce)"), !this.advanceFully(f, s)); p++)
968
+ g && (c = this.stackID(f) + " -> ");
969
+ for (let p of n.recoverByInsert(o))
970
+ g && console.log(u + this.stackID(p) + " (via recover-insert)"), this.advanceFully(p, s);
971
+ this.stream.end > n.pos ? (a == n.pos && (a++, o = 0), n.recoverByDelete(o, a), g && console.log(u + this.stackID(n) + ` (via recover-delete ${this.parser.getName(o)})`), D(n, s)) : (!i || i.score < n.score) && (i = n);
972
+ }
973
+ return i;
974
+ }
975
+ // Convert the stack's buffer to a syntax tree.
976
+ stackToTree(t) {
977
+ return t.close(), S.build({
978
+ buffer: A.create(t),
979
+ nodeSet: this.parser.nodeSet,
980
+ topID: this.topTerm,
981
+ maxBufferLength: this.parser.bufferLength,
982
+ reused: this.reused,
983
+ start: this.ranges[0].from,
984
+ length: t.pos - this.ranges[0].from,
985
+ minRepeatType: this.parser.minRepeatTerm
986
+ });
987
+ }
988
+ stackID(t) {
989
+ let e = (C || (C = /* @__PURE__ */ new WeakMap())).get(t);
990
+ return e || C.set(t, e = String.fromCodePoint(this.nextStackID++)), e + t;
991
+ }
992
+ }
993
+ function D(l, t) {
994
+ for (let e = 0; e < t.length; e++) {
995
+ let s = t[e];
996
+ if (s.pos == l.pos && s.sameState(l)) {
997
+ t[e].score < l.score && (t[e] = l);
998
+ return;
999
+ }
1000
+ }
1001
+ t.push(l);
1002
+ }
1003
+ class Q {
1004
+ constructor(t, e, s) {
1005
+ this.source = t, this.flags = e, this.disabled = s;
1006
+ }
1007
+ allows(t) {
1008
+ return !this.disabled || this.disabled[t] == 0;
1009
+ }
1010
+ }
1011
+ const T = (l) => l;
1012
+ class Z {
1013
+ /**
1014
+ Define a context tracker.
1015
+ */
1016
+ constructor(t) {
1017
+ this.start = t.start, this.shift = t.shift || T, this.reduce = t.reduce || T, this.reuse = t.reuse || T, this.hash = t.hash || (() => 0), this.strict = t.strict !== !1;
1018
+ }
1019
+ }
1020
+ class w extends L {
1021
+ /**
1022
+ @internal
1023
+ */
1024
+ constructor(t) {
1025
+ if (super(), this.wrappers = [], t.version != 14)
1026
+ throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);
1027
+ let e = t.nodeNames.split(" ");
1028
+ this.minRepeatTerm = e.length;
1029
+ for (let n = 0; n < t.repeatNodeCount; n++)
1030
+ e.push("");
1031
+ let s = Object.keys(t.topRules).map((n) => t.topRules[n][1]), i = [];
1032
+ for (let n = 0; n < e.length; n++)
1033
+ i.push([]);
1034
+ function h(n, o, a) {
1035
+ i[n].push([o, o.deserialize(String(a))]);
1036
+ }
1037
+ if (t.nodeProps)
1038
+ for (let n of t.nodeProps) {
1039
+ let o = n[0];
1040
+ typeof o == "string" && (o = y[o]);
1041
+ for (let a = 1; a < n.length; ) {
1042
+ let u = n[a++];
1043
+ if (u >= 0)
1044
+ h(u, o, n[a++]);
1045
+ else {
1046
+ let f = n[a + -u];
1047
+ for (let c = -u; c > 0; c--)
1048
+ h(n[a++], o, f);
1049
+ a++;
1050
+ }
1051
+ }
1052
+ }
1053
+ this.nodeSet = new M(e.map((n, o) => $.define({
1054
+ name: o >= this.minRepeatTerm ? void 0 : n,
1055
+ id: o,
1056
+ props: i[o],
1057
+ top: s.indexOf(o) > -1,
1058
+ error: o == 0,
1059
+ skipped: t.skippedNodes && t.skippedNodes.indexOf(o) > -1
1060
+ }))), t.propSources && (this.nodeSet = this.nodeSet.extend(...t.propSources)), this.strict = !1, this.bufferLength = E;
1061
+ let r = x(t.tokenData);
1062
+ this.context = t.context, this.specializerSpecs = t.specialized || [], this.specialized = new Uint16Array(this.specializerSpecs.length);
1063
+ for (let n = 0; n < this.specializerSpecs.length; n++)
1064
+ this.specialized[n] = this.specializerSpecs[n].term;
1065
+ this.specializers = this.specializerSpecs.map(B), this.states = x(t.states, Uint32Array), this.data = x(t.stateData), this.goto = x(t.goto), this.maxTerm = t.maxTerm, this.tokenizers = t.tokenizers.map((n) => typeof n == "number" ? new m(r, n) : n), this.topRules = t.topRules, this.dialects = t.dialects || {}, this.dynamicPrecedences = t.dynamicPrecedences || null, this.tokenPrecTable = t.tokenPrec, this.termNames = t.termNames || null, this.maxNode = this.nodeSet.types.length - 1, this.dialect = this.parseDialect(), this.top = this.topRules[Object.keys(this.topRules)[0]];
1066
+ }
1067
+ createParse(t, e, s) {
1068
+ let i = new K(this, t, e, s);
1069
+ for (let h of this.wrappers)
1070
+ i = h(i, t, e, s);
1071
+ return i;
1072
+ }
1073
+ /**
1074
+ Get a goto table entry @internal
1075
+ */
1076
+ getGoto(t, e, s = !1) {
1077
+ let i = this.goto;
1078
+ if (e >= i[0])
1079
+ return -1;
1080
+ for (let h = i[e + 1]; ; ) {
1081
+ let r = i[h++], n = r & 1, o = i[h++];
1082
+ if (n && s)
1083
+ return o;
1084
+ for (let a = h + (r >> 1); h < a; h++)
1085
+ if (i[h] == t)
1086
+ return o;
1087
+ if (n)
1088
+ return -1;
1089
+ }
1090
+ }
1091
+ /**
1092
+ Check if this state has an action for a given terminal @internal
1093
+ */
1094
+ hasAction(t, e) {
1095
+ let s = this.data;
1096
+ for (let i = 0; i < 2; i++)
1097
+ for (let h = this.stateSlot(
1098
+ t,
1099
+ i ? 2 : 1
1100
+ /* ParseState.Actions */
1101
+ ), r; ; h += 3) {
1102
+ if ((r = s[h]) == 65535)
1103
+ if (s[h + 1] == 1)
1104
+ r = s[h = k(s, h + 2)];
1105
+ else {
1106
+ if (s[h + 1] == 2)
1107
+ return k(s, h + 2);
1108
+ break;
1109
+ }
1110
+ if (r == e || r == 0)
1111
+ return k(s, h + 1);
1112
+ }
1113
+ return 0;
1114
+ }
1115
+ /**
1116
+ @internal
1117
+ */
1118
+ stateSlot(t, e) {
1119
+ return this.states[t * 6 + e];
1120
+ }
1121
+ /**
1122
+ @internal
1123
+ */
1124
+ stateFlag(t, e) {
1125
+ return (this.stateSlot(
1126
+ t,
1127
+ 0
1128
+ /* ParseState.Flags */
1129
+ ) & e) > 0;
1130
+ }
1131
+ /**
1132
+ @internal
1133
+ */
1134
+ validAction(t, e) {
1135
+ return !!this.allActions(t, (s) => s == e ? !0 : null);
1136
+ }
1137
+ /**
1138
+ @internal
1139
+ */
1140
+ allActions(t, e) {
1141
+ let s = this.stateSlot(
1142
+ t,
1143
+ 4
1144
+ /* ParseState.DefaultReduce */
1145
+ ), i = s ? e(s) : void 0;
1146
+ for (let h = this.stateSlot(
1147
+ t,
1148
+ 1
1149
+ /* ParseState.Actions */
1150
+ ); i == null; h += 3) {
1151
+ if (this.data[h] == 65535)
1152
+ if (this.data[h + 1] == 1)
1153
+ h = k(this.data, h + 2);
1154
+ else
1155
+ break;
1156
+ i = e(k(this.data, h + 1));
1157
+ }
1158
+ return i;
1159
+ }
1160
+ /**
1161
+ Get the states that can follow this one through shift actions or
1162
+ goto jumps. @internal
1163
+ */
1164
+ nextStates(t) {
1165
+ let e = [];
1166
+ for (let s = this.stateSlot(
1167
+ t,
1168
+ 1
1169
+ /* ParseState.Actions */
1170
+ ); ; s += 3) {
1171
+ if (this.data[s] == 65535)
1172
+ if (this.data[s + 1] == 1)
1173
+ s = k(this.data, s + 2);
1174
+ else
1175
+ break;
1176
+ if (!(this.data[s + 2] & 1)) {
1177
+ let i = this.data[s + 1];
1178
+ e.some((h, r) => r & 1 && h == i) || e.push(this.data[s], i);
1179
+ }
1180
+ }
1181
+ return e;
1182
+ }
1183
+ /**
1184
+ Configure the parser. Returns a new parser instance that has the
1185
+ given settings modified. Settings not provided in `config` are
1186
+ kept from the original parser.
1187
+ */
1188
+ configure(t) {
1189
+ let e = Object.assign(Object.create(w.prototype), this);
1190
+ if (t.props && (e.nodeSet = this.nodeSet.extend(...t.props)), t.top) {
1191
+ let s = this.topRules[t.top];
1192
+ if (!s)
1193
+ throw new RangeError(`Invalid top rule name ${t.top}`);
1194
+ e.top = s;
1195
+ }
1196
+ return t.tokenizers && (e.tokenizers = this.tokenizers.map((s) => {
1197
+ let i = t.tokenizers.find((h) => h.from == s);
1198
+ return i ? i.to : s;
1199
+ })), t.specializers && (e.specializers = this.specializers.slice(), e.specializerSpecs = this.specializerSpecs.map((s, i) => {
1200
+ let h = t.specializers.find((n) => n.from == s.external);
1201
+ if (!h)
1202
+ return s;
1203
+ let r = Object.assign(Object.assign({}, s), { external: h.to });
1204
+ return e.specializers[i] = B(r), r;
1205
+ })), t.contextTracker && (e.context = t.contextTracker), t.dialect && (e.dialect = this.parseDialect(t.dialect)), t.strict != null && (e.strict = t.strict), t.wrap && (e.wrappers = e.wrappers.concat(t.wrap)), t.bufferLength != null && (e.bufferLength = t.bufferLength), e;
1206
+ }
1207
+ /**
1208
+ Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
1209
+ are registered for this parser.
1210
+ */
1211
+ hasWrappers() {
1212
+ return this.wrappers.length > 0;
1213
+ }
1214
+ /**
1215
+ Returns the name associated with a given term. This will only
1216
+ work for all terms when the parser was generated with the
1217
+ `--names` option. By default, only the names of tagged terms are
1218
+ stored.
1219
+ */
1220
+ getName(t) {
1221
+ return this.termNames ? this.termNames[t] : String(t <= this.maxNode && this.nodeSet.types[t].name || t);
1222
+ }
1223
+ /**
1224
+ The eof term id is always allocated directly after the node
1225
+ types. @internal
1226
+ */
1227
+ get eofTerm() {
1228
+ return this.maxNode + 1;
1229
+ }
1230
+ /**
1231
+ The type of top node produced by the parser.
1232
+ */
1233
+ get topNode() {
1234
+ return this.nodeSet.types[this.top[1]];
1235
+ }
1236
+ /**
1237
+ @internal
1238
+ */
1239
+ dynamicPrecedence(t) {
1240
+ let e = this.dynamicPrecedences;
1241
+ return e == null ? 0 : e[t] || 0;
1242
+ }
1243
+ /**
1244
+ @internal
1245
+ */
1246
+ parseDialect(t) {
1247
+ let e = Object.keys(this.dialects), s = e.map(() => !1);
1248
+ if (t)
1249
+ for (let h of t.split(" ")) {
1250
+ let r = e.indexOf(h);
1251
+ r >= 0 && (s[r] = !0);
1252
+ }
1253
+ let i = null;
1254
+ for (let h = 0; h < e.length; h++)
1255
+ if (!s[h])
1256
+ for (let r = this.dialects[e[h]], n; (n = this.data[r++]) != 65535; )
1257
+ (i || (i = new Uint8Array(this.maxTerm + 1)))[n] = 1;
1258
+ return new Q(t, s, i);
1259
+ }
1260
+ /**
1261
+ Used by the output of the parser generator. Not available to
1262
+ user code. @hide
1263
+ */
1264
+ static deserialize(t) {
1265
+ return new w(t);
1266
+ }
1267
+ }
1268
+ function k(l, t) {
1269
+ return l[t] | l[t + 1] << 16;
1270
+ }
1271
+ function V(l) {
1272
+ let t = null;
1273
+ for (let e of l) {
1274
+ let s = e.p.stoppedAt;
1275
+ (e.pos == e.p.stream.end || s != null && e.pos > s) && e.p.parser.stateFlag(
1276
+ e.state,
1277
+ 2
1278
+ /* StateFlag.Accepting */
1279
+ ) && (!t || t.score < e.score) && (t = e);
1280
+ }
1281
+ return t;
1282
+ }
1283
+ function B(l) {
1284
+ if (l.external) {
1285
+ let t = l.extend ? 1 : 0;
1286
+ return (e, s) => l.external(e, s) << 1 | t;
1287
+ }
1288
+ return l.get;
1289
+ }
1290
+ export {
1291
+ Z as C,
1292
+ Y as E,
1293
+ w as L,
1294
+ H as a
1295
+ };