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.js CHANGED
@@ -1430,22 +1430,28 @@ class TextSuggester {
1430
1430
  }
1431
1431
  if (((_c = this.patternMatch) === null || _c === void 0 ? void 0 : _c.astNode) == null) {
1432
1432
  let options = (_d = this.rootPattern) === null || _d === void 0 ? void 0 : _d.getTokens();
1433
- const parts = this.text.split(" ").filter((part) => {
1434
- return part.length > 0;
1435
- });
1436
1433
  options = options === null || options === void 0 ? void 0 : options.filter((option) => {
1437
- return parts.some((part) => {
1438
- return option.indexOf(part) > -1;
1439
- });
1434
+ return option.indexOf(this.text) > -1;
1440
1435
  });
1441
1436
  if ((options === null || options === void 0 ? void 0 : options.length) === 0) {
1442
1437
  this.tokens = null;
1443
1438
  return;
1444
1439
  }
1440
+ const values = options === null || options === void 0 ? void 0 : options.map((option) => {
1441
+ const parts = option.split(this.text);
1442
+ return parts[1];
1443
+ });
1445
1444
  this.tokens = {
1446
1445
  startIndex: 0,
1447
- values: options || [],
1446
+ values: values || [],
1448
1447
  };
1448
+ this.matchedText = this.text;
1449
+ this.match = {
1450
+ text: this.text,
1451
+ startIndex: 0,
1452
+ endIndex: this.text.length - 1,
1453
+ };
1454
+ this.error = null;
1449
1455
  return;
1450
1456
  }
1451
1457
  const options = this.options;
@@ -1522,7 +1528,7 @@ class Visitor {
1522
1528
  this.selectedNodes.forEach((node) => {
1523
1529
  if (node.isComposite) {
1524
1530
  const children = [];
1525
- this.walkUp(node, (descendant) => {
1531
+ Visitor.walkUp(node, (descendant) => {
1526
1532
  if (!descendant.isComposite) {
1527
1533
  children.push(descendant);
1528
1534
  }
@@ -1567,7 +1573,7 @@ class Visitor {
1567
1573
  if (this.root == null) {
1568
1574
  return this;
1569
1575
  }
1570
- this.walkDown(this.root, (node, stack) => {
1576
+ Visitor.walkDown(this.root, (node, stack) => {
1571
1577
  if (this.selectedNodes.includes(node)) {
1572
1578
  const parent = stack[stack.length - 1];
1573
1579
  const grandParent = stack[stack.length - 2];
@@ -1585,7 +1591,7 @@ class Visitor {
1585
1591
  if (this.root == null) {
1586
1592
  return this;
1587
1593
  }
1588
- this.walkUp(this.root, (node, stack) => {
1594
+ Visitor.walkUp(this.root, (node, stack) => {
1589
1595
  if (this.selectedNodes.includes(node)) {
1590
1596
  const parent = stack[stack.length - 1];
1591
1597
  if (parent != null) {
@@ -1602,7 +1608,7 @@ class Visitor {
1602
1608
  if (this.root == null) {
1603
1609
  return this;
1604
1610
  }
1605
- this.walkDown(this.root, (node, stack) => {
1611
+ Visitor.walkDown(this.root, (node, stack) => {
1606
1612
  if (this.selectedNodes.includes(node)) {
1607
1613
  const parent = stack[stack.length - 1];
1608
1614
  if (parent != null) {
@@ -1630,26 +1636,6 @@ class Visitor {
1630
1636
  }
1631
1637
  return callback(node);
1632
1638
  }
1633
- walkUp(node, callback, ancestors = []) {
1634
- ancestors.push(node);
1635
- if (node.isComposite && Array.isArray(node.children)) {
1636
- const children = node.children.slice();
1637
- children.forEach((c) => this.walkUp(c, callback, ancestors));
1638
- }
1639
- ancestors.pop();
1640
- callback(node, ancestors);
1641
- return this;
1642
- }
1643
- walkDown(node, callback, ancestors = []) {
1644
- callback(node, ancestors);
1645
- ancestors.push(node);
1646
- if (node.isComposite && Array.isArray(node.children)) {
1647
- const children = node.children.slice();
1648
- children.forEach((c) => this.walkDown(c, callback, ancestors));
1649
- }
1650
- ancestors.pop();
1651
- return this;
1652
- }
1653
1639
  selectAll() {
1654
1640
  return this.select((n) => true);
1655
1641
  }
@@ -1667,7 +1653,7 @@ class Visitor {
1667
1653
  const node = this.root;
1668
1654
  const selectedNodes = [];
1669
1655
  if (node.isComposite) {
1670
- this.walkDown(node, (descendant) => {
1656
+ Visitor.walkDown(node, (descendant) => {
1671
1657
  if (callback(descendant)) {
1672
1658
  selectedNodes.push(descendant);
1673
1659
  }
@@ -1720,6 +1706,26 @@ class Visitor {
1720
1706
  return new Visitor(root);
1721
1707
  }
1722
1708
  }
1709
+ static walkUp(node, callback, ancestors = []) {
1710
+ ancestors.push(node);
1711
+ if (node.isComposite && Array.isArray(node.children)) {
1712
+ const children = node.children.slice();
1713
+ children.forEach((c) => this.walkUp(c, callback, ancestors));
1714
+ }
1715
+ ancestors.pop();
1716
+ callback(node, ancestors);
1717
+ return this;
1718
+ }
1719
+ static walkDown(node, callback, ancestors = []) {
1720
+ callback(node, ancestors);
1721
+ ancestors.push(node);
1722
+ if (node.isComposite && Array.isArray(node.children)) {
1723
+ const children = node.children.slice();
1724
+ children.forEach((c) => this.walkDown(c, callback, ancestors));
1725
+ }
1726
+ ancestors.pop();
1727
+ return this;
1728
+ }
1723
1729
  }
1724
1730
 
1725
1731
  exports.AndComposite = AndComposite;