Class: SyntaxTree::XML::Token

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/xml/nodes.rb

Overview

A Token is any kind of lexical token from the source. It has a type, a value which is a subset of the source, and an index where it starts in the source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#format, #pretty_print

Constructor Details

#initialize(type:, value:, location:) ⇒ Token

Returns a new instance of Token.



56
57
58
59
60
# File 'lib/syntax_tree/xml/nodes.rb', line 56

def initialize(type:, value:, location:)
  @type = type
  @value = value
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



54
55
56
# File 'lib/syntax_tree/xml/nodes.rb', line 54

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



54
55
56
# File 'lib/syntax_tree/xml/nodes.rb', line 54

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



54
55
56
# File 'lib/syntax_tree/xml/nodes.rb', line 54

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



62
63
64
# File 'lib/syntax_tree/xml/nodes.rb', line 62

def accept(visitor)
  visitor.visit_token(self)
end

#child_nodesObject Also known as: deconstruct



66
67
68
# File 'lib/syntax_tree/xml/nodes.rb', line 66

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



72
73
74
# File 'lib/syntax_tree/xml/nodes.rb', line 72

def deconstruct_keys(keys)
  { type: type, value: value, location: location }
end