def _read_newick_from_string(nw, root_node, matcher, formatcode):
if nw.count('<STR_LIT:(>') != nw.count('<STR_LIT:)>'):<EOL><INDENT>raise NewickError('<STR_LIT>')<EOL><DEDENT>nw = re.sub("<STR_LIT>", "<STR_LIT>", nw)<EOL>current_parent = None<EOL>for chunk in nw.split("<STR_LIT:(>")[<NUM_LIT:1>:]:<EOL><INDENT>current_parent = root_node if current_parent is None else current_parent.add_child()<EOL>subchunks = [ch.strip() for ch in chunk.split("<STR_LIT:U+002C>")]<EOL>if subchunks[-<NUM_LIT:1>] != '<STR_LIT>' and not subchunks[-<NUM_LIT:1>].endswith('<STR_LIT:;>'):<EOL><INDENT>raise NewickError('<STR_LIT>' %chunk)<EOL><DEDENT>for i, leaf in enumerate(subchunks):<EOL><INDENT>if leaf.strip() == '<STR_LIT>' and i == len(subchunks) - <NUM_LIT:1>:<EOL><INDENT>continue <EOL><DEDENT>closing_nodes = leaf.split("<STR_LIT:)>")<EOL>_read_node_data(closing_nodes[<NUM_LIT:0>], current_parent, "<STR_LIT>", matcher, formatcode)<EOL>if len(closing_nodes)><NUM_LIT:1>:<EOL><INDENT>for closing_internal in closing_nodes[<NUM_LIT:1>:]:<EOL><INDENT>closing_internal =  closing_internal.rstrip("<STR_LIT:;>")<EOL>_read_node_data(closing_internal, current_parent, "<STR_LIT>", matcher, formatcode)<EOL>current_parent = current_parent.up<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return root_node<EOL>
Reads a newick string in the New Hampshire format.