def convert_in(group_names, name, terms): negate = (terms[0][0] == 'negate') s = "" for c in terms[negate:]: if c[0] == 'literal': s = s + chr(c[1]) elif c[0] == 'range': for i in range(c[1][0], c[1][1] + 1): s = s + chr(i) elif c[0] == 'category': s = s + categories[c[1]] else: raise AssertionError("unknown option for 'in': %s" % c[0]) return Expression.Any(s, negate)
def AnyBut(s): """s -> match any character not in s""" return Expression.Any(s, 1)
def Any(s): """(s) -> match any character in s""" if len(s) == 1: return Expression.Literal(s) return Expression.Any(s, 0)