Sha256: 118dc19174d53163c8e53abc9e8056050702d7589f487a172825d1d8928a5e54

Contents?: true

Size: 978 Bytes

Versions: 4

Compression:

Stored size: 978 Bytes

Contents

module Yoda
  module AST
    class MultipleLeftHandSideNode < Node
      # @return [Array<Vnode>]
      def pre_nodes
        @pre_nodes ||= children.take_while { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) }
      end

      # @return [Vnode, nil]
      def rest_node
        @rest_node ||= node.children.find { |arg_node| arg_node.type == :restarg }
      end

      # @return [Array<Vnode>]
      def post_nodes
        @post_nodes ||= children.drop_while { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) }.select { |arg_node| %i(arg optarg mlhs).include?(arg_node.type) }
      end

      # @return [Model::Parameters::Base]
      def parameter
        rest_parameter = rest_node&.respond_to?(:parameter) && rest_node.parameter

        Model::Parameters::Multiple.new(
          parameters: pre_nodes.map(&:parameter),
          rest_parameter: rest_parameter,
          post_parameters: post_nodes.map(&:paramter),
        )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yoda-language-server-0.10.1 lib/yoda/ast/multiple_left_hand_side_node.rb
yoda-language-server-0.10.0 lib/yoda/ast/multiple_left_hand_side_node.rb
yoda-language-server-0.9.0 lib/yoda/ast/multiple_left_hand_side_node.rb
yoda-language-server-0.8.0 lib/yoda/ast/multiple_left_hand_side_node.rb