clarity-pattern-parser 9.2.1 → 9.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-pattern-parser",
3
- "version": "9.2.1",
3
+ "version": "9.2.3",
4
4
  "description": "Parsing Library for Typescript and Javascript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -380,7 +380,9 @@ describe("Grammar", () => {
380
380
  `;
381
381
  const expression = `
382
382
  import { first-name } from "first-name.cpat"
383
- import { space } from "space.cpat" with params { custom-space = " " }
383
+ import { space } from "space.cpat" with params {
384
+ custom-space = " "
385
+ }
384
386
  last-name = "Doe"
385
387
  full-name = first-name + space + last-name
386
388
  `;
@@ -131,13 +131,15 @@ export class Grammar {
131
131
  }
132
132
 
133
133
  private _buildPatterns(ast: Node) {
134
- const body = ast.find(n => n.name === "body");
134
+ const body = ast.find(n => n.name === "body" && n.findAncester(n => n.name === "head") == null);
135
135
 
136
136
  if (body == null) {
137
137
  return;
138
138
  }
139
139
 
140
- body.findAll(n => n.name === "assign-statement").forEach((n) => {
140
+ const statements = body.findAll(n => n.name === "assign-statement");
141
+
142
+ statements.forEach((n) => {
141
143
  const patternNode = n.children.find(n => patternNodes[n.name] != null);
142
144
 
143
145
  if (patternNode == null) {
@@ -449,7 +451,7 @@ export class Grammar {
449
451
  const paramsStatement = importStatement.find(n => n.name === "with-params-statement");
450
452
 
451
453
  if (paramsStatement != null) {
452
- const statements = paramsStatement.find(n => n.name === "with-params-body");
454
+ const statements = paramsStatement.find(n => n.name === "body");
453
455
 
454
456
  if (statements != null) {
455
457
  const expression = statements.toString();
@@ -8,7 +8,8 @@ import { Optional } from "../../patterns/Optional";
8
8
 
9
9
  const bodyLineContent = new Options("body-line-content", [
10
10
  comment,
11
- statement
11
+ statement,
12
+ lineSpaces
12
13
  ]);
13
14
 
14
15
  const optionalLineSpaces = new Optional("optional-line-spaces", lineSpaces);
@@ -19,4 +20,4 @@ const bodyLine = new Sequence("body-line", [
19
20
  optionalLineSpaces,
20
21
  ]);
21
22
 
22
- export const body = new Optional("optional-body", new Repeat("body", bodyLine, {divider: newLine}));
23
+ export const body = new Optional("optional-body", new Repeat("body", bodyLine, { divider: newLine }));
@@ -47,7 +47,7 @@ const withParamsStatement = new Optional("optional-with-params-statement", new S
47
47
  optionalLineSpaces,
48
48
  openBracket,
49
49
  optionalSpaces,
50
- body.clone("with-params-body"),
50
+ body,
51
51
  optionalSpaces,
52
52
  closeBracket
53
53
  ]));
@@ -28,7 +28,7 @@ describe("Patterns String Template Literal", ()=>{
28
28
  debugger;
29
29
  const result = body.exec(`
30
30
  <div>
31
- <div></div>
31
+ <span></span>
32
32
  <div></div>
33
33
  </div>
34
34
  `, true);
@@ -43,7 +43,7 @@ describe("Options", () => {
43
43
  cursor.next();
44
44
 
45
45
  result = a.parse(cursor);
46
- expected = new Node("or", "a-b", 0, 0, [
46
+ expected = new Node("options", "a-b", 0, 0, [
47
47
  new Node("literal", "b", 0, 0, [], "B")
48
48
  ], "B");
49
49
  });
@@ -76,7 +76,7 @@ describe("Options", () => {
76
76
  test("Properties", () => {
77
77
  const a = new Options("a", [new Literal("a", "A")]);
78
78
 
79
- expect(a.type).toBe("or");
79
+ expect(a.type).toBe("options");
80
80
  expect(a.name).toBe("a");
81
81
  expect(a.parent).toBeNull();
82
82
  expect(a.children[0].name).toBe("a");
@@ -48,8 +48,8 @@ export class Options implements Pattern {
48
48
  const children = clonePatterns(options);
49
49
  this._assignChildrenToParent(children);
50
50
 
51
- this._id = `or-${idIndex++}`;
52
- this._type = "or";
51
+ this._id = `options-${idIndex++}`;
52
+ this._type = "options";
53
53
  this._name = name;
54
54
  this._parent = null;
55
55
  this._children = children;