Helper to iteratively yield the matches.
190842
def _iterative_matches(self, nodes):
        """"""
        nodelen = len(nodes)
        if 0 >= self.min:
            yield 0, {}

        results = []
        # generate matches that use just one alt from self.content
        for alt in self.content:
            for c, r in generate_matches(alt, nodes):
                yield c, r
                results.append((c, r))

        # for each match, iterate down the nodes
        while results:
            new_results = []
            for c0, r0 in results:
                # stop if the entire set of nodes has been matched
                if c0 < nodelen and c0 <= self.max:
                    for alt in self.content:
                        for c1, r1 in generate_matches(alt, nodes[c0:]):
                            if c1 > 0:
                                r = {}
                                r.update(r0)
                                r.update(r1)
                                yield c0 + c1, r
                                new_results.append((c0 + c1, r))
            results = new_results
1270400
def _build_matches(matches, uuids, no_filtered, fastmode=False):
    """"""

    result = []

    for m in matches:
        mk = m[0].uuid if not fastmode else m[0]
        subset = [uuids[mk]]

        for id_ in m[1:]:
            uk = id_.uuid if not fastmode else id_
            u = uuids[uk]

            if u not in subset:
                subset.append(u)

        result.append(subset)

    result += no_filtered
    result.sort(key=len, reverse=True)

    sresult = []
    for r in result:
        r.sort(key=lambda id_: id_.uuid)
        sresult.append(r)

    return sresult
764317
def matchesWithMatchers(self, event):
        '''
        
        '''
        ret = []
        self._matches(event, set(), ret)
        return tuple(ret)
1327758
def each
      (1..ROWS).each do |r|
        (1..COLS).each do |c|
          yield(r, c, self[r, c])
        end
      end
    end
1071568
def convert_to_match_query(ir_blocks):
    """"""
    output_block = ir_blocks[-1]
    if not isinstance(output_block, ConstructResult):
        raise AssertionError(u'Expected last IR block to be ConstructResult, found: '
                             u'{} {}'.format(output_block, ir_blocks))
    ir_except_output = ir_blocks[:-1]

    folds, ir_except_output_and_folds = extract_folds_from_ir_blocks(ir_except_output)

    # Extract WHERE Filter
    global_operation_ir_blocks_tuple = _extract_global_operations(ir_except_output_and_folds)
    global_operation_blocks, pruned_ir_blocks = global_operation_ir_blocks_tuple
    if len(global_operation_blocks) > 1:
        raise AssertionError(u'Received IR blocks with multiple global operation blocks. Only one '
                             u'is allowed: {} {}'.format(global_operation_blocks, ir_blocks))
    if len(global_operation_blocks) == 1:
        if not isinstance(global_operation_blocks[0], Filter):
            raise AssertionError(u'Received non-Filter global operation block. {}'
                                 .format(global_operation_blocks[0]))
        where_block = global_operation_blocks[0]
    else:
        where_block = None

    match_steps = _split_ir_into_match_steps(pruned_ir_blocks)

    match_traversals = _split_match_steps_into_match_traversals(match_steps)

    return MatchQuery(
        match_traversals=match_traversals,
        folds=folds,
        output_block=output_block,
        where_block=where_block,
    )
1109620
def _match(self):
        """"""
        #disable optimized matching
        optimized_rows = None
        optimized_columns = None
        for match in self.__match_rows(optimized_rows):
            #match in rows
            yield match
        for match in self.__match_rows(optimized_columns,
                                       transpose=True):
            #match in columns and transpose coordinates
            yield match
34752
def join(iterable, sep):
    """"""
    i = 0
    for i, item in enumerate(iterable):
        if i == 0:
            yield item
        else:
            yield sep
            yield item
393600
def exclude_matches(self, matches):
        
        for match in matches:
            for exclude_pattern in self.exclude_patterns:
                if re.match(exclude_pattern, match) is not None:
                    break
            else:
                yield match
880829
function SingleMatcherIterator(i, node, match) {
  this.i = i;
  this.n = node;
  this.m = match;
  this.f = true;
}
912203
def match_seq(self, nodes, results=None):
        """"""
        for c, r in self.generate_matches(nodes):
            if c == len(nodes):
                if results is not None:
                    results.update(r)
                    if self.name:
                        results[self.name] = list(nodes)
                return True
        return False
1298882
def iter_up(self, include_self=True):
        """"""
        if include_self: yield self
        parent = self.parent
        while parent is not None:
            yield parent
            try:
                parent = parent.parent
            except AttributeError:
                return
202878
def load_matches(self):
        
        if not self.exists():
            return []

        matches = []
        with open(self.location(), 'r') as f:
            for line in f.readlines():
                match_obj = json.loads(line.strip("\n"))
                if match_obj['processed']:
                    continue

                matches.append(match_obj)

        return matches
776046
def ibatch(iterable, size):
    """"""
    source = iter(iterable)
    while True:
        batch = itertools.islice(source, size)
        yield itertools.chain([next(batch)], batch)
1298035
def iter_lines(file_like: Iterable[str]) -> Generator[str, None, None]:
    
    for line in file_like:
        line = line.rstrip('\r\n')
        if line:
            yield line
1345458
def match_tokens(expected_tokens):
    """"""
    if isinstance(expected_tokens, Token):
        # Match a single token.
        def _grammar_func(tokens):
            try:
                next_token = next(iter(tokens))
            except StopIteration:
                return

            if next_token == expected_tokens:
                return TokenMatch(None, next_token.value, (next_token,))

    elif isinstance(expected_tokens, tuple):
        # Match multiple tokens.
        match_len = len(expected_tokens)
        def _grammar_func(tokens):
            upcoming = tuple(itertools.islice(tokens, match_len))
            if upcoming == expected_tokens:
                return TokenMatch(None, None, upcoming)
    else:
        raise TypeError(
            "'expected_tokens' must be an instance of Token or a tuple "
            "thereof. Got %r." % expected_tokens)

    return _grammar_func
926767
def gather(self, iterable):
        
        for result in self.lookup(iterable, gather=True):
            yield result
639999
def match_paren(self, tokens, item):
        """"""
        match, = tokens
        return self.match(match, item)