code: def _tgrep_bind_node_label_action(_s, _l, tokens):
      """
      Builds a lambda function representing a predicate on a tree node
      which can optionally bind a matching node into the tgrep2 string's
      label_dict.
  
      Called for expressions like (`tgrep_node_expr2`)::
  
          /NP/
          @NP=n
      """
      # tokens[0] is a tgrep_node_expr
      if len(tokens) == 1:
          return tokens[0]
      else:
          # if present, tokens[1] is the character '=', and tokens[2] is
          # a tgrep_node_label, a string value containing the node label
          assert len(tokens) == 3
          assert tokens[1] == "="
          node_pred = tokens[0]
          node_label = tokens[2]
  
          def node_label_bind_pred(n, m=None, l=None):
              if node_pred(n, m, l):
                  # bind `n` into the dictionary `l`
                  if l is None:
                      raise TgrepException(
                          "cannot bind node_label {}: label_dict is None".format(
                              node_label
                          )
                      )
                  l[node_label] = n
                  return True
              else:
                  return False
  
          return node_label_bind_pred
  
imports: import functools
  import re
  import nltk.tree
label_desc: Use image node_id 22 for calling a global function with example usage: _tgrep_bind_node_label_action(_s, _l, tokens) and returns: tokens, node_label_bind_pred, True, False