def GlobToERE(pat): # type: (str) -> Tuple[str, List[str]] lexer = match.GlobLexer(pat) p = _GlobParser(lexer) parts, warnings = p.Parse() # Vestigial: if there is nothing like * ? or [abc], then the whole string is # a literal, and we could use a more efficient mechanism. # But we would have to DEQUOTE before doing that. if 0: is_glob = False for p in parts: if p.tag in (glob_part_e.Operator, glob_part_e.CharClass): is_glob = True if 0: print('---') for p in parts: print(p) regex = _GenerateERE(parts) return regex, warnings
def _ReadTokens(s): lex = match.GlobLexer(s) return list(lex.Tokens())