<s> from parsimonious . grammar import Grammar <EOL> from . . import html_paths <EOL> def read_html_path ( string ) : <EOL> path_node = _grammar . parse ( string ) <EOL> return read_html_path_node ( path_node ) <EOL> def read_html_path_node ( path_node ) : <EOL> if path_node . children : <EOL> return _read_html_path_elements_node ( path_node . children [ <NUM_LIT:0> ] ) <EOL> else : <EOL> return html_paths . empty <EOL> def _read_html_path_elements_node ( path_node ) : <EOL> elements = [ <EOL> _read_element_node ( child ) <EOL> for child in _repeated_children_with_separator ( path_node , has_whitespace = True ) <EOL> ] <EOL> return html_paths . path ( elements ) <EOL> def _read_element_node ( node ) : <EOL> tag_names = _read_tag_names_node ( node . children [ <NUM_LIT:0> ] ) <EOL> class_names = _read_class_names_node ( node . children [ <NUM_LIT:1> ] ) <EOL> fresh = _read_fresh_node ( node . children [ <NUM_LIT:2> ] ) <EOL> return html_paths . element ( tag_names , class_names = class_names , fresh = fresh ) <EOL> def _read_tag_names_node ( node ) : <EOL> return [ <EOL> child . text <EOL> for child in _repeated_children_with_separator ( node , has_whitespace = False ) <EOL> ] <EOL> def _read_class_names_node ( class_names_node ) : <EOL> return [ <EOL> _read_class_name_node ( node ) <EOL> for node in class_names_node . children <EOL> ] <EOL> def _read_class_name_node ( node ) : <EOL> return node . children [ <NUM_LIT:1> ] . text <EOL> def _read_fresh_node ( node ) : <EOL> return len ( node . children ) > <NUM_LIT:0> <EOL> def _repeated_children_with_separator ( node , has_whitespace ) : <EOL> yield node . children [ <NUM_LIT:0> ] <EOL> if has_whitespace : <EOL> sequence_node_index = <NUM_LIT:3> <EOL> else : <EOL> sequence_node_index = <NUM_LIT:1> <EOL> sequence_node = node . children [ <NUM_LIT:1> ] <EOL> for child in sequence_node . children : <EOL> yield child . children [ sequence_node_index ] <EOL> grammar_text = r"""<STR_LIT>""" <EOL> _grammar = Grammar ( grammar_text ) </s>
