clarity-pattern-parser 10.3.7 → 11.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.
Files changed (51) hide show
  1. package/dist/ast/Node.d.ts +2 -2
  2. package/dist/ast/compact.d.ts +2 -0
  3. package/dist/ast/remove.d.ts +2 -0
  4. package/dist/index.browser.js +417 -487
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.d.ts +3 -1
  7. package/dist/index.esm.js +416 -488
  8. package/dist/index.esm.js.map +1 -1
  9. package/dist/index.js +417 -487
  10. package/dist/index.js.map +1 -1
  11. package/dist/patterns/ExpressionPattern.d.ts +27 -25
  12. package/dist/patterns/FiniteRepeat.d.ts +1 -2
  13. package/dist/patterns/InfiniteRepeat.d.ts +1 -2
  14. package/dist/patterns/Literal.d.ts +0 -1
  15. package/dist/patterns/Not.d.ts +1 -2
  16. package/dist/patterns/Optional.d.ts +0 -1
  17. package/dist/patterns/Options.d.ts +1 -2
  18. package/dist/patterns/Pattern.d.ts +0 -1
  19. package/dist/patterns/PrecedenceTree.d.ts +28 -0
  20. package/dist/patterns/Reference.d.ts +1 -2
  21. package/dist/patterns/Regex.d.ts +1 -2
  22. package/dist/patterns/Repeat.d.ts +0 -3
  23. package/dist/patterns/Sequence.d.ts +3 -6
  24. package/dist/patterns/execPattern.d.ts +3 -0
  25. package/dist/patterns/testPattern.d.ts +2 -0
  26. package/package.json +1 -1
  27. package/src/ast/Node.test.ts +17 -17
  28. package/src/ast/Node.ts +7 -5
  29. package/src/ast/compact.ts +11 -0
  30. package/src/ast/remove.ts +11 -0
  31. package/src/grammar/Grammar.test.ts +0 -50
  32. package/src/grammar/Grammar.ts +0 -20
  33. package/src/grammar/patterns/statement.ts +1 -6
  34. package/src/index.ts +4 -0
  35. package/src/patterns/ExpressionPattern.test.ts +1 -1
  36. package/src/patterns/ExpressionPattern.ts +235 -384
  37. package/src/patterns/FiniteRepeat.ts +5 -22
  38. package/src/patterns/InfiniteRepeat.ts +6 -21
  39. package/src/patterns/Literal.ts +5 -19
  40. package/src/patterns/Not.ts +5 -16
  41. package/src/patterns/Optional.ts +0 -7
  42. package/src/patterns/Options.ts +5 -21
  43. package/src/patterns/Pattern.ts +0 -1
  44. package/src/patterns/PrecedenceTree.test.ts +162 -0
  45. package/src/patterns/PrecedenceTree.ts +207 -0
  46. package/src/patterns/Reference.ts +5 -17
  47. package/src/patterns/Regex.ts +5 -17
  48. package/src/patterns/Repeat.ts +1 -13
  49. package/src/patterns/Sequence.ts +7 -22
  50. package/src/patterns/execPattern.ts +16 -0
  51. package/src/patterns/testPattern.ts +11 -0
