Did I find the right examples for you? yes no

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)

        def lex(lex_table, str, debug=False):
    rule_dict = dict(lex_table)

    def matches_rule(rule, str, start):
        assert isinstance(rule, RE)
        match_obj = rule.RE.match(str, start)
        if match_obj:
            return match_obj.end()-start, match_obj
        else:
            return 0, None

    result = []
    i = 0
    while i < len(str):
        rule_matched = False
        for name, rule in lex_table:
            length, match_obj = matches_rule(rule, str, i)
            if length:
                result.append((name, str[i:i+length], i, match_obj))
                i += length
                rule_matched = True
                break
        if not rule_matched:
            raise InvalidTokenError(str, i)
    return result
        


src/s/y/synoptic-2013.1/synoptic/query.py   synoptic(Download)
 
 
    from synoptic.lex import LexIterator, lex
    pstate = LexIterator(
        [(tag, s, idx, matchobj)
         for (tag, s, idx, matchobj) in lex(_LEX_TABLE, expr_str)