@voicenter-team/voicenter-ui-plus 1.1.13 → 1.1.14

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