@@ -11,52 +11,54 @@ export declare class ExpressionPattern implements Pattern {
11
11
  private _originalPatterns;
12
12
  private _patterns;
13
13
  private _atomPatterns;
14
- private _unaryPrefixPatterns;
15
- private _unaryPrefixNames;
14
+ private _prefixPatterns;
15
+ private _prefixNames;
16
+ private _postfixPatterns;
17
+ private _postfixNames;
16
18
  private _binaryPatterns;
17
- private _recursivePatterns;
18
- private _recursiveNames;
19
- private _endsInRecursion;
20
- private _binaryAssociation;
21
- private _precedenceMap;
22
19
  private _binaryNames;
23
- private _shouldCompactPatternsMap;
24
- shouldCompactAst: boolean;
20
+ private associationMap;
21
+ private _precedenceMap;
22
+ private _shouldStopParsing;
23
+ private _precedenceTree;
25
24
  get id(): string;
26
25
  get type(): string;
27
26
  get name(): string;
28
27
  get parent(): Pattern | null;
29
28
  set parent(pattern: Pattern | null);
30
29
  get children(): Pattern[];
31
- get unaryPrefixPatterns(): readonly Pattern[];
30
+ get prefixPatterns(): readonly Pattern[];
32
31
  get atomPatterns(): readonly Pattern[];
32
+ get postfixPatterns(): readonly Pattern[];
33
33
  get binaryPatterns(): readonly Pattern[];
34
- get recursivePatterns(): readonly Pattern[];
35
34
  get startedOnIndex(): number;
36
35
  constructor(name: string, patterns: Pattern[]);
37
36
  private _organizePatterns;
38
- private _isBinary;
39
- private _isBinaryPattern;
40
- private _extractDelimiter;
41
37
  private _extractName;
42
- private _isUnary;
43
- private _isUnaryPattern;
44
- private _extractUnaryPrefixPattern;
45
- private _isRecursive;
46
- private _isRecursivePattern;
47
- private _extractRecursiveTail;
48
- private _endsWithRecursion;
38
+ private _isPrefix;
39
+ private _extractPrefix;
40
+ private _isAtom;
41
+ private _isPostfix;
42
+ private _extractPostfix;
43
+ private _isBinary;
44
+ private _extractBinary;
45
+ private _unwrapAssociationIfNecessary;
46
+ private _referenceCount;
47
+ private _isRecursiveReference;
49
48
  parse(cursor: Cursor): Node | null;
50
- private _compactResult;
51
49
  private _tryToParse;
50
+ private _tryToMatchPrefix;
51
+ private _tryToMatchAtom;
52
+ private _tryToMatchPostfix;
53
+ private _tryToMatchBinary;
52
54
  private _isBeyondRecursiveAllowance;
53
- test(text: string): boolean;
55
+ test(text: string, record?: boolean): boolean;
54
56
  exec(text: string, record?: boolean): ParseResult;
55
57
  getTokens(): string[];
56
- getTokensAfter(childReference: Pattern): string[];
58
+ getTokensAfter(_childReference: Pattern): string[];
57
59
  getNextTokens(): string[];
58
60
  getPatterns(): Pattern[];
59
- getPatternsAfter(childReference: Pattern): Pattern[];
61
+ getPatternsAfter(_childReference: Pattern): Pattern[];
60
62
  getNextPatterns(): Pattern[];
61
63
  find(predicate: (p: Pattern) => boolean): Pattern | null;
62
64
  clone(name?: string): Pattern;
@@ -19,7 +19,6 @@ export declare class FiniteRepeat implements Pattern {
19
19
  private _max;
20
20
  private _trimDivider;
21
21
  private _firstIndex;
22
- shouldCompactAst: boolean;
23
22
  get id(): string;
24
23
  get type(): string;
25
24
  get name(): string;
@@ -31,7 +30,7 @@ export declare class FiniteRepeat implements Pattern {
31
30
  get startedOnIndex(): number;
32
31
  constructor(name: string, pattern: Pattern, options?: FiniteRepeatOptions);
33
32
  parse(cursor: Cursor): Node | null;
34
- test(text: string): boolean;
33
+ test(text: string, record?: boolean): boolean;
35
34
  exec(text: string, record?: boolean): ParseResult;
36
35
  clone(name?: string): Pattern;
37
36
  getTokens(): string[];
@@ -19,7 +19,6 @@ export declare class InfiniteRepeat implements Pattern {
19
19
  private _firstIndex;
20
20
  private _min;
21
21
  private _trimDivider;
22
- shouldCompactAst: boolean;
23
22
  get id(): string;
24
23
  get type(): string;
25
24
  get name(): string;
@@ -30,7 +29,7 @@ export declare class InfiniteRepeat implements Pattern {
30
29
  get startedOnIndex(): number;
31
30
  constructor(name: string, pattern: Pattern, options?: InfiniteRepeatOptions);
32
31
  private _assignChildrenToParent;
33
- test(text: string): boolean;
32
+ test(text: string, record?: boolean): boolean;
34
33
  exec(text: string, record?: boolean): ParseResult;
35
34
  parse(cursor: Cursor): Node | null;
36
35
  private _meetsMin;
@@ -12,7 +12,6 @@ export declare class Literal implements Pattern {
12
12
  private _firstIndex;
13
13
  private _lastIndex;
14
14
  private _endIndex;
15
- shouldCompactAst: boolean;
16
15
  get id(): string;
17
16
  get type(): string;
18
17
  get name(): string;
@@ -8,7 +8,6 @@ export declare class Not implements Pattern {
8
8
  private _name;
9
9
  private _parent;
10
10
  private _children;
11
- shouldCompactAst: boolean;
12
11
  get id(): string;
13
12
  get type(): string;
14
13
  get name(): string;
@@ -17,7 +16,7 @@ export declare class Not implements Pattern {
17
16
  get children(): Pattern[];
18
17
  get startedOnIndex(): number;
19
18
  constructor(name: string, pattern: Pattern);
20
- test(text: string): boolean;
19
+ test(text: string, record?: boolean): boolean;
21
20
  exec(text: string, record?: boolean): ParseResult;
22
21
  parse(cursor: Cursor): Node | null;
23
22
  clone(name?: string): Pattern;
@@ -8,7 +8,6 @@ export declare class Optional implements Pattern {
8
8
  private _name;
9
9
  private _parent;
10
10
  private _children;
11
- shouldCompactAst: boolean;
12
11
  get id(): string;
13
12
  get type(): string;
14
13
  get name(): string;
@@ -10,7 +10,6 @@ export declare class Options implements Pattern {
10
10
  private _children;
11
11
  private _isGreedy;
12
12
  private _firstIndex;
13
- shouldCompactAst: boolean;
14
13
  get id(): string;
15
14
  get type(): string;
16
15
  get name(): string;
@@ -20,7 +19,7 @@ export declare class Options implements Pattern {
20
19
  get startedOnIndex(): number;
21
20
  constructor(name: string, options: Pattern[], isGreedy?: boolean);
22
21
  private _assignChildrenToParent;
23
- test(text: string): boolean;
22
+ test(text: string, record?: boolean): boolean;
24
23
  exec(text: string, record?: boolean): ParseResult;
25
24
  parse(cursor: Cursor): Node | null;
26
25
  private _tryToParse;
@@ -5,7 +5,6 @@ export interface Pattern {
5
5
  id: string;
6
6
  type: string;
7
7
  name: string;
8
- shouldCompactAst: boolean;
9
8
  startedOnIndex: number;
10
9
  parent: Pattern | null;
11
10
  children: Pattern[];
@@ -0,0 +1,28 @@
1
+ import { Node } from "../ast/Node";
2
+ export declare enum Association {
3
+ left = 0,
4
+ right = 1
5
+ }
6
+ export declare class PrecedenceTree {
7
+ private _prefixPlaceholder;
8
+ private _prefixNode;
9
+ private _postfixPlaceholder;
10
+ private _postfixNode;
11
+ private _binaryPlaceholder;
12
+ private _binaryNode;
13
+ private _atomNode;
14
+ private _orphanedAtom;
15
+ private _precedenceMap;
16
+ private _associationMap;
17
+ constructor(precedenceMap?: Record<string, number>, associationMap?: Record<string, Association>);
18
+ addPrefix(name: string, ...prefix: Node[]): void;
19
+ addPostfix(name: string, ...postfix: Node[]): void;
20
+ addBinary(name: string, ...delimiterNode: Node[]): void;
21
+ private _getPrecedenceFromNode;
22
+ private _getPrecedence;
23
+ private _compileAtomNode;
24
+ addAtom(node: Node): void;
25
+ hasAtom(): boolean;
26
+ commit(): Node | null;
27
+ private reset;
28
+ }
@@ -11,7 +11,6 @@ export declare class Reference implements Pattern {
11
11
  private _pattern;
12
12
  private _children;
13
13
  private _firstIndex;
14
- shouldCompactAst: boolean;
15
14
  get id(): string;
16
15
  get type(): string;
17
16
  get name(): string;
@@ -20,7 +19,7 @@ export declare class Reference implements Pattern {
20
19
  get children(): Pattern[];
21
20
  get startedOnIndex(): number;
22
21
  constructor(name: string);
23
- test(text: string): boolean;
22
+ test(text: string, record?: boolean): boolean;
24
23
  exec(text: string, record?: boolean): ParseResult;
25
24
  parse(cursor: Cursor): Node | null;
26
25
  getReferencePatternSafely(): Pattern;
@@ -14,7 +14,6 @@ export declare class Regex implements Pattern {
14
14
  private _firstIndex;
15
15
  private _substring;
16
16
  private _tokens;
17
- shouldCompactAst: boolean;
18
17
  get id(): string;
19
18
  get type(): string;
20
19
  get name(): string;
@@ -25,7 +24,7 @@ export declare class Regex implements Pattern {
25
24
  get startedOnIndex(): number;
26
25
  constructor(name: string, regex: string);
27
26
  private assertArguments;
28
- test(text: string): boolean;
27
+ test(text: string, record?: boolean): boolean;
29
28
  exec(text: string, record?: boolean): ParseResult;
30
29
  parse(cursor: Cursor): Node | null;
31
30
  private resetState;
@@ -15,9 +15,6 @@ export declare class Repeat implements Pattern {
15
15
  private _pattern;
16
16
  private _options;
17
17
  private _children;
18
- private _shouldCompactAst;
19
- get shouldCompactAst(): boolean;
20
- set shouldCompactAst(value: boolean);
21
18
  get id(): string;
22
19
  get type(): string;
23
20
  get name(): string;
@@ -1,6 +1,7 @@
1
1
  import { Cursor } from "./Cursor";
2
2
  import { Pattern } from "./Pattern";
3
3
  import { Node } from "../ast/Node";
4
+ import { ParseResult } from "./ParseResult";
4
5
  export declare class Sequence implements Pattern {
5
6
  private _id;
6
7
  private _type;
@@ -9,7 +10,6 @@ export declare class Sequence implements Pattern {
9
10
  private _children;
10
11
  private _nodes;
11
12
  private _firstIndex;
12
- shouldCompactAst: boolean;
13
13
  get id(): string;
14
14
  get type(): string;
15
15
  get name(): string;
@@ -19,11 +19,8 @@ export declare class Sequence implements Pattern {
19
19
  get startedOnIndex(): number;
20
20
  constructor(name: string, sequence: Pattern[]);
21
21
  private _assignChildrenToParent;
22
- test(text: string): boolean;
23
- exec(text: string, record?: boolean): {
24
- ast: Node | null;
25
- cursor: Cursor;
26
- };
22
+ test(text: string, record?: boolean): boolean;
23
+ exec(text: string, record?: boolean): ParseResult;
27
24
  parse(cursor: Cursor): Node | null;
28
25
  private tryToParse;
29
26
  private getLastValidNode;
@@ -0,0 +1,3 @@
1
+ import { ParseResult } from "./ParseResult";
2
+ import { Pattern } from "./Pattern";
3
+ export declare function execPattern(pattern: Pattern, text: string, record?: boolean): ParseResult;
@@ -0,0 +1,2 @@
1
+ import { Pattern } from "./Pattern";
2
+ export declare function testPattern(pattern: Pattern, text: string, record?: boolean): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-pattern-parser",
3
- "version": "10.3.7",
3
+ "version": "11.0.0",
4
4
  "description": "Parsing Library for Typescript and Javascript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -441,34 +441,34 @@ describe("Node", () => {
441
441
  });
442
442
 
443
443
  test("Transform", () => {
444
- const node = Node.createNode("grandparent", [
445
- Node.createNode("parent", [
446
- Node.createValueNode("child", "John"),
447
- Node.createValueNode("child", "Jane"),
448
- Node.createValueNode("child", "Jack")
444
+ const node = Node.createNode("family", "grandparent", [
445
+ Node.createNode("family", "parent", [
446
+ Node.createValueNode("family", "child", "John"),
447
+ Node.createValueNode("family", "child", "Jane"),
448
+ Node.createValueNode("family", "child", "Jack")
449
449
  ]),
450
- Node.createValueNode("aunt", "aunt")
450
+ Node.createValueNode("family", "aunt", "aunt")
451
451
  ]);
452
452
 
453
453
  const result = node.transform({
454
454
  "child": (node: Node) => {
455
- return Node.createValueNode("adopted-child", node.value);
455
+ return Node.createValueNode("family", "adopted-child", node.value);
456
456
  },
457
- "parent": (node)=>{
458
- return Node.createNode("adopted-parent", node.children.slice());
457
+ "parent": (node) => {
458
+ return Node.createNode("family", "adopted-parent", node.children.slice());
459
459
  },
460
- "grandparent": (node)=>{
461
- return Node.createNode("adopted-grandparent", node.children.slice());
460
+ "grandparent": (node) => {
461
+ return Node.createNode("family", "adopted-grandparent", node.children.slice());
462
462
  }
463
463
  });
464
464
 
465
- const expected = Node.createNode("adopted-grandparent", [
466
- Node.createNode("adopted-parent", [
467
- Node.createValueNode("adopted-child", "John"),
468
- Node.createValueNode("adopted-child", "Jane"),
469
- Node.createValueNode("adopted-child", "Jack")
465
+ const expected = Node.createNode("family", "adopted-grandparent", [
466
+ Node.createNode("family", "adopted-parent", [
467
+ Node.createValueNode("family", "adopted-child", "John"),
468
+ Node.createValueNode("family", "adopted-child", "Jane"),
469
+ Node.createValueNode("family", "adopted-child", "Jack")
470
470
  ]),
471
- Node.createValueNode("aunt", "aunt")
471
+ Node.createValueNode("family", "aunt", "aunt")
472
472
  ]);
473
473
 
474
474
  expect(result.toJson()).toBe(expected.toJson());
package/src/ast/Node.ts CHANGED
@@ -114,6 +114,8 @@ export class Node {
114
114
 
115
115
  if (index > -1) {
116
116
  this.spliceChildren(index, 1, newNode);
117
+ newNode._parent = this;
118
+ referenceNode._parent = null;
117
119
  }
118
120
  }
119
121
 
@@ -308,7 +310,7 @@ export class Node {
308
310
  return length;
309
311
  }
310
312
 
311
- compact(){
313
+ compact() {
312
314
  this._value = this.toString();
313
315
  this._children.length = 0;
314
316
  }
@@ -340,12 +342,12 @@ export class Node {
340
342
  return node.toJson(0) === this.toJson(0);
341
343
  }
342
344
 
343
- static createValueNode(name: string, value: string) {
344
- return new Node("custom-value-node", name, 0, 0, [], value);
345
+ static createValueNode(type: string, name: string, value = "") {
346
+ return new Node(type, name, 0, 0, [], value);
345
347
  }
346
348
 
347
- static createNode(name: string, children: Node[]) {
349
+ static createNode(type: string, name: string, children: Node[] = []) {
348
350
  const value = children.map(c => c.toString()).join("");
349
- return new Node("custom-node", name, 0, 0, children, value);
351
+ return new Node(type, name, 0, 0, children, value);
350
352
  }
351
353
  }
@@ -0,0 +1,11 @@
1
+ import { Node } from "./Node";
2
+
3
+ export function compact(node: Node, nodeMap: Record<string, boolean>) {
4
+ node.walkBreadthFirst(n=>{
5
+ if (nodeMap[n.name]){
6
+ n.compact();
7
+ }
8
+ });
9
+
10
+ return node;
11
+ }
@@ -0,0 +1,11 @@
1
+ import { Node } from "./Node";
2
+
3
+ export function remove(node: Node, nodeMap: Record<string, boolean>) {
4
+ node.walkBreadthFirst(n=>{
5
+ if (nodeMap[n.name]){
6
+ n.remove();
7
+ }
8
+ });
9
+
10
+ return node;
11
+ }
@@ -584,54 +584,4 @@ describe("Grammar", () => {
584
584
  expect(result).toBe(result);
585
585
  });
586
586
 
587
- test("Compacted Recursive Sequence", () => {
588
- const { expression } = patterns`
589
- variables = "a" | "b" | "c"
590
- ternary = expression + " ? " + expression + " : " + expression compact
591
- expression = ternary | variables
592
- `;
593
- const result = expression.exec("a ? b : c");
594
- expect(result.ast?.children.length).toBe(0);
595
- expect(result.ast?.value).toBe("a ? b : c");
596
- });
597
-
598
- test("Compacted Repeat", () => {
599
- const { variables } = patterns`
600
- variable = "a" | "b" | "c"
601
- variables = (variable, /\s*,\s*/)+ compact
602
- `;
603
- const result = variables.exec("a,b,c");
604
- expect(result.ast?.children.length).toBe(0);
605
- expect(result.ast?.value).toBe("a,b,c");
606
- });
607
-
608
- test("Compacted Binary Expression", () => {
609
- const { expression } = patterns`
610
- variable = "a" | "b" | "c"
611
- mult-div-operator = " * " | " / "
612
- add-sub-operator = " + " | " - "
613
-
614
- mult-div-expression = expression + mult-div-operator + expression compact
615
- add-sub-expression = expression + add-sub-operator + expression compact
616
- expression = mult-div-expression | add-sub-expression | variable
617
- `;
618
- const result = expression.exec("a * b + c");
619
- expect(result.ast?.children.length).toBe(0);
620
- expect(result.ast?.value).toBe("a * b + c");
621
- });
622
-
623
- test("Compacted Expression", () => {
624
- const { expression } = patterns`
625
- variable = "a" | "b" | "c"
626
- mult-div-operator = " * " | " / "
627
- add-sub-operator = " + " | " - "
628
-
629
- mult-div-expression = expression + mult-div-operator + expression
630
- add-sub-expression = expression + add-sub-operator + expression
631
- expression = mult-div-expression | add-sub-expression | variable compact
632
- `;
633
- const result = expression.exec("a * b + c");
634
- expect(result.ast?.children.length).toBe(0);
635
- expect(result.ast?.value).toBe("a * b + c");
636
- });
637
587
  });
@@ -238,15 +238,10 @@ export class Grammar {
238
238
 
239
239
  private _saveOptions(statementNode: Node) {
240
240
  const nameNode = statementNode.find(n => n.name === "name") as Node;
241
- const shouldCompactAst = statementNode.find(n=>n.name === "compact");
242
241
  const name = nameNode.value;
243
242
  const optionsNode = statementNode.find(n => n.name === "options-literal") as Node;
244
243
  const options = this._buildOptions(name, optionsNode);
245
244
 
246
- if (shouldCompactAst != null){
247
- options.shouldCompactAst = true;
248
- }
249
-
250
245
  this._parseContext.patternsByName.set(name, options);
251
246
  }
252
247
 
@@ -315,15 +310,10 @@ export class Grammar {
315
310
 
316
311
  private _saveSequence(statementNode: Node) {
317
312
  const nameNode = statementNode.find(n => n.name === "name") as Node;
318
- const shouldCompactAst = statementNode.find(n=>n.name === "compact");
319
313
  const name = nameNode.value;
320
314
  const sequenceNode = statementNode.find(n => n.name === "sequence-literal") as Node;
321
315
  const sequence = this._buildSequence(name, sequenceNode);
322
316
 
323
- if (shouldCompactAst != null){
324
- sequence.shouldCompactAst = true;
325
- }
326
-
327
317
  this._parseContext.patternsByName.set(name, sequence);
328
318
  }
329
319
 
@@ -349,15 +339,10 @@ export class Grammar {
349
339
 
350
340
  private _saveRepeat(statementNode: Node) {
351
341
  const nameNode = statementNode.find(n => n.name === "name") as Node;
352
- const shouldCompactAst = statementNode.find(n=>n.name === "compact");
353
342
  const name = nameNode.value;
354
343
  const repeatNode = statementNode.find(n => n.name === "repeat-literal") as Node;
355
344
  const repeat = this._buildRepeat(name, repeatNode);
356
345
 
357
- if (shouldCompactAst != null){
358
- repeat.shouldCompactAst = true;
359
- }
360
-
361
346
  this._parseContext.patternsByName.set(name, repeat);
362
347
  }
363
348
 
@@ -542,16 +527,11 @@ export class Grammar {
542
527
 
543
528
  private _saveAlias(statementNode: Node) {
544
529
  const nameNode = statementNode.find(n => n.name === "name") as Node;
545
- const shouldCompactAst = statementNode.find(n=>n.name === "compact");
546
530
  const aliasNode = statementNode.find(n => n.name === "alias-literal") as Node;
547
531
  const aliasName = aliasNode.value;
548
532
  const name = nameNode.value;
549
533
  const alias = this._getPattern(aliasName).clone(name);
550
534
 
551
- if (shouldCompactAst != null){
552
- alias.shouldCompactAst = true;
553
- }
554
-
555
535
  this._parseContext.patternsByName.set(name, alias);
556
536
  }
557
537
 
@@ -2,17 +2,13 @@ import { Sequence } from "../../patterns/Sequence";
2
2
  import { Literal } from "../../patterns/Literal";
3
3
  import { Options } from "../../patterns/Options";
4
4
  import { name } from "./name";
5
- import { lineSpaces, spaces } from "./spaces";
5
+ import { spaces } from "./spaces";
6
6
  import { pattern } from "./pattern";
7
7
  import { Optional } from "../../patterns/Optional";
8
8
 
9
9
  const optionalSpaces = new Optional("optional-spaces", spaces);
10
10
  const assignOperator = new Literal("assign-operator", "=");
11
11
 
12
- const compact = new Literal("compact", "compact");
13
- const compactModifier = new Sequence("compact-modifier", [lineSpaces, compact]);
14
- const optionalCompactModifier = new Optional("optional-compact-modifier", compactModifier);
15
-
16
12
  const assignStatement = new Sequence("assign-statement", [
17
13
  optionalSpaces,
18
14
  name,
@@ -20,7 +16,6 @@ const assignStatement = new Sequence("assign-statement", [
20
16
  assignOperator,
21
17
  optionalSpaces,
22
18
  pattern,
23
- optionalCompactModifier
24
19
  ]);
25
20
 
26
21
  export const statement = new Options("statement", [assignStatement, name.clone("export-name")]);
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { Node } from "./ast/Node";
2
+ import { compact } from './ast/compact';
3
+ import { remove } from './ast/remove';
2
4
  import { Grammar } from "./grammar/Grammar";
3
5
  import { Suggestion } from "./intellisense/Suggestion";
4
6
  import { SuggestionOption } from "./intellisense/SuggestionOption";
@@ -46,4 +48,6 @@ export {
46
48
  Repeat,
47
49
  grammar,
48
50
  patterns,
51
+ compact,
52
+ remove
49
53
  };
@@ -79,7 +79,7 @@ function createExpressionPattern() {
79
79
  new RightAssociatedPattern(multDivExpression),
80
80
  addSubExpression,
81
81
  boolExpression,
82
- ternary,
82
+ new RightAssociatedPattern(ternary),
83
83
  group,
84
84
  variables,
85
85
  ]);