clarity-pattern-parser 3.0.7 → 3.0.9

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 (62) hide show
  1. package/dist/Cursor.js +105 -0
  2. package/dist/Cursor.js.map +1 -0
  3. package/dist/CursorHistory.js +104 -0
  4. package/dist/CursorHistory.js.map +1 -0
  5. package/dist/Permutor.js +52 -0
  6. package/dist/Permutor.js.map +1 -0
  7. package/dist/TextSuggester.js +223 -0
  8. package/dist/TextSuggester.js.map +1 -0
  9. package/dist/ast/CompositeNode.js +17 -0
  10. package/dist/ast/CompositeNode.js.map +1 -0
  11. package/dist/ast/Node.js +16 -0
  12. package/dist/ast/Node.js.map +1 -0
  13. package/dist/ast/ValueNode.js +14 -0
  14. package/dist/ast/ValueNode.js.map +1 -0
  15. package/dist/ast/Visitor.d.ts +2 -2
  16. package/dist/ast/Visitor.js +209 -0
  17. package/dist/ast/Visitor.js.map +1 -0
  18. package/dist/index.browser.js +38 -32
  19. package/dist/index.browser.js.map +1 -1
  20. package/dist/index.esm.js +38 -32
  21. package/dist/index.esm.js.map +1 -1
  22. package/dist/index.js +38 -32
  23. package/dist/index.js.map +1 -1
  24. package/dist/patterns/ParseError.js +9 -0
  25. package/dist/patterns/ParseError.js.map +1 -0
  26. package/dist/patterns/Pattern.js +127 -0
  27. package/dist/patterns/Pattern.js.map +1 -0
  28. package/dist/patterns/RecursivePattern.js +65 -0
  29. package/dist/patterns/RecursivePattern.js.map +1 -0
  30. package/dist/patterns/composite/AndComposite.js +117 -0
  31. package/dist/patterns/composite/AndComposite.js.map +1 -0
  32. package/dist/patterns/composite/CompositePattern.js +7 -0
  33. package/dist/patterns/composite/CompositePattern.js.map +1 -0
  34. package/dist/patterns/composite/OptionalComposite.js +29 -0
  35. package/dist/patterns/composite/OptionalComposite.js.map +1 -0
  36. package/dist/patterns/composite/OrComposite.js +69 -0
  37. package/dist/patterns/composite/OrComposite.js.map +1 -0
  38. package/dist/patterns/composite/RepeatComposite.js +83 -0
  39. package/dist/patterns/composite/RepeatComposite.js.map +1 -0
  40. package/dist/patterns/value/AndValue.js +118 -0
  41. package/dist/patterns/value/AndValue.js.map +1 -0
  42. package/dist/patterns/value/AnyOfThese.js +59 -0
  43. package/dist/patterns/value/AnyOfThese.js.map +1 -0
  44. package/dist/patterns/value/Literal.js +63 -0
  45. package/dist/patterns/value/Literal.js.map +1 -0
  46. package/dist/patterns/value/NotValue.js +70 -0
  47. package/dist/patterns/value/NotValue.js.map +1 -0
  48. package/dist/patterns/value/OptionalValue.js +32 -0
  49. package/dist/patterns/value/OptionalValue.js.map +1 -0
  50. package/dist/patterns/value/OrValue.js +73 -0
  51. package/dist/patterns/value/OrValue.js.map +1 -0
  52. package/dist/patterns/value/RegexValue.js +69 -0
  53. package/dist/patterns/value/RegexValue.js.map +1 -0
  54. package/dist/patterns/value/RepeatValue.js +84 -0
  55. package/dist/patterns/value/RepeatValue.js.map +1 -0
  56. package/dist/patterns/value/ValuePattern.js +7 -0
  57. package/dist/patterns/value/ValuePattern.js.map +1 -0
  58. package/package.json +1 -1
  59. package/src/TextSuggester.ts +15 -7
  60. package/src/ast/Visitor.ts +40 -40
  61. package/src/tests/TextSuggester.test.ts +15 -0
  62. package/src/tests/javascriptPatterns/json.ts +1 -0
package/dist/index.esm.js CHANGED
@@ -1426,22 +1426,28 @@ class TextSuggester {
1426
1426
  }
1427
1427
  if (((_c = this.patternMatch) === null || _c === void 0 ? void 0 : _c.astNode) == null) {
1428
1428
  let options = (_d = this.rootPattern) === null || _d === void 0 ? void 0 : _d.getTokens();
1429
- const parts = this.text.split(" ").filter((part) => {
1430
- return part.length > 0;
1431
- });
1432
1429
  options = options === null || options === void 0 ? void 0 : options.filter((option) => {
1433
- return parts.some((part) => {
1434
- return option.indexOf(part) > -1;
1435
- });
1430
+ return option.indexOf(this.text) > -1;
1436
1431
  });
1437
1432
  if ((options === null || options === void 0 ? void 0 : options.length) === 0) {
1438
1433
  this.tokens = null;
1439
1434
  return;
1440
1435
  }
1436
+ const values = options === null || options === void 0 ? void 0 : options.map((option) => {
1437
+ const parts = option.split(this.text);
1438
+ return parts[1];
1439
+ });
1441
1440
  this.tokens = {
1442
1441
  startIndex: 0,
1443
- values: options || [],
1442
+ values: values || [],
1444
1443
  };
1444
+ this.matchedText = this.text;
1445
+ this.match = {
1446
+ text: this.text,
1447
+ startIndex: 0,
1448
+ endIndex: this.text.length - 1,
1449
+ };
1450
+ this.error = null;
1445
1451
  return;
1446
1452
  }
