Class: Brandish::Parser::Node::Pair

Inherits:
Brandish::Parser::Node show all
Defined in:
lib/brandish/parser/node/pair.rb

Overview

A key-value pair used for a command. This is used to represent an argument for the command node.

Instance Attribute Summary collapse

Attributes inherited from Brandish::Parser::Node

#location

Instance Method Summary collapse

Methods inherited from Brandish::Parser::Node

#prevent_update, #update, #update_prevented?

Constructor Details

#initialize(key:, value:, location: nil) ⇒ Pair

Initialize the pair node with the given key, value and location.

Parameters:



25
26
27
28
29
30
# File 'lib/brandish/parser/node/pair.rb', line 25

def initialize(key:, value:, location: nil)
  @key = key
  @value = value
  @location = location || key.location.union(value.location)
  freeze
end

Instance Attribute Details

#keyScanner::Token (readonly)

The key of the pair. This will always be a :TEXT.

Returns:

  • (Scanner::Token)

    The key.



13
14
15
# File 'lib/brandish/parser/node/pair.rb', line 13

def key
  @key
end

#valueParser::Node::Text, Parser::Node::String (readonly)

The value of the pair.

Returns:



18
19
20
# File 'lib/brandish/parser/node/pair.rb', line 18

def value
  @value
end

Instance Method Details

#inspect::String

Pretty inspect.

Returns:

  • (::String)


35
36
37
38
# File 'lib/brandish/parser/node/pair.rb', line 35

def inspect
  "#<#{self.class} key=#{@key.inspect} value=#{@value.inspect} " \
    "location=#{@location.inspect}>"
end