Class: SyntaxTree::ERB::Token

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/erb/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, #skip?, #without_new_line

Constructor Details

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

Returns a new instance of Token.



72
73
74
75
76
# File 'lib/syntax_tree/erb/nodes.rb', line 72

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



70
71
72
# File 'lib/syntax_tree/erb/nodes.rb', line 70

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



70
71
72
# File 'lib/syntax_tree/erb/nodes.rb', line 70

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



70
71
72
# File 'lib/syntax_tree/erb/nodes.rb', line 70

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



78
79
80
# File 'lib/syntax_tree/erb/nodes.rb', line 78

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

#child_nodesObject Also known as: deconstruct



82
83
84
# File 'lib/syntax_tree/erb/nodes.rb', line 82

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



88
89
90
# File 'lib/syntax_tree/erb/nodes.rb', line 88

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