occam-dom 4.0.15 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/main.js +15 -0
- package/example.js +37842 -0
- package/index.html +47 -0
- package/lib/constants.js +13 -0
- package/lib/example/utilities/token.js +28 -0
- package/lib/example/view/div/sizeable.js +39 -0
- package/lib/example/view/input/expressionString.js +142 -0
- package/lib/example/view/input/maximumDepth.js +143 -0
- package/lib/example/view/input.js +39 -0
- package/lib/example/view/subHeading.js +39 -0
- package/lib/example/view/textarea/content.js +142 -0
- package/lib/example/view/textarea/nodes.js +155 -0
- package/lib/example/view/textarea/parseTree.js +166 -0
- package/lib/example/view/textarea.js +39 -0
- package/lib/example/view.js +239 -0
- package/lib/example.js +19 -0
- package/lib/expression/bnf.js +14 -0
- package/lib/expression/entries.js +27 -0
- package/lib/expression/lexer.js +145 -0
- package/lib/expression/parser.js +134 -0
- package/lib/expression.js +113 -0
- package/lib/index.js +39 -0
- package/lib/path.js +69 -0
- package/lib/query.js +216 -0
- package/lib/ruleNames.js +54 -0
- package/lib/spread.js +113 -0
- package/lib/subExpression.js +101 -0
- package/lib/utilities/array.js +67 -0
- package/lib/utilities/node.js +334 -0
- package/lib/utilities/query.js +39 -0
- package/package.json +3 -3
- package/src/constants.js +3 -0
- package/src/example/utilities/token.js +19 -0
- package/src/example/view/div/sizeable.js +12 -0
- package/src/example/view/input/expressionString.js +33 -0
- package/src/example/view/input/maximumDepth.js +35 -0
- package/src/example/view/input.js +14 -0
- package/src/example/view/subHeading.js +16 -0
- package/src/example/view/textarea/content.js +33 -0
- package/src/example/view/textarea/nodes.js +55 -0
- package/src/example/view/textarea/parseTree.js +46 -0
- package/src/example/view/textarea.js +18 -0
- package/src/example/view.js +125 -0
- package/src/example.js +21 -0
- package/src/expression/bnf.js +63 -0
- package/src/expression/entries.js +18 -0
- package/src/expression/lexer.js +35 -0
- package/src/expression/parser.js +15 -0
- package/src/expression.js +82 -0
- package/src/index.js +7 -0
- package/src/path.js +32 -0
- package/src/query.js +207 -0
- package/src/ruleNames.js +12 -0
- package/src/spread.js +104 -0
- package/src/subExpression.js +52 -0
- package/src/utilities/array.js +30 -0
- package/src/utilities/node.js +454 -0
- package/src/utilities/query.js +22 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { ERROR_RULE_NAME,
|
|
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";
|
|
13
|
+
|
|
14
|
+
export function indexFromIndexNode(indexNode) {
|
|
15
|
+
const nonTerminalNode = indexNode, ///
|
|
16
|
+
index = fromFirstChildNode(nonTerminalNode, (firstChildNode) => {
|
|
17
|
+
const terminalNode = firstChildNode, ///
|
|
18
|
+
content = terminalNode.getContent(),
|
|
19
|
+
index = Number(content);
|
|
20
|
+
|
|
21
|
+
return index;
|
|
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);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return endIndex;
|
|
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();
|
|
224
|
+
|
|
225
|
+
if (childNodeNonTerminalNode) {
|
|
226
|
+
const nonTerminalNode = childNode, ///
|
|
227
|
+
ruleName = nonTerminalNode.getRuleName(),
|
|
228
|
+
ruleNameStartIndexRuleName = (ruleName === START_INDEX_RULE_NAME);
|
|
229
|
+
|
|
230
|
+
if (ruleNameStartIndexRuleName) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}) || null;
|
|
235
|
+
|
|
236
|
+
if (startIndexNode !== null) {
|
|
237
|
+
startIndex = indexFromIndexNode(startIndexNode);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return startIndex;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function pathNodeFromExpressionNode(expressionNode) {
|
|
244
|
+
const nonTerminalNode = expressionNode, ///
|
|
245
|
+
pathNode = fromFirstChildNode(nonTerminalNode, (firstChildNode) => {
|
|
246
|
+
const pathNode = firstChildNode; ///
|
|
247
|
+
|
|
248
|
+
return pathNode;
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return pathNode;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function spreadNodeFromExpressionNode(expressionNode) {
|
|
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; ///
|
|
348
|
+
}
|
|
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
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return subExpressionNode;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function fromFirstChildNode(nonTerminalNode, callback) {
|
|
384
|
+
let result;
|
|
385
|
+
|
|
386
|
+
const firstIndex = 0;
|
|
387
|
+
|
|
388
|
+
nonTerminalNode.forwardsSomeChildNode((childNode, index) => {
|
|
389
|
+
if (index === firstIndex) {
|
|
390
|
+
const firstChildNode = childNode; ///
|
|
391
|
+
|
|
392
|
+
result = callback(firstChildNode);
|
|
393
|
+
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function fromSecondChildNode(nonTerminalNode, callback) {
|
|
402
|
+
let result;
|
|
403
|
+
|
|
404
|
+
const secondIndex = 1;
|
|
405
|
+
|
|
406
|
+
nonTerminalNode.forwardsSomeChildNode((childNode, index) => {
|
|
407
|
+
if (index === secondIndex) {
|
|
408
|
+
const firstChildNode = childNode; ///
|
|
409
|
+
|
|
410
|
+
result = callback(firstChildNode);
|
|
411
|
+
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
return result;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function fromThirdChildNode(nonTerminalNode, callback) {
|
|
420
|
+
let result;
|
|
421
|
+
|
|
422
|
+
const thirdIndex = 2;
|
|
423
|
+
|
|
424
|
+
nonTerminalNode.forwardsSomeChildNode((childNode, index) => {
|
|
425
|
+
if (index === thirdIndex) {
|
|
426
|
+
const thirdChildNode = childNode; ///
|
|
427
|
+
|
|
428
|
+
result = callback(thirdChildNode);
|
|
429
|
+
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function fromLastChildNode(nonTerminalNode, callback) {
|
|
438
|
+
let result;
|
|
439
|
+
|
|
440
|
+
const multiplicity = nonTerminalNode.getMultiplicity(),
|
|
441
|
+
lastIndex = multiplicity - 1;
|
|
442
|
+
|
|
443
|
+
nonTerminalNode.backwardsSomeChildNode((childNode, index) => {
|
|
444
|
+
if (index === lastIndex) {
|
|
445
|
+
const thirdChildNode = childNode; ///
|
|
446
|
+
|
|
447
|
+
result = callback(thirdChildNode);
|
|
448
|
+
|
|
449
|
+
return true;
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
return result;
|
|
454
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Query from "../query";
|
|
4
|
+
import Expression from "../expression";
|
|
5
|
+
|
|
6
|
+
export function queryByExpressionString(node, expressionString, maximumDepth) {
|
|
7
|
+
let nodes = null;
|
|
8
|
+
|
|
9
|
+
const expression = Expression.fromExpressionString(expressionString);
|
|
10
|
+
|
|
11
|
+
if (expression !== null) {
|
|
12
|
+
const query = Query.fromExpression(expression, maximumDepth);
|
|
13
|
+
|
|
14
|
+
nodes = query.execute(node);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return nodes;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
queryByExpressionString
|
|
22
|
+
};
|