Match the pattern's content to the node's children. This assumes the node type matches and self.content is not None. Returns True if it matches, False if not. If results is not None, it must be a dict which will be updated with the nodes matching named sub
(self, node, results=None)
| 670 | self.name = name |
| 671 | |
| 672 | def _submatch(self, node, results=None) -> bool: |
| 673 | """ |
| 674 | Match the pattern's content to the node's children. |
| 675 | |
| 676 | This assumes the node type matches and self.content is not None. |
| 677 | |
| 678 | Returns True if it matches, False if not. |
| 679 | |
| 680 | If results is not None, it must be a dict which will be |
| 681 | updated with the nodes matching named subpatterns. |
| 682 | |
| 683 | When returning False, the results dict may still be updated. |
| 684 | """ |
| 685 | if self.wildcards: |
| 686 | for c, r in generate_matches(self.content, node.children): |
| 687 | if c == len(node.children): |
| 688 | if results is not None: |
| 689 | results.update(r) |
| 690 | return True |
| 691 | return False |
| 692 | if len(self.content) != len(node.children): |
| 693 | return False |
| 694 | for subpattern, child in zip(self.content, node.children): |
| 695 | if not subpattern.match(child, results): |
| 696 | return False |
| 697 | return True |
| 698 | |
| 699 | |
| 700 | class WildcardPattern(BasePattern): |
nothing calls this directly
no test coverage detected