occam-parsers 23.0.137 → 23.0.139

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { arrayUtilities } from "necessary";
4
4
 
5
- const { first, forwardsSome, backwardsSome } = arrayUtilities;
5
+ const { push, first, forwardsSome, backwardsSome } = arrayUtilities;
6
6
 
7
7
  function getMultiplicity() {
8
8
  const childNodesLength = this.childNodes.length,
@@ -232,12 +232,33 @@ function findAncestorNode(callback) {
232
232
 
233
233
  index++;
234
234
  }
235
+
236
+ ancestorNode = undefined;
237
+
238
+ return ancestorNode;
235
239
  }
236
240
 
237
241
  function everyAncestorNode(callback) {
238
- const ancestorNodes = this.getAncestorNodes();
242
+ let result = true;
243
+
244
+ let index = 0,
245
+ ancestorNode = this.parentNode; ///
246
+
247
+ while (ancestorNode !== null) {
248
+ result = callback(ancestorNode, index);
249
+
250
+ if (!result) {
251
+ break;
252
+ }
253
+
254
+ const parentNode = ancestorNode.getParentNode();
239
255
 
240
- return ancestorNodes.every(callback);
256
+ ancestorNode = parentNode; ///
257
+
258
+ index++;
259
+ }
260
+
261
+ return result;
241
262
  }
242
263
 
