@maketribe/ms-app 3.1.1 → 3.1.3

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