class RuboCop::AST::NodePattern::Compiler

def compile_expr(token = tokens.shift)

rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def compile_expr(token = tokens.shift)
  # read a single pattern-matching expression from the token stream,
  # return Ruby code which performs the corresponding matching operation
  #
  # the 'pattern-matching' expression may be a composite which
  # contains an arbitrary number of sub-expressions, but that composite
  # must all have precedence higher or equal to that of `&&`
  #
  # Expressions may use placeholders like:
  #   CUR_NODE: Ruby code that evaluates to an AST node
  #   CUR_ELEMENT: Either the node or the type if in first element of
  #   a sequence (aka seq_head, e.g. "(seq_head first_node_arg ...")
  if (atom = compile_atom(token))
    return atom_to_expr(atom)
  end
  case token
  when '('       then compile_seq
  when '{'       then compile_union
  when '['       then compile_intersect
  when '!'       then compile_negation
  when '$'       then compile_capture
  when '^'       then compile_ascend
  when '`'       then compile_descend
  when WILDCARD  then compile_new_wildcard(token[1..-1])
  when FUNCALL   then compile_funcall(token)
  when PREDICATE then compile_predicate(token)
  when NODE      then compile_nodetype(token)
  else                fail_due_to("invalid token #{token.inspect}")
  end
end