1447
1453
  const options = this.options;
@@ -1518,7 +1524,7 @@ class Visitor {
1518
1524
  this.selectedNodes.forEach((node) => {
1519
1525
  if (node.isComposite) {
1520
1526
  const children = [];
1521
- this.walkUp(node, (descendant) => {
1527
+ Visitor.walkUp(node, (descendant) => {
1522
1528
  if (!descendant.isComposite) {
1523
1529
  children.push(descendant);
1524
1530
  }
@@ -1563,7 +1569,7 @@ class Visitor {
1563
1569
  if (this.root == null) {
1564
1570
  return this;
1565
1571
  }
1566
- this.walkDown(this.root, (node, stack) => {
1572
+ Visitor.walkDown(this.root, (node, stack) => {
1567
1573
  if (this.selectedNodes.includes(node)) {
1568
1574
  const parent = stack[stack.length - 1];
1569
1575
  const grandParent = stack[stack.length - 2];
@@ -1581,7 +1587,7 @@ class Visitor {
1581
1587
  if (this.root == null) {
1582
1588
  return this;
1583
1589
  }
1584
- this.walkUp(this.root, (node, stack) => {
1590
+ Visitor.walkUp(this.root, (node, stack) => {
1585
1591
  if (this.selectedNodes.includes(node)) {
1586
1592
  const parent = stack[stack.length - 1];
1587
1593
  if (parent != null) {
@@ -1598,7 +1604,7 @@ class Visitor {
1598
1604
  if (this.root == null) {
1599
1605
  return this;
1600
1606
  }
1601
- this.walkDown(this.root, (node, stack) => {
1607
+ Visitor.walkDown(this.root, (node, stack) => {
1602
1608
  if (this.selectedNodes.includes(node)) {
1603
1609
  const parent = stack[stack.length - 1];
1604
1610
  if (parent != null) {
@@ -1626,26 +1632,6 @@ class Visitor {
1626
1632
  }
1627
1633
  return callback(node);
1628
1634
  }
1629
- walkUp(node, callback, ancestors = []) {
1630
- ancestors.push(node);
1631
- if (node.isComposite && Array.isArray(node.children)) {
1632
- const children = node.children.slice();
1633
- children.forEach((c) => this.walkUp(c, callback, ancestors));
1634
- }
1635
- ancestors.pop();
1636
- callback(node, ancestors);
1637
- return this;
1638
- }
1639
- walkDown(node, callback, ancestors = []) {
1640
- callback(node, ancestors);
1641
- ancestors.push(node);
1642
- if (node.isComposite && Array.isArray(node.children)) {
1643
- const children = node.children.slice();
1644
- children.forEach((c) => this.walkDown(c, callback, ancestors));
1645
- }
1646
- ancestors.pop();
1647
- return this;
1648
- }
1649
1635
  selectAll() {
1650
1636
  return this.select((n) => true);
1651
1637
  }
@@ -1663,7 +1649,7 @@ class Visitor {
1663
1649
  const node = this.root;
1664
1650
  const selectedNodes = [];
1665
1651
  if (node.isComposite) {
1666
- this.walkDown(node, (descendant) => {
1652
+ Visitor.walkDown(node, (descendant) => {
1667
1653
  if (callback(descendant)) {
1668
1654
  selectedNodes.push(descendant);
1669
1655
  }
@@ -1716,6 +1702,26 @@ class Visitor {
1716
1702
  return new Visitor(root);
1717
1703
  }
1718
1704
  }
1705
+ static walkUp(node, callback, ancestors = []) {
1706
+ ancestors.push(node);
1707
+ if (node.isComposite && Array.isArray(node.children)) {
1708
+ const children = node.children.slice();
1709
+ children.forEach((c) => this.walkUp(c, callback, ancestors));
1710
+ }
1711
+ ancestors.pop();
1712
+ callback(node, ancestors);
1713
+ return this;
1714
+ }
1715
+ static walkDown(node, callback, ancestors = []) {
1716
+ callback(node, ancestors);
1717
+ ancestors.push(node);
1718
+ if (node.isComposite && Array.isArray(node.children)) {
1719
+ const children = node.children.slice();
1720
+ children.forEach((c) => this.walkDown(c, callback, ancestors));
1721
+ }
1722
+ ancestors.pop();
1723
+ return this;
1724
+ }
1719
1725
  }
1720
1726
 
1721
1727
  export { AndComposite, AndValue, AnyOfThese, CompositeNode, CompositePattern, Cursor, Literal, Node, NotValue, OptionalComposite, OptionalValue, OrComposite, OrValue, ParseError, Pattern, RecursivePattern, RegexValue, RepeatComposite, RepeatValue, TextSuggester, ValueNode, ValuePattern, Visitor };