Sha256: 2e59e6bdc1ea499e75af8b55b5e533d47f28cdf48f407a407664fb6038bd4dae

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module Brandish
  class Parser
    class Node
      # A key-value pair used for a command.  This is used to represent an
      # argument for the command node.
      class Pair < Node
        # The key of the pair.  This will *always* be a `:TEXT`.
        #
        # @return [Scanner::Token] The key.
        attr_reader :key

        # The value of the pair.
        #
        # @return [Parser::Node::Text, Parser::Node::String] The value.
        attr_reader :value

        # Initialize the pair node with the given key, value and location.
        #
        # @param key [Yoga::Token] The key.
        # @param value [Parser::Node::Text, Parser::Node::String] The value.
        # @param location [Location] The location of the key-value pair.
        def initialize(key:, value:, location: nil)
          @key = key
          @value = value
          @location = location || key.location.union(value.location)
          freeze
        end

        # Pretty inspect.
        #
        # @return [::String]
        def inspect
          "#<#{self.class} key=#{@key.inspect} value=#{@value.inspect} " \
            "location=#{@location.inspect}>"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
brandish-0.1.3 lib/brandish/parser/node/pair.rb
brandish-0.1.2 lib/brandish/parser/node/pair.rb
brandish-0.1.1 lib/brandish/parser/node/pair.rb