occam-dom 5.0.0 → 5.0.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.
- package/example.js +1495 -1305
- package/lib/example/constants.js +22 -0
- package/lib/example/utilities/query.js +23 -0
- package/lib/example/view/div/sizeable.js +2 -2
- package/lib/example/view/textarea/expressions.js +143 -0
- package/lib/example/view/textarea/outerNodes.js +147 -0
- package/lib/example/view/{input/expressionString.js → textarea/parseTree/inner.js} +43 -28
- package/lib/{expression/parser.js → example/view/textarea/parseTree/outer.js} +20 -28
- package/lib/example/view/textarea/parseTree.js +1 -19
- package/lib/example/view.js +26 -20
- package/lib/index.js +7 -19
- package/lib/node.js +302 -0
- package/lib/parseTree/childNodes.js +164 -0
- package/lib/parseTree/horizontalBranch.js +120 -0
- package/lib/parseTree/node.js +145 -0
- package/lib/parseTree/string.js +109 -0
- package/lib/parseTree/verticalBranch.js +184 -0
- package/lib/parseTree.js +191 -0
- package/lib/utilities/node.js +56 -309
- package/package.json +5 -4
- package/src/example/constants.js +4 -0
- package/src/example/utilities/query.js +21 -0
- package/src/example/view/div/sizeable.js +1 -1
- package/src/example/view/textarea/expressions.js +39 -0
- package/src/example/view/textarea/outerNodes.js +48 -0
- package/src/example/view/textarea/parseTree/inner.js +24 -0
- package/src/example/view/textarea/parseTree/outer.js +17 -0
- package/src/example/view/textarea/parseTree.js +0 -18
- package/src/example/view.js +44 -32
- package/src/index.js +2 -5
- package/src/node.js +221 -0
- package/src/parseTree/childNodes.js +108 -0
- package/src/parseTree/horizontalBranch.js +32 -0
- package/src/parseTree/node.js +77 -0
- package/src/parseTree/string.js +18 -0
- package/src/parseTree/verticalBranch.js +77 -0
- package/src/parseTree.js +141 -0
- package/src/utilities/node.js +66 -416
- package/lib/example/view/textarea/nodes.js +0 -155
- package/lib/expression/bnf.js +0 -14
- package/lib/expression/entries.js +0 -27
- package/lib/expression/lexer.js +0 -145
- package/lib/expression.js +0 -113
- package/lib/path.js +0 -69
- package/lib/query.js +0 -216
- package/lib/ruleNames.js +0 -54
- package/lib/spread.js +0 -113
- package/lib/subExpression.js +0 -101
- package/lib/utilities/array.js +0 -67
- package/lib/utilities/query.js +0 -39
- package/src/example/view/input/expressionString.js +0 -33
- package/src/example/view/textarea/nodes.js +0 -55
- package/src/expression/bnf.js +0 -63
- package/src/expression/entries.js +0 -18
- package/src/expression/lexer.js +0 -35
- package/src/expression/parser.js +0 -15
- package/src/expression.js +0 -82
- package/src/path.js +0 -32
- package/src/query.js +0 -207
- package/src/ruleNames.js +0 -12
- package/src/spread.js +0 -104
- package/src/subExpression.js +0 -52
- package/src/utilities/array.js +0 -30
- package/src/utilities/query.js +0 -22
package/src/utilities/node.js
CHANGED
|
@@ -1,454 +1,104 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
INDEX_RULE_NAME,
|
|
5
|
-
UNIQUE_RULE_NAME,
|
|
6
|
-
SPREAD_RULE_NAME,
|
|
7
|
-
END_INDEX_RULE_NAME,
|
|
8
|
-
RULE_NAME_RULE_NAME,
|
|
9
|
-
TOKEN_TYPE_RULE_NAME,
|
|
10
|
-
START_INDEX_RULE_NAME,
|
|
11
|
-
SUB_EXPRESSION_RULE_NAME,
|
|
12
|
-
INFINITE_DESCENT_RULE_NAME } from "../ruleNames";
|
|
3
|
+
import Node from "../node";
|
|
13
4
|
|
|
14
|
-
export function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const terminalNode = firstChildNode, ///
|
|
18
|
-
content = terminalNode.getContent(),
|
|
19
|
-
index = Number(content);
|
|
5
|
+
export function topmostNodeFromOuterNodes(Class, outerNodes) {
|
|
6
|
+
if (outerNodes === undefined) {
|
|
7
|
+
outerNodes = Class; ///
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
return index;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function ruleNamesFromPathNode(pathNode) {
|
|
28
|
-
const selectorNodes = selectorNodesFromPathNode(pathNode),
|
|
29
|
-
ruleNameNodes = selectorNodes.reduce((ruleNameNodes, selectorNode) => {
|
|
30
|
-
const nonTerminalNode = selectorNode, ///
|
|
31
|
-
ruleNameNode = fromFirstChildNode(nonTerminalNode, (firstChildNode) => {
|
|
32
|
-
let ruleNameNode = null;
|
|
33
|
-
|
|
34
|
-
const nonTerminalNode = firstChildNode, ///
|
|
35
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
36
|
-
ruleNameRuleNameRuleName = (ruleName === RULE_NAME_RULE_NAME);
|
|
37
|
-
|
|
38
|
-
if (ruleNameRuleNameRuleName) {
|
|
39
|
-
ruleNameNode = nonTerminalNode; ///
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return ruleNameNode;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
if (ruleNameNode !== null) {
|
|
46
|
-
ruleNameNodes.push(ruleNameNode);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return ruleNameNodes;
|
|
50
|
-
}, []),
|
|
51
|
-
ruleNames = ruleNameNodes.map((ruleNameNode) => {
|
|
52
|
-
const nonTerminalNode = ruleNameNode, ///
|
|
53
|
-
ruleName = fromFirstChildNode(nonTerminalNode, (firstChildNode) => {
|
|
54
|
-
const terminalNode = firstChildNode, ///
|
|
55
|
-
content = terminalNode.getContent(),
|
|
56
|
-
ruleName = content; ///
|
|
57
|
-
|
|
58
|
-
return ruleName;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return ruleName;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return ruleNames;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function tokenTypesFromPathNode(pathNode) {
|
|
68
|
-
const selectorNodes = selectorNodesFromPathNode(pathNode),
|
|
69
|
-
tokenTypeNodes = selectorNodes.reduce((tokenTypeNodes, selectorNode) => {
|
|
70
|
-
const nonTerminalNode = selectorNode, ///
|
|
71
|
-
tokenTypeNode = fromFirstChildNode(nonTerminalNode, (firstChildNode) => {
|
|
72
|
-
let tokenTypeNode = null;
|
|
73
|
-
|
|
74
|
-
const nonTerminalNode = firstChildNode, ///
|
|
75
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
76
|
-
ruleNameTokenTypeRuleName = (ruleName === TOKEN_TYPE_RULE_NAME);
|
|
77
|
-
|
|
78
|
-
if (ruleNameTokenTypeRuleName) {
|
|
79
|
-
tokenTypeNode = nonTerminalNode; ///
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return tokenTypeNode;
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
if (tokenTypeNode !== null) {
|
|
86
|
-
tokenTypeNodes.push(tokenTypeNode);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return tokenTypeNodes;
|
|
90
|
-
}, []),
|
|
91
|
-
tokenTypes = tokenTypeNodes.map((tokenTypeNode) => {
|
|
92
|
-
const nonTerminalNode = tokenTypeNode, ///
|
|
93
|
-
tokenType = fromThirdChildNode(nonTerminalNode, (thirdChildNode) => {
|
|
94
|
-
const terminalNode = thirdChildNode, ///
|
|
95
|
-
content = terminalNode.getContent(),
|
|
96
|
-
tokenType = content; ///
|
|
97
|
-
|
|
98
|
-
return tokenType;
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return tokenType;
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
return tokenTypes;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function selectorNodesFromPathNode(pathNode) {
|
|
108
|
-
let nonTerminalNode;
|
|
109
|
-
|
|
110
|
-
nonTerminalNode = pathNode; ///
|
|
111
|
-
|
|
112
|
-
const selectorsNode = fromLastChildNode(nonTerminalNode, (lastChildNode) => {
|
|
113
|
-
const selectorsNode = lastChildNode; ///
|
|
114
|
-
|
|
115
|
-
return selectorsNode;
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
nonTerminalNode = selectorsNode; ///
|
|
119
|
-
|
|
120
|
-
const selectorNodes = nonTerminalNode.filterChildNode((childNode) => {
|
|
121
|
-
const childNodeNonTerminalNode = childNode.isNonTerminalNode();
|
|
122
|
-
|
|
123
|
-
if (childNodeNonTerminalNode) {
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return selectorNodes;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function infiniteDescentFromPathNode(pathNode) {
|
|
132
|
-
const nonTerminalNode = pathNode, ///
|
|
133
|
-
infiniteDescent = fromSecondChildNode(nonTerminalNode, (secondChildNode) => {
|
|
134
|
-
const nonTerminalNode = secondChildNode, ///
|
|
135
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
136
|
-
ruleNameInfiniteDescentRuleName = (ruleName === INFINITE_DESCENT_RULE_NAME),
|
|
137
|
-
infiniteDescent = ruleNameInfiniteDescentRuleName; ///
|
|
138
|
-
|
|
139
|
-
return infiniteDescent;
|
|
140
|
-
}) || false;
|
|
141
|
-
|
|
142
|
-
return infiniteDescent;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function uniqueFromSpreadNode(spreadNode) {
|
|
146
|
-
const nonTerminalNode = spreadNode,
|
|
147
|
-
unique = fromFirstChildNode(nonTerminalNode, (firstChildNode) => {
|
|
148
|
-
let unique = false;
|
|
149
|
-
|
|
150
|
-
const firstChildNodeNonTerminalNode = firstChildNode.isNonTerminalNode();
|
|
151
|
-
|
|
152
|
-
if (firstChildNodeNonTerminalNode) {
|
|
153
|
-
const nonTerminalNode = firstChildNode, ///
|
|
154
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
155
|
-
ruleNameUniqueRuleName = (ruleName === UNIQUE_RULE_NAME);
|
|
156
|
-
|
|
157
|
-
if (ruleNameUniqueRuleName) {
|
|
158
|
-
unique = true;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return unique;
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
return unique;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function indexFromSpreadNode(spreadNode) {
|
|
169
|
-
let index = null;
|
|
170
|
-
|
|
171
|
-
const nonTerminalNode = spreadNode, ///
|
|
172
|
-
indexNode = nonTerminalNode.findChildNode((childNode) => {
|
|
173
|
-
const childNodeNonTerminalNode = childNode.isNonTerminalNode();
|
|
174
|
-
|
|
175
|
-
if (childNodeNonTerminalNode) {
|
|
176
|
-
const nonTerminalNode = childNode, ///
|
|
177
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
178
|
-
ruleNameIndexRuleName = (ruleName === INDEX_RULE_NAME);
|
|
179
|
-
|
|
180
|
-
if (ruleNameIndexRuleName) {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}) || null;
|
|
185
|
-
|
|
186
|
-
if (indexNode !== null) {
|
|
187
|
-
index = indexFromIndexNode(indexNode);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return index;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function endIndexFromSpreadNode(spreadNode) {
|
|
194
|
-
let endIndex = Infinity;
|
|
195
|
-
|
|
196
|
-
const nonTerminalNode = spreadNode, ///
|
|
197
|
-
endIndexNode = nonTerminalNode.findChildNode((childNode) => {
|
|
198
|
-
const childNodeNonTerminalNode = childNode.isNonTerminalNode();
|
|
199
|
-
|
|
200
|
-
if (childNodeNonTerminalNode) {
|
|
201
|
-
const nonTerminalNode = childNode, ///
|
|
202
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
203
|
-
ruleNameEndIndexRuleName = (ruleName === END_INDEX_RULE_NAME);
|
|
204
|
-
|
|
205
|
-
if (ruleNameEndIndexRuleName) {
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}) || null;
|
|
210
|
-
|
|
211
|
-
if (endIndexNode !== null) {
|
|
212
|
-
endIndex = indexFromIndexNode(endIndexNode);
|
|
9
|
+
Class = Node; ///
|
|
213
10
|
}
|
|
214
11
|
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export function startIndexFromSpreadNode(spreadNode) {
|
|
219
|
-
let startIndex = 0;
|
|
220
|
-
|
|
221
|
-
const nonTerminalNode = spreadNode, ///
|
|
222
|
-
startIndexNode = nonTerminalNode.findChildNode((childNode) => {
|
|
223
|
-
const childNodeNonTerminalNode = childNode.isNonTerminalNode();
|
|
12
|
+
const nodes = outerNodes; ///
|
|
224
13
|
|
|
225
|
-
|
|
226
|
-
const nonTerminalNode = childNode, ///
|
|
227
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
228
|
-
ruleNameStartIndexRuleName = (ruleName === START_INDEX_RULE_NAME);
|
|
14
|
+
orderNodes(nodes);
|
|
229
15
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}) || null;
|
|
16
|
+
const topmostNode = Node.fromNothing(),
|
|
17
|
+
outerNodeToNodeMap = new WeakMap();
|
|
235
18
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return startIndex;
|
|
241
|
-
}
|
|
19
|
+
outerNodes.forEach((outerNode) => {
|
|
20
|
+
const ancestorNodes = outerNode.getAncestorNodes();
|
|
242
21
|
|
|
243
|
-
|
|
244
|
-
const nonTerminalNode = expressionNode, ///
|
|
245
|
-
pathNode = fromFirstChildNode(nonTerminalNode, (firstChildNode) => {
|
|
246
|
-
const pathNode = firstChildNode; ///
|
|
22
|
+
let parentNode = topmostNode; ///
|
|
247
23
|
|
|
248
|
-
|
|
249
|
-
|
|
24
|
+
ancestorNodes.some((ancestorNode) => {
|
|
25
|
+
const outerNode = ancestorNode, ///
|
|
26
|
+
node = outerNodeToNodeMap.get(outerNode) || null;
|
|
250
27
|
|
|
251
|
-
|
|
252
|
-
|
|
28
|
+
if (node !== null) {
|
|
29
|
+
parentNode = node; ///
|
|
253
30
|
|
|
254
|
-
|
|
255
|
-
const nonTerminalNode = expressionNode, ///
|
|
256
|
-
spreadNode = fromSecondChildNode(nonTerminalNode, (secondChildNode) => {
|
|
257
|
-
let spreadNode = null;
|
|
258
|
-
|
|
259
|
-
const nonTerminalNode = secondChildNode, ///
|
|
260
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
261
|
-
ruleNameSpreadRuleName = (ruleName === SPREAD_RULE_NAME);
|
|
262
|
-
|
|
263
|
-
if (ruleNameSpreadRuleName) {
|
|
264
|
-
spreadNode = secondChildNode; ///
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return spreadNode;
|
|
268
|
-
}) || null;
|
|
269
|
-
|
|
270
|
-
return spreadNode;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
export function errorNodesFromExpressionNode(expressionNode) {
|
|
274
|
-
const nonTerminalNode = expressionNode, ///
|
|
275
|
-
errorNodes = nonTerminalNode.reduceChildNode((errorNodes, childNode) => {
|
|
276
|
-
const childNodeNonTerminalNode = childNode.isNonTerminalNode();
|
|
277
|
-
|
|
278
|
-
if (childNodeNonTerminalNode) {
|
|
279
|
-
const nonTerminalNode = childNode, ///
|
|
280
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
281
|
-
ruleNameErrorRuleName = (ruleName === ERROR_RULE_NAME);
|
|
282
|
-
|
|
283
|
-
if (ruleNameErrorRuleName) {
|
|
284
|
-
const errorNode = nonTerminalNode; ///
|
|
285
|
-
|
|
286
|
-
errorNodes.push(errorNode);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return errorNodes;
|
|
291
|
-
}, []);
|
|
292
|
-
|
|
293
|
-
return errorNodes;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export function subExpressionNodeFromExpressionNode(expressionNode) {
|
|
297
|
-
let subExpressionNode = null;
|
|
298
|
-
|
|
299
|
-
const nonTerminalNode = expressionNode, ///
|
|
300
|
-
multiplicity = nonTerminalNode.getMultiplicity();
|
|
301
|
-
|
|
302
|
-
if (multiplicity > 1) {
|
|
303
|
-
subExpressionNode = fromLastChildNode(nonTerminalNode, (lastChildNode) => {
|
|
304
|
-
let subExpressionNode = null;
|
|
305
|
-
|
|
306
|
-
const nonTerminalNode = lastChildNode, ///
|
|
307
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
308
|
-
ruleNameSubExpressionRuleName = (ruleName === SUB_EXPRESSION_RULE_NAME);
|
|
309
|
-
|
|
310
|
-
if (ruleNameSubExpressionRuleName) {
|
|
311
|
-
subExpressionNode = lastChildNode; ///
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return subExpressionNode;
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return subExpressionNode;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export function pathNodeFromSubExpressionNode(subExpressionNode) {
|
|
322
|
-
const nonTerminalNode = subExpressionNode, ///
|
|
323
|
-
pathNode = fromFirstChildNode(nonTerminalNode, (firstChildNode) => {
|
|
324
|
-
const pathNode = firstChildNode; ///
|
|
325
|
-
|
|
326
|
-
return pathNode;
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
return pathNode;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
export function spreadNodeFromSubExpressionNode(subExpressionNode) {
|
|
333
|
-
let spreadNode = null;
|
|
334
|
-
|
|
335
|
-
const nonTerminalNode = subExpressionNode, ///
|
|
336
|
-
multiplicity = nonTerminalNode.getMultiplicity();
|
|
337
|
-
|
|
338
|
-
if (multiplicity > 1) {
|
|
339
|
-
spreadNode = fromSecondChildNode(nonTerminalNode, (secondChildNode) => {
|
|
340
|
-
let spreadNode = null;
|
|
341
|
-
|
|
342
|
-
const nonTerminalNode = secondChildNode, ///
|
|
343
|
-
ruleName = nonTerminalNode.getRuleName(),
|
|
344
|
-
ruleNameSpreadRuleName = (ruleName === SPREAD_RULE_NAME);
|
|
345
|
-
|
|
346
|
-
if (ruleNameSpreadRuleName) {
|
|
347
|
-
spreadNode = secondChildNode; ///
|
|
31
|
+
return true;
|
|
348
32
|
}
|
|
349
|
-
|
|
350
|
-
return spreadNode;
|
|
351
|
-
}) || null;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
return spreadNode;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
export function subExpressionNodeFromSubExpressionNode(subExpressionNode) {
|
|
358
|
-
const nonTerminalNode = subExpressionNode; ///
|
|
359
|
-
|
|
360
|
-
subExpressionNode = null;
|
|
361
|
-
|
|
362
|
-
const multiplicity = nonTerminalNode.getMultiplicity();
|
|
363
|
-
|
|
364
|
-
if (multiplicity > 1) {
|
|
365
|
-
subExpressionNode = fromLastChildNode(nonTerminalNode, (lastChildNode) => {
|
|
366
|
-
let subExpressionNode = null;
|
|
367
|
-
|
|
368
|
-
const nonTerminalNoe = lastChildNode, ///
|
|
369
|
-
ruleName = nonTerminalNoe.getRuleName(),
|
|
370
|
-
ruleNameSubExpressionRuleName = (ruleName === SUB_EXPRESSION_RULE_NAME);
|
|
371
|
-
|
|
372
|
-
if (ruleNameSubExpressionRuleName) {
|
|
373
|
-
subExpressionNode = lastChildNode; ///
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return subExpressionNode;
|
|
377
33
|
});
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return subExpressionNode;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function fromFirstChildNode(nonTerminalNode, callback) {
|
|
384
|
-
let result;
|
|
385
34
|
|
|
386
|
-
|
|
35
|
+
const node = Class.fromOuterNode(outerNode),
|
|
36
|
+
childNode = node; ///
|
|
387
37
|
|
|
388
|
-
|
|
389
|
-
if (index === firstIndex) {
|
|
390
|
-
const firstChildNode = childNode; ///
|
|
38
|
+
parentNode.addChildNode(childNode);
|
|
391
39
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
return true;
|
|
395
|
-
}
|
|
40
|
+
outerNodeToNodeMap.set(outerNode, node);
|
|
396
41
|
});
|
|
397
42
|
|
|
398
|
-
return
|
|
43
|
+
return topmostNode;
|
|
399
44
|
}
|
|
400
45
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const secondIndex = 1;
|
|
405
|
-
|
|
406
|
-
nonTerminalNode.forwardsSomeChildNode((childNode, index) => {
|
|
407
|
-
if (index === secondIndex) {
|
|
408
|
-
const firstChildNode = childNode; ///
|
|
46
|
+
export default {
|
|
47
|
+
topmostNodeFromOuterNodes
|
|
48
|
+
};
|
|
409
49
|
|
|
410
|
-
|
|
50
|
+
function orderNodes(nodes) {
|
|
51
|
+
nodes.sort((nodeA, nodeB) => {
|
|
52
|
+
const nodeALessThanNodeB = isLessThan(nodeA, nodeB),
|
|
53
|
+
result = nodeALessThanNodeB ?
|
|
54
|
+
-1 :
|
|
55
|
+
+1;
|
|
411
56
|
|
|
412
|
-
|
|
413
|
-
}
|
|
57
|
+
return result;
|
|
414
58
|
});
|
|
415
|
-
|
|
416
|
-
return result;
|
|
417
59
|
}
|
|
418
60
|
|
|
419
|
-
function
|
|
420
|
-
let
|
|
61
|
+
function isLessThan(nodeA, nodeB) {
|
|
62
|
+
let lessThan = null;
|
|
421
63
|
|
|
422
|
-
const
|
|
64
|
+
const ancestorNodesA = ancestorNodesFromNode(nodeA),
|
|
65
|
+
ancestorNodesB = ancestorNodesFromNode(nodeB),
|
|
66
|
+
ancestorNodesALength = ancestorNodesA.length,
|
|
67
|
+
ancestorNodesBLength = ancestorNodesB.length,
|
|
68
|
+
minimumAncestorNodesLength = Math.min(ancestorNodesALength, ancestorNodesBLength);
|
|
423
69
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
70
|
+
for (let index = 0; index < minimumAncestorNodesLength; index++) {
|
|
71
|
+
const ancestorNodeA = ancestorNodesA[index],
|
|
72
|
+
ancestorNodeB = ancestorNodesB[index];
|
|
427
73
|
|
|
428
|
-
|
|
74
|
+
if (ancestorNodeA !== ancestorNodeB) {
|
|
75
|
+
const parentIndex = index - 1,
|
|
76
|
+
ancestorNodeAParentNode = ancestorNodesA[parentIndex],
|
|
77
|
+
parentNode = ancestorNodeAParentNode, ///
|
|
78
|
+
childNodeA = ancestorNodeA, ///
|
|
79
|
+
childNodeB = ancestorNodeB, ///
|
|
80
|
+
indexA = parentNode.indexOfChildNode(childNodeA),
|
|
81
|
+
indexB = parentNode.indexOfChildNode(childNodeB);
|
|
429
82
|
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
});
|
|
83
|
+
lessThan = (indexA < indexB);
|
|
433
84
|
|
|
434
|
-
|
|
435
|
-
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
436
88
|
|
|
437
|
-
|
|
438
|
-
|
|
89
|
+
if (lessThan === null) {
|
|
90
|
+
lessThan = (ancestorNodesALength < ancestorNodesBLength);
|
|
91
|
+
}
|
|
439
92
|
|
|
440
|
-
|
|
441
|
-
|
|
93
|
+
return lessThan;
|
|
94
|
+
}
|
|
442
95
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
const thirdChildNode = childNode; ///
|
|
96
|
+
function ancestorNodesFromNode(node) {
|
|
97
|
+
const ancestorNodes = node.getAncestorNodes();
|
|
446
98
|
|
|
447
|
-
|
|
99
|
+
ancestorNodes.unshift(node);
|
|
448
100
|
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
});
|
|
101
|
+
ancestorNodes.reverse();
|
|
452
102
|
|
|
453
|
-
return
|
|
454
|
-
}
|
|
103
|
+
return ancestorNodes;
|
|
104
|
+
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "default", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NodesTextarea;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
var _textarea = /*#__PURE__*/ _interop_require_default(require("../textarea"));
|
|
12
|
-
var _constants = require("../../../constants");
|
|
13
|
-
var _token = require("../../utilities/token");
|
|
14
|
-
function _assert_this_initialized(self) {
|
|
15
|
-
if (self === void 0) {
|
|
16
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
17
|
-
}
|
|
18
|
-
return self;
|
|
19
|
-
}
|
|
20
|
-
function _call_super(_this, derived, args) {
|
|
21
|
-
derived = _get_prototype_of(derived);
|
|
22
|
-
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
23
|
-
}
|
|
24
|
-
function _class_call_check(instance, Constructor) {
|
|
25
|
-
if (!(instance instanceof Constructor)) {
|
|
26
|
-
throw new TypeError("Cannot call a class as a function");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function _defineProperties(target, props) {
|
|
30
|
-
for(var i = 0; i < props.length; i++){
|
|
31
|
-
var descriptor = props[i];
|
|
32
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
33
|
-
descriptor.configurable = true;
|
|
34
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
35
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
39
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
40
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
41
|
-
return Constructor;
|
|
42
|
-
}
|
|
43
|
-
function _define_property(obj, key, value) {
|
|
44
|
-
if (key in obj) {
|
|
45
|
-
Object.defineProperty(obj, key, {
|
|
46
|
-
value: value,
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
writable: true
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
obj[key] = value;
|
|
53
|
-
}
|
|
54
|
-
return obj;
|
|
55
|
-
}
|
|
56
|
-
function _get_prototype_of(o) {
|
|
57
|
-
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
58
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
59
|
-
};
|
|
60
|
-
return _get_prototype_of(o);
|
|
61
|
-
}
|
|
62
|
-
function _inherits(subClass, superClass) {
|
|
63
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
64
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
65
|
-
}
|
|
66
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
67
|
-
constructor: {
|
|
68
|
-
value: subClass,
|
|
69
|
-
writable: true,
|
|
70
|
-
configurable: true
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
if (superClass) _set_prototype_of(subClass, superClass);
|
|
74
|
-
}
|
|
75
|
-
function _interop_require_default(obj) {
|
|
76
|
-
return obj && obj.__esModule ? obj : {
|
|
77
|
-
default: obj
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function _possible_constructor_return(self, call) {
|
|
81
|
-
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
82
|
-
return call;
|
|
83
|
-
}
|
|
84
|
-
return _assert_this_initialized(self);
|
|
85
|
-
}
|
|
86
|
-
function _set_prototype_of(o, p) {
|
|
87
|
-
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
88
|
-
o.__proto__ = p;
|
|
89
|
-
return o;
|
|
90
|
-
};
|
|
91
|
-
return _set_prototype_of(o, p);
|
|
92
|
-
}
|
|
93
|
-
function _type_of(obj) {
|
|
94
|
-
"@swc/helpers - typeof";
|
|
95
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
96
|
-
}
|
|
97
|
-
function _is_native_reflect_construct() {
|
|
98
|
-
try {
|
|
99
|
-
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
100
|
-
} catch (_) {}
|
|
101
|
-
return (_is_native_reflect_construct = function() {
|
|
102
|
-
return !!result;
|
|
103
|
-
})();
|
|
104
|
-
}
|
|
105
|
-
var NodesTextarea = /*#__PURE__*/ function(Textarea) {
|
|
106
|
-
_inherits(NodesTextarea, Textarea);
|
|
107
|
-
function NodesTextarea() {
|
|
108
|
-
_class_call_check(this, NodesTextarea);
|
|
109
|
-
return _call_super(this, NodesTextarea, arguments);
|
|
110
|
-
}
|
|
111
|
-
_create_class(NodesTextarea, [
|
|
112
|
-
{
|
|
113
|
-
key: "setNodes",
|
|
114
|
-
value: function setNodes(nodes, tokens) {
|
|
115
|
-
var value = nodes.reduce(function(value, node) {
|
|
116
|
-
var nodeTerminalNode = node.isTerminalNode();
|
|
117
|
-
if (nodeTerminalNode) {
|
|
118
|
-
var terminalNode = node, significantToken = terminalNode.getSignificantToken(), significantTokenType = significantToken.getType(), tokenIndex = (0, _token.tokenIndexFromTerminalNodeAndTokens)(terminalNode, tokens);
|
|
119
|
-
value = "".concat(value, "[").concat(significantTokenType, "]").concat(tokenIndex, "\n");
|
|
120
|
-
} else {
|
|
121
|
-
var nonTerminalNode = node, ruleName = nonTerminalNode.getRuleName(), tokenIndexes = (0, _token.tokenIndexesFromNonTerminalNodeAndTokens)(nonTerminalNode, tokens);
|
|
122
|
-
value = "".concat(value).concat(ruleName).concat(tokenIndexes, "\n");
|
|
123
|
-
}
|
|
124
|
-
return value;
|
|
125
|
-
}, _constants.EMPTY_STRING);
|
|
126
|
-
this.setValue(value);
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
key: "clearNodes",
|
|
131
|
-
value: function clearNodes() {
|
|
132
|
-
var value = _constants.EMPTY_STRING;
|
|
133
|
-
this.setValue(value);
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
key: "parentContext",
|
|
138
|
-
value: function parentContext() {
|
|
139
|
-
var setNodes = this.setNodes.bind(this), clearNodes = this.clearNodes.bind(this);
|
|
140
|
-
return {
|
|
141
|
-
setNodes: setNodes,
|
|
142
|
-
clearNodes: clearNodes
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
]);
|
|
147
|
-
return NodesTextarea;
|
|
148
|
-
}(_textarea.default);
|
|
149
|
-
_define_property(NodesTextarea, "defaultProperties", {
|
|
150
|
-
className: "nodes",
|
|
151
|
-
spellCheck: "false",
|
|
152
|
-
readOnly: true
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9leGFtcGxlL3ZpZXcvdGV4dGFyZWEvbm9kZXMuanMiXSwic291cmNlc0NvbnRlbnQiOlsiXCJ1c2Ugc3RyaWN0XCI7XG5cbmltcG9ydCBUZXh0YXJlYSBmcm9tIFwiLi4vdGV4dGFyZWFcIjtcblxuaW1wb3J0IHsgRU1QVFlfU1RSSU5HIH0gZnJvbSBcIi4uLy4uLy4uL2NvbnN0YW50c1wiO1xuaW1wb3J0IHsgdG9rZW5JbmRleEZyb21UZXJtaW5hbE5vZGVBbmRUb2tlbnMsIHRva2VuSW5kZXhlc0Zyb21Ob25UZXJtaW5hbE5vZGVBbmRUb2tlbnMgfSBmcm9tIFwiLi4vLi4vdXRpbGl0aWVzL3Rva2VuXCJcblxuZXhwb3J0IGRlZmF1bHQgY2xhc3MgTm9kZXNUZXh0YXJlYSBleHRlbmRzIFRleHRhcmVhIHtcbiAgc2V0Tm9kZXMobm9kZXMsIHRva2VucykgeyAvLy9cbiAgICBjb25zdCB2YWx1ZSA9IG5vZGVzLnJlZHVjZSgodmFsdWUsIG5vZGUpID0+IHtcbiAgICAgIGNvbnN0IG5vZGVUZXJtaW5hbE5vZGUgPSBub2RlLmlzVGVybWluYWxOb2RlKCk7XG5cbiAgICAgIGlmIChub2RlVGVybWluYWxOb2RlKSB7XG4gICAgICAgIGNvbnN0IHRlcm1p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