#NEWLINE# def _tgrep_node_action( _s , _l , tokens ) : #NEWLINE# #INDENT# '\n    Builds a lambda function representing a predicate on a tree node\n    depending on the name of its node.\n    ' #NEWLINE# if ( tokens [ 0 ] == "'" ) : #NEWLINE# #INDENT# tokens = tokens [ 1 : ] #NEWLINE# #UNINDENT# if ( len ( tokens ) > 1 ) : #NEWLINE# #INDENT# assert ( list ( set ( tokens [ 1 : : 2 ] ) ) == [ '|' ] ) #NEWLINE# tokens = [ _tgrep_node_action ( None , None , [ node ] ) for node in tokens [ : : 2 ] ] #NEWLINE# return ( lambda t : ( lambda n , m = None , l = None : any ( ( f ( n , m , l ) for f in t ) ) ) ) ( tokens ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( tokens [ 0 ] , '__call__' ) : #NEWLINE# #INDENT# return tokens [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( tokens [ 0 ] == '*' ) or ( tokens [ 0 ] == '__' ) ) : #NEWLINE# #INDENT# return ( lambda n , m = None , l = None : True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if tokens [ 0 ] . startswith ( '"' ) : #NEWLINE# #INDENT# assert tokens [ 0 ] . endswith ( '"' ) #NEWLINE# node_lit = tokens [ 0 ] [ 1 : ( - 1 ) ] . replace ( '\\"' , '"' ) . replace ( '\\\\' , '\\' ) #NEWLINE# return ( lambda s : ( lambda n , m = None , l = None : ( _tgrep_node_literal_value ( n ) == s ) ) ) ( node_lit ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if tokens [ 0 ] . startswith ( '/' ) : #NEWLINE# #INDENT# assert tokens [ 0 ] . endswith ( '/' ) #NEWLINE# node_lit = tokens [ 0 ] [ 1 : ( - 1 ) ] #NEWLINE# return ( lambda r : ( lambda n , m = None , l = None : r . search ( _tgrep_node_literal_value ( n ) ) ) ) ( re . compile ( node_lit ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if tokens [ 0 ] . startswith ( 'i@' ) : #NEWLINE# #INDENT# node_func = _tgrep_node_action ( _s , _l , [ tokens [ 0 ] [ 2 : ] . lower ( ) ] ) #NEWLINE# return ( lambda f : ( lambda n , m = None , l = None : f ( _tgrep_node_literal_value ( n ) . lower ( ) ) ) ) ( node_func ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( lambda s : ( lambda n , m = None , l = None : ( _tgrep_node_literal_value ( n ) == s ) ) ) ( tokens [ 0 ] )