Sha256: e732866f48e695d185346eb6e239ef83f17fd3baef6b85892755e2a96010cfec

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

module AQL
  class Node
    # AST node for function call
    class Call < self
      include Concord.new(:name, :arguments)

    private

      # Emit node
      #
      # @param [Buffer] buffer
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit(buffer)
        buffer.append(name)
        buffer.parentheses do
          emit_arguments_with_for_check(buffer)
        end
      end

      # Emit arguments with for check
      #
      # Handles edge case described in https://github.com/triAGENS/ArangoDB/issues/399
      #
      # @param [Buffer] buffer
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_arguments_with_for_check(buffer)
        if for_argument?
          emit_arguments_with_extra_parentheses(buffer)
        else
          emit_arguments(buffer)
        end
      end

      # Emit arguments with parentheses
      #
      # @param [Buffer] buffer
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_arguments_with_extra_parentheses(buffer)
        buffer.parentheses { emit_arguments(buffer) }
      end

      # Test for `for` body
      #
      # @return [true]
      #   if an instance of Node::Operation::For is the only argument
      #
      # @return [false]
      #   otherwise
      #
      # @api private
      #
      def for_argument?
        local = arguments
        local.length == 1 and local.first.kind_of?(Operation::For)
      end

      # Emit arguments
      #
      # @param [Buffer] buffer
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_arguments(buffer)
        buffer.delimited(arguments)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aql-0.0.3 lib/aql/node/call.rb
aql-0.0.2 lib/aql/node/call.rb
aql-0.0.1 lib/aql/node/call.rb