@aiderdesk/aiderdesk 0.61.0-dev → 0.61.0

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