243
264
  function filterAncestorNode(callback) {
@@ -258,6 +279,118 @@ function forEachAncestorNode(callback) {
258
279
  ancestorNodes.forEach(callback);
259
280
  }
260
281
 
282
+ function getDescendantNodes(descendantNodes = []) {
283
+ push(descendantNodes, this.childNodes);
284
+
285
+ this.forEachChildNode((childNode) => {
286
+ childNode.getDescendantNodes(descendantNodes);
287
+ });
288
+
289
+ return descendantNodes;
290
+ }
291
+
292
+ function mapDescendantNode(callback) {
293
+ const descendantNodes = this.getDescendantNodes();
294
+
295
+ return descendantNodes.map(callback);
296
+ }
297
+
298
+ function someDescendantNode(callback) {
299
+ let result = false;
300
+
301
+ const childNodesLength = this.childNodes.length;
302
+
303
+ for (let index = 0; index < childNodesLength; index++) {
304
+ const childNode = this.childNodes[index],
305
+ descendantNode = childNode; ///
306
+
307
+ result = callback(descendantNode);
308
+
309
+ if (result) {
310
+ break;
311
+ }
312
+
313
+ result = childNode.someDescendantNode(callback);
314
+
315
+ if (result) {
316
+ break;
317
+ }
318
+ }
319
+
320
+ return result;
321
+ }
322
+
323
+ function findDescendantNode(callback) {
324
+ let descendantNode = undefined;
325
+
326
+ const childNodesLength = this.childNodes.length;
327
+
328
+ for (let index = 0; index < childNodesLength; index++) {
329
+ let result;
330
+
331
+ const childNode = this.childNodes[index];
332
+
333
+ descendantNode = childNode; ///
334
+
335
+ result = callback(descendantNode);
336
+
337
+ if (result) {
338
+ break;
339
+ }
340
+
341
+ descendantNode = childNode.findDescendantNode(callback);
342
+
343
+ if (descendantNode !== undefined) {
344
+ break;
345
+ }
346
+ }
347
+
348
+ return descendantNode;
349
+ }
350
+
351
+ function everyDescendantNode(callback) {
352
+ let result = true;
353
+
354
+ const childNodesLength = this.childNodes.length;
355
+
356
+ for (let index = 0; index < childNodesLength; index++) {
357
+ const childNode = this.childNodes[index],
358
+ descendantNode = childNode; ///
359
+
360
+ result = callback(descendantNode);
361
+
362
+ if (!result) {
363
+ break;
364
+ }
365
+
366
+ result = childNode.everyDescendantNode(callback);
367
+
368
+ if (!result) {
369
+ break;
370
+ }
371
+ }
372
+
373
+ return result;
374
+ }
375
+
376
+ function filterDescendantNode(callback) {
377
+ const descendantNodes = this.getDescendantNodes();
378
+
379
+ return descendantNodes.filter(callback);
380
+ }
381
+
382
+ function reduceDescendantNode(callback, initialValue) {
383
+ const descendantNodes = this.getDescendantNodes();
384
+
385
+ return descendantNodes.reduce(callback, initialValue);
386
+ }
387
+
388
+ function forEachDescendantNode(callback) {
389
+ const descendantNodes = this.getDescendantNodes();
390
+
391
+ descendantNodes.forEach(callback);
392
+ }
393
+
261
394
  const nodeMixins = {
262
395
  getMultiplicity,
263
396
  mapChildNode,
@@ -291,7 +424,15 @@ const nodeMixins = {
291
424
  everyAncestorNode,
292
425
  filterAncestorNode,
293
426
  reduceAncestorNode,
294
- forEachAncestorNode
427
+ forEachAncestorNode,
428
+ getDescendantNodes,
429
+ mapDescendantNode,
430
+ someDescendantNode,
431
+ findDescendantNode,
432
+ everyDescendantNode,
433
+ filterDescendantNode,
434
+ reduceDescendantNode,
435
+ forEachDescendantNode
295
436
  };
296
437
 
297
438
  export default nodeMixins;
@@ -92,6 +92,10 @@ export default class NonTerminalNode {
92
92
  return nonTerminalNode;
93
93
  }
94
94
 
95
+ getDescendantNodes(descendantNodes) {
96
+ return descendantNodes;
97
+ }
98
+
95
99
  getFirstSignificantTokenIndex(tokens) {
96
100
  let firstSignificantTokenIndex;
97
101
 
@@ -132,24 +136,6 @@ export default class NonTerminalNode {
132
136
  return significantTokens;
133
137
  }
134
138
 
135
- getDescendantNodes(descendantNodes = []) {
136
- const descendantNode = this; ///
137
-
138
- descendantNodes.push(descendantNode);
139
-
140
- this.childNodes.forEach((childNode) => {
141
- const childNodeNonTerminalNode = childNode.isNonTerminalNode();
142
-
143
- if (childNodeNonTerminalNode) {
144
- const nonTerminalNode = childNode; ///
145
-
146
- nonTerminalNode.getDescendantNodes(descendantNodes);
147
- }
148
- });
149
-
150
- return descendantNodes;
151
- }
152
-
153
139
  getMultiplicity() {
154
140
  const childNodesLength = this.childNodes.length,
155
141
  multiplicity = childNodesLength; ///
@@ -164,12 +164,33 @@ export default class TerminalNode {
164
164
 
165
165
  index++;
166
166
  }
167
+
168
+ ancestorNode = undefined;
169
+
170
+ return ancestorNode;
167
171
  }
168
172
 
169
173
  everyAncestorNode(callback) {
170
- const ancestorNodes = this.getAncestorNodes();
174
+ let result = true;
175
+
176
+ let index = 0,
177
+ ancestorNode = this.parentNode; ///
178
+
179
+ while (ancestorNode !== null) {
180
+ result = callback(ancestorNode, index);
171
181
 
172
- return ancestorNodes.every(callback);
182
+ if (!result) {
183
+ break;
184
+ }
185
+
186
+ const parentNode = ancestorNode.getParentNode();
187
+
188
+ ancestorNode = parentNode; ///
189
+
190
+ index++;
191
+ }
192
+
193
+ return result;
173
194
  }
174
195
 
175
196
  filterAncestorNode(callback) {
@@ -190,6 +211,28 @@ export default class TerminalNode {
190
211
  ancestorNodes.forEach(callback);
191
212
  }
192
213
 
214
+ getDescendantNodes(descendantNodes = []) {
215
+ return descendantNodes;
216
+ }
217
+
218
+ someDescendantNode(callback) {
219
+ const result = false;
220
+
221
+ return result;
222
+ }
223
+
224
+ findDescendantNode(callback) {
225
+ let descendantNode = undefined;
226
+
227
+ return descendantNode;
228
+ }
229
+
230
+ everyDescendantNode(callback) {
231
+ let result = true;
232
+
233
+ return result;
234
+ }
235
+
193
236
  asParseTree(tokens) {
194
237
  const terminalNode = this, ///
195
238
  terminalNodeParseTree = TerminalNodeParseTree.fromTerminalNodeAndTokens(terminalNode, tokens),