MCPcopy
hub / github.com/psf/black / generate_matches

Function generate_matches

src/blib2to3/pytree.py:943–970  ·  view source on GitHub ↗

Generator yielding matches for a sequence of patterns and nodes. Args: patterns: a sequence of patterns nodes: a sequence of nodes Yields: (count, results) tuples where: count: the entire sequence of patterns matches nodes[:count]; results: dict

(
    patterns: list[BasePattern], nodes: list[NL]
)

Source from the content-addressed store, hash-verified

941
942
943def generate_matches(
944 patterns: list[BasePattern], nodes: list[NL]
945) -> Iterator[tuple[int, _Results]]:
946 """
947 Generator yielding matches for a sequence of patterns and nodes.
948
949 Args:
950 patterns: a sequence of patterns
951 nodes: a sequence of nodes
952
953 Yields:
954 (count, results) tuples where:
955 count: the entire sequence of patterns matches nodes[:count];
956 results: dict containing named submatches.
957 """
958 if not patterns:
959 yield 0, {}
960 else:
961 p, rest = patterns[0], patterns[1:]
962 for c0, r0 in p.generate_matches(nodes):
963 if not rest:
964 yield c0, r0
965 else:
966 for c1, r1 in generate_matches(rest, nodes[c0:]):
967 r = {}
968 r.update(r0)
969 r.update(r1)
970 yield c0 + c1, r

Callers 3

_submatchMethod · 0.85
_iterative_matchesMethod · 0.85
_recursive_matchesMethod · 0.85

Calls 1

generate_matchesMethod · 0.45

Tested by

no test coverage detected