@camunda/copilot-chat 0.0.3 → 0.1.1

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