clarity-pattern-parser 11.0.19 → 11.0.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-pattern-parser",
3
- "version": "11.0.19",
3
+ "version": "11.0.21",
4
4
  "description": "Parsing Library for Typescript and Javascript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -10,6 +10,7 @@ import { Grammar } from "./Grammar";
10
10
  import { Optional } from "../patterns/Optional";
11
11
  import { Context } from "../patterns/Context";
12
12
  import { patterns } from "./patterns";
13
+ import { Expression } from "../patterns/Expression";
13
14
 
14
15
  describe("Grammar", () => {
15
16
  test("Literal", () => {
@@ -517,7 +518,7 @@ debugger;
517
518
  ],
518
519
  true
519
520
  ),
520
- new Options("anonymous", [
521
+ new Expression("anonymous", [
521
522
  new Reference("pattern"),
522
523
  new Reference("pattern")
523
524
  ])
@@ -280,6 +280,10 @@ export class Grammar {
280
280
  }
281
281
 
282
282
  private _isRecursivePattern(name: string, pattern: Pattern) {
283
+ if (pattern.type === "reference") {
284
+ return true;
285
+ }
286
+
283
287
  if (pattern.children.length === 0) {
284
288
  return false;
285
289
  }
@@ -287,10 +291,9 @@ export class Grammar {
287
291
  const firstChild = pattern.children[0];
288
292
  const lastChild = pattern.children[pattern.children.length - 1];
289
293
  const isLongEnough = pattern.children.length >= 2;
290
- return pattern.type === "reference" ||
291
- (pattern.type === "sequence" && isLongEnough &&
292
- (firstChild.type === "reference" && firstChild.name === name) ||
293
- (lastChild.type === "reference" && lastChild.name === name));
294
+ return (pattern.type === "sequence" && isLongEnough &&
295
+ (firstChild.name === name) ||
296
+ (lastChild.name === name));
294
297
  }
295
298
 
296
299
  private _buildPattern(node: Node): Pattern {
@@ -233,7 +233,9 @@ export class Expression implements Pattern {
233
233
  }
234
234
 
235
235
  if (pattern.type === "reference") {
236
+ pattern.parent = this;
236
237
  pattern = (pattern as Reference).getReferencePatternSafely();
238
+ pattern.parent = null;
237
239
  }
238
240
 
239
241
  return pattern;
@@ -247,7 +249,7 @@ export class Expression implements Pattern {
247
249
  if (pattern == null) {
248
250
  return false;
249
251
  }
250
- return pattern.type === "reference" && pattern.name === this.name;
252
+ return pattern.name === this.name;
251
253
  }
252
254
 
253
255
  parse(cursor: Cursor): Node | null {