<s> '''<STR_LIT>''' <EOL> import re <EOL> from time import clock <EOL> class GrammarParser ( ) : <EOL> def __init__ ( self , grammar , printer = None ) : <EOL> self . grammar = grammar <EOL> self . printer = None <EOL> if printer is not None : <EOL> self . printer = printer <EOL> self . re_cache = { } <EOL> self . regions = [ ] <EOL> self . data = None <EOL> self . unused_rules = [ ] <EOL> self . unexists_rules = [ ] <EOL> def contain_rule ( self , rule_name ) : <EOL> return "<STR_LIT>" in self . grammar and rule_name in self . grammar [ "<STR_LIT>" ] <EOL> def validate_rule_list ( self , rules ) : <EOL> for rule in rules : <EOL> self . validate_rule ( rule ) <EOL> def validate_rule ( self , rule ) : <EOL> if "<STR_LIT>" in rule : <EOL> self . validate_rule ( rule [ "<STR_LIT>" ] ) <EOL> if "<STR_LIT>" in rule : <EOL> self . validate_rule_list ( rule [ "<STR_LIT>" ] ) <EOL> if "<STR_LIT>" in rule : <EOL> self . validate_rule_list ( rule [ "<STR_LIT>" ] ) <EOL> if "<STR_LIT>" in rule : <EOL> if not self . contain_rule ( rule [ "<STR_LIT>" ] ) and rule [ "<STR_LIT>" ] not in self . unexists_rules : <EOL> self . unexists_rules . append ( rule [ "<STR_LIT>" ] ) <EOL> else : <EOL> if rule [ "<STR_LIT>" ] in self . unused_rules : <EOL> while rule [ "<STR_LIT>" ] in self . unused_rules : <EOL> self . unused_rules . remove ( rule [ "<STR_LIT>" ] ) <EOL> self . validate_rule ( self . grammar [ "<STR_LIT>" ] [ rule [ "<STR_LIT>" ] ] ) <EOL> def validate_grammar ( self , first = True ) : <EOL> if first : <EOL> self . unexists_rules = [ ] <EOL> self . unused_rules = [ ] <EOL> if "<STR_LIT>" in self . grammar : <EOL> for rule_name in self . grammar [ "<STR_LIT>" ] : <EOL> self . unused_rules . append ( rule_name ) <EOL> if "<STR_LIT>" in self . grammar : <EOL> self . validate_rule ( self . grammar [ "<STR_LIT>" ] ) <EOL> if "<STR_LIT>" in self . grammar : <EOL> self . validate_rule ( self . grammar [ "<STR_LIT>" ] ) <EOL> self . unexists_rules . sort ( ) <EOL> self . unused_rules . sort ( ) <EOL> return { "<STR_LIT>" : self . unused_rules , "<STR_LIT>" : self . unexists_rules } <EOL> def parse_grammar ( self , data ) : <EOL> if self . data is None or self . data != data : <EOL> self . data = data <EOL> self . regions = [ ] <EOL> else : <EOL> if self . printer is not None : <EOL> self . printer ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> return True <EOL> starttime = clock ( ) <EOL> if "<STR_LIT>" in self . grammar : <EOL> if self . printer is not None : <EOL> self . printer ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> begin = <NUM_LIT:0> <EOL> if ( "<STR_LIT>" not in self . grammar [ "<STR_LIT>" ] or self . grammar [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) : <EOL> separator_output = self . parse_rule ( self . grammar [ "<STR_LIT>" ] , True , "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> if separator_output [ "<STR_LIT>" ] : <EOL> begin = separator_output [ "<STR_LIT:end>" ] <EOL> self . regions += separator_output [ "<STR_LIT>" ] <EOL> parse_output = self . parse_rule ( self . grammar [ "<STR_LIT>" ] , False , "<STR_LIT>" , <NUM_LIT:0> , begin ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> self . regions += parse_output [ "<STR_LIT>" ] <EOL> if ( "<STR_LIT>" not in self . grammar [ "<STR_LIT>" ] or self . grammar [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) : <EOL> separator_output = self . parse_rule ( self . grammar [ "<STR_LIT>" ] , True , "<STR_LIT>" , <NUM_LIT:0> , parse_output [ "<STR_LIT:end>" ] ) <EOL> if separator_output [ "<STR_LIT>" ] : <EOL> parse_output [ "<STR_LIT:end>" ] = separator_output [ "<STR_LIT:end>" ] <EOL> self . regions += separator_output [ "<STR_LIT>" ] <EOL> self . elapse_time = clock ( ) - starttime <EOL> return { "<STR_LIT:success>" : parse_output [ "<STR_LIT>" ] , "<STR_LIT>" : parse_output [ "<STR_LIT>" ] , "<STR_LIT:end>" : parse_output [ "<STR_LIT:end>" ] } <EOL> def parse_rule_list ( self , rules , is_separator , parent , level , begin ) : <EOL> regions = [ ] <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( len ( rules ) ) + "<STR_LIT>" ) <EOL> index = <NUM_LIT:0> <EOL> root_begin = None <EOL> for rule in rules : <EOL> index += <NUM_LIT:1> <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( index ) + "<STR_LIT:/>" + str ( len ( rules ) ) + "<STR_LIT>" + str ( begin ) ) <EOL> parse_output = self . parse_rule ( rule , is_separator , parent , level + <NUM_LIT:1> , begin ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> if root_begin is None : <EOL> root_begin = parse_output [ "<STR_LIT>" ] <EOL> begin = parse_output [ "<STR_LIT>" ] <EOL> regions += parse_output [ "<STR_LIT>" ] <EOL> else : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" ) <EOL> break <EOL> if root_begin is None : <EOL> root_begin = begin <EOL> parse_output [ "<STR_LIT>" ] = root_begin <EOL> parse_output [ "<STR_LIT>" ] = regions <EOL> return parse_output <EOL> def parse_rule_list_any ( self , rules , is_separator , parent , level , begin ) : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( len ( rules ) ) + "<STR_LIT>" ) <EOL> index = <NUM_LIT:0> <EOL> for rule in rules : <EOL> index += <NUM_LIT:1> <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( index ) + "<STR_LIT:/>" + str ( len ( rules ) ) + "<STR_LIT>" + str ( begin ) ) <EOL> parse_output = self . parse_rule ( rule , is_separator , parent , level + <NUM_LIT:1> , begin ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" ) <EOL> return parse_output <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" ) <EOL> return parse_output <EOL> def parse_rule ( self , rule , is_separator , parent , level , begin ) : <EOL> regions = [ ] <EOL> if self . printer is not None and not is_separator : <EOL> if "<STR_LIT:name>" in rule : <EOL> self . printer ( level , "<STR_LIT>" + rule [ "<STR_LIT:name>" ] + "<STR_LIT>" + str ( begin ) + "<STR_LIT>" ) <EOL> else : <EOL> self . printer ( level , "<STR_LIT>" + str ( begin ) + "<STR_LIT>" ) <EOL> rule_output = { "<STR_LIT>" : False , "<STR_LIT>" : False , "<STR_LIT>" : begin , "<STR_LIT>" : begin , "<STR_LIT:end>" : begin , "<STR_LIT>" : [ ] } <EOL> if "<STR_LIT:name>" in rule : <EOL> if parent != "<STR_LIT>" : <EOL> parent += "<STR_LIT:>>" <EOL> parent += rule [ "<STR_LIT:name>" ] <EOL> good = True <EOL> if "<STR_LIT>" in rule : <EOL> exclude_output = self . parse_rule ( rule [ "<STR_LIT>" ] , is_separator , parent , level + <NUM_LIT:1> , begin ) <EOL> if exclude_output [ "<STR_LIT>" ] : <EOL> good = False <EOL> if good : <EOL> if "<STR_LIT>" in rule : <EOL> if rule [ "<STR_LIT>" ] in self . re_cache : <EOL> re_pattern = self . re_cache [ rule [ "<STR_LIT>" ] ] <EOL> else : <EOL> re_pattern = re . compile ( rule [ "<STR_LIT>" ] ) <EOL> if not is_separator and "<STR_LIT>" in self . grammar and ( "<STR_LIT>" not in rule or rule [ "<STR_LIT>" ] ) : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( begin ) ) <EOL> separator_output = self . parse_rule ( self . grammar [ "<STR_LIT>" ] , True , parent , level + <NUM_LIT:1> , begin ) <EOL> if separator_output [ "<STR_LIT>" ] : <EOL> begin = separator_output [ "<STR_LIT>" ] <EOL> regions += separator_output [ "<STR_LIT>" ] <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" ) <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( begin ) + "<STR_LIT>" + rule [ "<STR_LIT>" ] ) <EOL> matches = re_pattern . search ( self . data [ begin : len ( self . data ) ] ) <EOL> if matches is not None and matches . start ( ) == <NUM_LIT:0> : <EOL> rule_output [ "<STR_LIT>" ] = True <EOL> rule_output [ "<STR_LIT>" ] = True <EOL> rule_output [ "<STR_LIT>" ] = begin <EOL> rule_output [ "<STR_LIT:end>" ] = begin + matches . end ( ) <EOL> rule_output [ "<STR_LIT>" ] = rule_output [ "<STR_LIT:end>" ] <EOL> begin = rule_output [ "<STR_LIT:end>" ] <EOL> if "<STR_LIT:name>" in rule : <EOL> regions . append ( { "<STR_LIT>" : rule_output [ "<STR_LIT>" ] , "<STR_LIT:end>" : rule_output [ "<STR_LIT:end>" ] , "<STR_LIT:value>" : self . data [ rule_output [ "<STR_LIT>" ] : rule_output [ "<STR_LIT:end>" ] ] , "<STR_LIT>" : parent , "<STR_LIT:name>" : rule [ "<STR_LIT:name>" ] } ) <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( rule_output [ "<STR_LIT>" ] ) + "<STR_LIT::>" + str ( rule_output [ "<STR_LIT:end>" ] ) ) <EOL> else : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( rule_output [ "<STR_LIT:end>" ] ) ) <EOL> if not is_separator and rule_output [ "<STR_LIT>" ] and "<STR_LIT>" in self . grammar and ( "<STR_LIT>" not in rule or rule [ "<STR_LIT>" ] ) : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( rule_output [ "<STR_LIT:end>" ] ) ) <EOL> separator_output = self . parse_rule ( self . grammar [ "<STR_LIT>" ] , True , parent , level + <NUM_LIT:1> , begin ) <EOL> if separator_output [ "<STR_LIT>" ] : <EOL> begin = separator_output [ "<STR_LIT>" ] <EOL> regions += separator_output [ "<STR_LIT>" ] <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" ) <EOL> elif "<STR_LIT>" in rule : <EOL> parse_output = self . parse_rule_list ( rule [ "<STR_LIT>" ] , is_separator , parent , level + <NUM_LIT:1> , begin ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> if "<STR_LIT:name>" in rule : <EOL> regions . append ( { "<STR_LIT>" : parse_output [ "<STR_LIT>" ] , "<STR_LIT:end>" : parse_output [ "<STR_LIT:end>" ] , "<STR_LIT:value>" : self . data [ parse_output [ "<STR_LIT>" ] : parse_output [ "<STR_LIT:end>" ] ] , "<STR_LIT>" : parent , "<STR_LIT:name>" : rule [ "<STR_LIT:name>" ] } ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> begin = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT:end>" ] = parse_output [ "<STR_LIT:end>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> regions += parse_output [ "<STR_LIT>" ] <EOL> elif "<STR_LIT>" in rule : <EOL> parse_output = self . parse_rule_list_any ( rule [ "<STR_LIT>" ] , is_separator , parent , level + <NUM_LIT:1> , begin ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> if "<STR_LIT:name>" in rule : <EOL> regions . append ( { "<STR_LIT>" : parse_output [ "<STR_LIT>" ] , "<STR_LIT:end>" : parse_output [ "<STR_LIT:end>" ] , "<STR_LIT:value>" : self . data [ parse_output [ "<STR_LIT>" ] : parse_output [ "<STR_LIT:end>" ] ] , "<STR_LIT>" : parent , "<STR_LIT:name>" : rule [ "<STR_LIT:name>" ] } ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> begin = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT:end>" ] = parse_output [ "<STR_LIT:end>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> regions += parse_output [ "<STR_LIT>" ] <EOL> elif "<STR_LIT>" in rule : <EOL> if "<STR_LIT>" in self . grammar and rule [ "<STR_LIT>" ] in self . grammar [ "<STR_LIT>" ] : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + rule [ "<STR_LIT>" ] ) <EOL> parse_output = self . parse_rule ( self . grammar [ "<STR_LIT>" ] [ rule [ "<STR_LIT>" ] ] , is_separator , parent , level + <NUM_LIT:1> , begin ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> if "<STR_LIT:name>" in rule : <EOL> regions . append ( { "<STR_LIT>" : parse_output [ "<STR_LIT>" ] , "<STR_LIT:end>" : parse_output [ "<STR_LIT:end>" ] , "<STR_LIT:value>" : self . data [ parse_output [ "<STR_LIT>" ] : parse_output [ "<STR_LIT:end>" ] ] , "<STR_LIT>" : parent , "<STR_LIT:name>" : rule [ "<STR_LIT:name>" ] } ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> begin = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT:end>" ] = parse_output [ "<STR_LIT:end>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> regions += parse_output [ "<STR_LIT>" ] <EOL> else : <EOL> rule_output [ "<STR_LIT>" ] = False <EOL> if "<STR_LIT>" in rule and rule [ "<STR_LIT>" ] and rule_output [ "<STR_LIT>" ] : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( begin ) ) <EOL> parse_output = self . parse_rule ( rule , is_separator , parent , level + <NUM_LIT:1> , begin ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> if "<STR_LIT:name>" in rule : <EOL> regions . append ( { "<STR_LIT>" : parse_output [ "<STR_LIT>" ] , "<STR_LIT:end>" : parse_output [ "<STR_LIT:end>" ] , "<STR_LIT:value>" : self . data [ parse_output [ "<STR_LIT>" ] : parse_output [ "<STR_LIT:end>" ] ] , "<STR_LIT>" : parent , "<STR_LIT:name>" : rule [ "<STR_LIT:name>" ] } ) <EOL> if parse_output [ "<STR_LIT>" ] : <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> begin = parse_output [ "<STR_LIT>" ] <EOL> rule_output [ "<STR_LIT:end>" ] = parse_output [ "<STR_LIT:end>" ] <EOL> rule_output [ "<STR_LIT>" ] = parse_output [ "<STR_LIT>" ] <EOL> regions += parse_output [ "<STR_LIT>" ] <EOL> if rule_output [ "<STR_LIT>" ] : <EOL> if "<STR_LIT:name>" in rule : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" ) <EOL> elif ( "<STR_LIT>" in rule and rule [ "<STR_LIT>" ] ) or ( "<STR_LIT>" in rule and rule [ "<STR_LIT>" ] ) : <EOL> rule_output [ "<STR_LIT>" ] = True <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" ) <EOL> if "<STR_LIT:name>" in rule : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + rule [ "<STR_LIT:name>" ] + "<STR_LIT>" + str ( begin ) + "<STR_LIT>" ) <EOL> else : <EOL> if self . printer is not None and not is_separator : <EOL> self . printer ( level , "<STR_LIT>" + str ( begin ) + "<STR_LIT>" ) <EOL> rule_output [ "<STR_LIT>" ] = regions <EOL> return rule_output <EOL> def find_all ( self ) : <EOL> return self . regions <EOL> def find_by_regex ( self , regex , search_regions = None ) : <EOL> if search_regions is None : <EOL> search_regions = self . regions <EOL> find_by_name = regex . startswith ( "<STR_LIT:@>" ) <EOL> if find_by_name : <EOL> regex = regex [ <NUM_LIT:1> : ] <EOL> re_pattern = re . compile ( regex ) <EOL> regions = [ ] <EOL> for region in search_regions : <EOL> if find_by_name : <EOL> name = region [ "<STR_LIT:name>" ] <EOL> else : <EOL> name = region [ "<STR_LIT>" ] <EOL> if re_pattern . match ( name ) is not None : <EOL> regions . append ( region ) <EOL> return regions <EOL> @ staticmethod <EOL> def filter_region ( region , selector , find_any , filter_selector , filter_value , search_regions ) : <EOL> nodes = GrammarParser . filter_inside_region ( [ region [ "<STR_LIT>" ] , region [ "<STR_LIT:end>" ] ] , search_regions ) <EOL> if find_any : <EOL> nodes = GrammarParser . filter_by_selector ( "<STR_LIT:>>" + filter_selector , nodes ) <EOL> else : <EOL> nodes = GrammarParser . filter_by_selector ( region [ "<STR_LIT>" ] + "<STR_LIT:>>" + filter_selector , nodes ) <EOL> for node in nodes : <EOL> if node [ "<STR_LIT:value>" ] == filter_value : <EOL> return True <EOL> return False <EOL> @ staticmethod <EOL> def filter_by_selector ( selector , search_regions ) : <EOL> regions = [ ] <EOL> filter_pattern = re . compile ( "<STR_LIT>" ) <EOL> filter_match = filter_pattern . search ( selector ) <EOL> filter_selector = None <EOL> if filter_match : <EOL> selector = selector [ : - len ( filter_match . group ( <NUM_LIT:0> ) ) ] <EOL> filter_any = filter_match . group ( "<STR_LIT>" ) and filter_match . group ( "<STR_LIT>" ) is not "<STR_LIT>" <EOL> filter_selector = filter_match . group ( "<STR_LIT>" ) <EOL> filter_value = filter_match . group ( "<STR_LIT>" ) <EOL> find_name = selector . startswith ( "<STR_LIT:@>" ) <EOL> if find_name : <EOL> selector = selector [ <NUM_LIT:1> : ] <EOL> find_any = selector . startswith ( "<STR_LIT:>>" ) <EOL> if find_any : <EOL> selector = selector [ <NUM_LIT:1> : ] <EOL> find_child = selector . endswith ( "<STR_LIT:>>" ) <EOL> if find_child : <EOL> selector = selector [ : - <NUM_LIT:1> ] <EOL> for region in search_regions : <EOL> key = "<STR_LIT>" <EOL> if find_name : <EOL> key = "<STR_LIT:name>" <EOL> is_child = selector + "<STR_LIT:>>" in region [ "<STR_LIT>" ] <EOL> child_filtered = not filter_selector or GrammarParser . filter_region ( region , selector , filter_any , filter_selector , filter_value , search_regions ) <EOL> if find_any : <EOL> if region [ key ] . endswith ( selector ) and not is_child : <EOL> if not child_filtered : <EOL> continue <EOL> if find_child : <EOL> regions += GrammarParser . filter_inside_region ( [ region [ "<STR_LIT>" ] , region [ "<STR_LIT:end>" ] ] , search_regions ) <EOL> else : <EOL> regions . append ( region ) <EOL> else : <EOL> if key is "<STR_LIT:name>" and region [ key ] is selector and not is_child : <EOL> if not child_filtered : <EOL> continue <EOL> if find_child : <EOL> regions += GrammarParser . filter_inside_region ( [ region [ "<STR_LIT>" ] , region [ "<STR_LIT:end>" ] ] , search_regions ) <EOL> else : <EOL> regions . append ( region ) <EOL> elif region [ key ] . startswith ( selector ) and not is_child : <EOL> if not child_filtered : <EOL> continue <EOL> if find_child : <EOL> regions += GrammarParser . filter_inside_region ( [ region [ "<STR_LIT>" ] , region [ "<STR_LIT:end>" ] ] , search_regions ) <EOL> else : <EOL> regions . append ( region ) <EOL> return regions <EOL> def find_by_selector ( self , selector , search_regions = None ) : <EOL> search_regions = search_regions or self . regions <EOL> return GrammarParser . filter_by_selector ( selector , search_regions ) <EOL> @ staticmethod <EOL> def filter_by_selectors ( selector_list , search_regions ) : <EOL> if type ( selector_list ) is str : <EOL> selectors = selector_list . split ( "<STR_LIT:|>" ) <EOL> new_selectors = [ ] <EOL> for selector in selectors : <EOL> new_selectors . append ( selector ) <EOL> return GrammarParser . filter_by_selectors ( new_selectors , search_regions ) <EOL> regions = [ ] <EOL> for selector in selector_list : <EOL> regions += GrammarParser . filter_by_selector ( selector , search_regions ) <EOL> return regions <EOL> def find_by_selectors ( self , selector_list , search_regions = None ) : <EOL> search_regions = search_regions or self . regions <EOL> return GrammarParser . filter_by_selectors ( selector_list , search_regions ) <EOL> @ staticmethod <EOL> def filter_by_region ( region , search_regions ) : <EOL> if type ( region ) is int : <EOL> return GrammarParser . filter_by_region ( [ region , region ] , search_regions ) <EOL> regions = [ ] <EOL> for node in search_regions : <EOL> if node [ "<STR_LIT>" ] <= region [ <NUM_LIT:0> ] and node [ "<STR_LIT:end>" ] >= region [ <NUM_LIT:1> ] : <EOL> regions . append ( node ) <EOL> return regions <EOL> def find_by_region ( self , region , search_regions = None ) : <EOL> search_regions = search_regions or self . regions <EOL> return GrammarParser . filter_by_region ( region , search_regions ) <EOL> @ staticmethod <EOL> def filter_inside_region ( region , search_regions ) : <EOL> if type ( region ) is int : <EOL> return GrammarParser . filter_inside_region ( <EOL> [ region , region ] , search_regions <EOL> ) <EOL> regions = [ ] <EOL> for node in search_regions : <EOL> if node [ "<STR_LIT>" ] >= region [ <NUM_LIT:0> ] and node [ "<STR_LIT:end>" ] <= region [ <NUM_LIT:1> ] : <EOL> regions . append ( node ) <EOL> return regions <EOL> def find_inside_region ( self , region , search_regions = None ) : <EOL> search_regions = search_regions or self . regions <EOL> return GrammarParser . filter_inside_region ( region , search_regions ) <EOL> def get_elapse_time ( self ) : <EOL> return self . elapse_time </s>
