attrs = {} else: attrs = cgi.parse_qs(pattern_name[pos + 1:], keep_blank_values=1, strict_parsing=1) pattern_name = pattern_name[:pos] for k, v in attrs.items(): if len(v) != 1: raise AssertionError( "The attribute name %s was found more than once (%d times) in the tag %s" % (repr(k), len(v), repr(pattern_name))) attrs[k] = v[0] return Expression.Group(pattern_name, convert_list(group_names, terms), attrs) # Convert a 'newline' tuple into an AnyEol object def convert_newline(group_names, name, ignore): assert ignore is None, "what does it mean when field is %s?" % ` ignore ` return Expression.AnyEol() # Convert a 'max_repeat' tuple into a MaxRepeat object def convert_max_repeat(group_names, name, (min_count, max_count, terms)): return Expression.MaxRepeat(convert_list(group_names, terms), min_count, max_count) # Convert a 'groupref' tuple into a GroupRef object
def Group(name, expr, attrs=None): """name, expr -> use 'name' to describe a successful match of the expression""" assert isinstance(expr, Expression.Expression), \ "expecting an Expression, not a %s" % type(expr) return Expression.Group(name, expr, attrs)