def compile_matchers(formatcode):
matchers = {}<EOL>for node_type in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>if node_type == "<STR_LIT>" or node_type == "<STR_LIT>":<EOL><INDENT>container1 = NW_FORMAT[formatcode][<NUM_LIT:0>][<NUM_LIT:0>]<EOL>container2 = NW_FORMAT[formatcode][<NUM_LIT:1>][<NUM_LIT:0>]<EOL>converterFn1 = NW_FORMAT[formatcode][<NUM_LIT:0>][<NUM_LIT:1>]<EOL>converterFn2 = NW_FORMAT[formatcode][<NUM_LIT:1>][<NUM_LIT:1>]<EOL>flexible1 = NW_FORMAT[formatcode][<NUM_LIT:0>][<NUM_LIT:2>]<EOL>flexible2 = NW_FORMAT[formatcode][<NUM_LIT:1>][<NUM_LIT:2>]<EOL><DEDENT>else:<EOL><INDENT>container1 = NW_FORMAT[formatcode][<NUM_LIT:2>][<NUM_LIT:0>]<EOL>container2 = NW_FORMAT[formatcode][<NUM_LIT:3>][<NUM_LIT:0>]<EOL>converterFn1 = NW_FORMAT[formatcode][<NUM_LIT:2>][<NUM_LIT:1>]<EOL>converterFn2 = NW_FORMAT[formatcode][<NUM_LIT:3>][<NUM_LIT:1>]<EOL>flexible1 = NW_FORMAT[formatcode][<NUM_LIT:2>][<NUM_LIT:2>]<EOL>flexible2 = NW_FORMAT[formatcode][<NUM_LIT:3>][<NUM_LIT:2>]<EOL><DEDENT>if converterFn1 == str:<EOL><INDENT>FIRST_MATCH = "<STR_LIT:(>"+_NAME_RE+"<STR_LIT:)>"<EOL><DEDENT>elif converterFn1 == float:<EOL><INDENT>FIRST_MATCH = "<STR_LIT:(>"+_FLOAT_RE+"<STR_LIT:)>"<EOL><DEDENT>elif converterFn1 is None:<EOL><INDENT>FIRST_MATCH = '<STR_LIT>'<EOL><DEDENT>if converterFn2 == str:<EOL><INDENT>SECOND_MATCH = "<STR_LIT>"+_NAME_RE+"<STR_LIT:)>"<EOL><DEDENT>elif converterFn2 == float:<EOL><INDENT>SECOND_MATCH = "<STR_LIT>"+_FLOAT_RE+"<STR_LIT:)>"<EOL><DEDENT>elif converterFn2 is None:<EOL><INDENT>SECOND_MATCH = '<STR_LIT>'<EOL><DEDENT>if flexible1 and node_type != '<STR_LIT>':<EOL><INDENT>FIRST_MATCH += "<STR_LIT:?>"<EOL><DEDENT>if flexible2:<EOL><INDENT>SECOND_MATCH += "<STR_LIT:?>"<EOL><DEDENT>matcher_str= '<STR_LIT>' % (FIRST_MATCH, SECOND_MATCH, _NHX_RE)<EOL>compiled_matcher = re.compile(matcher_str)<EOL>matchers[node_type] = [container1, container2, converterFn1, converterFn2, compiled_matcher]<EOL><DEDENT>return matchers<EOL>
Tests newick string against format types? and makes a re.compile