@staticmethod<EOL><INDENT>def format_spec_to_regex(field_name, format_spec):<DEDENT>
<EOL>regex_match = fmt_spec_regex.match(format_spec.replace('<STR_LIT:\\>', '<STR_LIT>'))<EOL>if regex_match is None:<EOL><INDENT>raise ValueError("<STR_LIT>".format(format_spec))<EOL><DEDENT>regex_dict = regex_match.groupdict()<EOL>fill = regex_dict['<STR_LIT>']<EOL>ftype = regex_dict['<STR_LIT:type>']<EOL>width = regex_dict['<STR_LIT:width>']<EOL>align = regex_dict['<STR_LIT>']<EOL>if fill is None:<EOL><INDENT>if width is not None and width[<NUM_LIT:0>] == '<STR_LIT:0>':<EOL><INDENT>fill = '<STR_LIT:0>'<EOL><DEDENT>elif ftype in ['<STR_LIT:s>', '<STR_LIT:d>']:<EOL><INDENT>fill = '<STR_LIT:U+0020>'<EOL><DEDENT><DEDENT>char_type = spec_regexes[ftype]<EOL>if ftype == '<STR_LIT:s>' and align and align.endswith('<STR_LIT:=>'):<EOL><INDENT>raise ValueError("<STR_LIT>".format(format_spec))<EOL><DEDENT>final_regex = char_type<EOL>if ftype in allow_multiple and (not width or width == '<STR_LIT:0>'):<EOL><INDENT>final_regex += r'<STR_LIT:*>'<EOL><DEDENT>elif width and width != '<STR_LIT:0>':<EOL><INDENT>if not fill:<EOL><INDENT>final_regex += r'<STR_LIT>'.format(int(width))<EOL><DEDENT>elif fill:<EOL><INDENT>final_regex = r'<STR_LIT>'.format(int(width))<EOL><DEDENT>elif ftype in allow_multiple:<EOL><INDENT>final_regex += r'<STR_LIT:*>'<EOL><DEDENT><DEDENT>return r'<STR_LIT>'.format(field_name, final_regex)<EOL>
Make an attempt at converting a format spec to a regular expression.