#NEWLINE# def _tgrep_bind_node_label_action( _s , _l , tokens ) : #NEWLINE# #INDENT# "\n    Builds a lambda function representing a predicate on a tree node\n    which can optionally bind a matching node into the tgrep2 string's\n    label_dict.\n\n    Called for expressions like (`tgrep_node_expr2`)::\n\n        /NP/\n        @NP=n\n    " #NEWLINE# if ( len ( tokens ) == 1 ) : #NEWLINE# #INDENT# return tokens [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( len ( tokens ) == 3 ) #NEWLINE# assert ( tokens [ 1 ] == '=' ) #NEWLINE# node_pred = tokens [ 0 ] #NEWLINE# node_label = tokens [ 2 ] #NEWLINE# def node_label_bind_pred( n , m = None , l = None ) : #NEWLINE# #INDENT# if node_pred ( n , m , l ) : #NEWLINE# #INDENT# if ( l is None ) : #NEWLINE# #INDENT# raise TgrepException ( 'cannot bind node_label {0}: label_dict is None' . format ( node_label ) ) #NEWLINE# #UNINDENT# l [ node_label ] = n #NEWLINE# return True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# return _s