<s> from vint . ast . node_type import NodeType <EOL> from vint . ast . traversing import traverse , register_traverser_extension <EOL> from vint . ast . parsing import Parser <EOL> STRING_EXPR_CONTENT = '<STR_LIT>' <EOL> class MapAndFilterParser ( object ) : <EOL> """<STR_LIT>""" <EOL> def process ( self , ast ) : <EOL> def enter_handler ( node ) : <EOL> node_type = NodeType ( node [ '<STR_LIT:type>' ] ) <EOL> if node_type is not NodeType . CALL : <EOL> return <EOL> called_function_identifier = node [ '<STR_LIT:left>' ] <EOL> if NodeType ( called_function_identifier [ '<STR_LIT:type>' ] ) is not NodeType . IDENTIFIER : <EOL> return <EOL> is_map_or_function_call = called_function_identifier . get ( '<STR_LIT:value>' ) in { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> if not is_map_or_function_call : <EOL> return <EOL> string_expr_node = node [ '<STR_LIT>' ] [ <NUM_LIT:1> ] <EOL> if NodeType ( string_expr_node [ '<STR_LIT:type>' ] ) is not NodeType . STRING : <EOL> return <EOL> parser = Parser ( ) <EOL> string_expr_content_nodes = parser . parse_string_expr ( string_expr_node ) <EOL> node [ STRING_EXPR_CONTENT ] = string_expr_content_nodes <EOL> traverse ( ast , on_enter = enter_handler ) <EOL> return ast <EOL> def get_string_expr_content ( node ) : <EOL> return node . get ( STRING_EXPR_CONTENT ) <EOL> @ register_traverser_extension <EOL> def traverse_string_expr_content ( node , on_enter = None , on_leave = None ) : <EOL> string_expr_content_nodes = get_string_expr_content ( node ) <EOL> if string_expr_content_nodes is None : <EOL> return <EOL> for child_node in string_expr_content_nodes : <EOL> traverse ( child_node , on_enter = on_enter , on_leave = on_leave ) </s>
