Class: PositionVisitor

Inherits:
Psych::Visitors::ToRuby
  • Object
show all
Defined in:
lib/traceable.rb

Overview

Extend the Ruby structure builder to remeber each object’s position.

Instance Method Summary collapse

Instance Method Details

#record_position(s, o) ⇒ Object

Copy a parser position from a parse tree node to a primitive object.



161
162
163
164
165
166
167
168
# File 'lib/traceable.rb', line 161

def record_position(s, o)
  s.extend Traceable
  s.file = o.file
  s.byte = o.byte
  s.line = o.line
  s.column = o.column
  s
end

#visit_Psych_Nodes_Mapping(o) ⇒ Object



182
183
184
# File 'lib/traceable.rb', line 182

def visit_Psych_Nodes_Mapping o
  record_position(super, o)
end

#visit_Psych_Nodes_Scalar(o) ⇒ Object

rubocop:disable Style/MethodName



171
172
173
174
175
176
# File 'lib/traceable.rb', line 171

def visit_Psych_Nodes_Scalar o
  # Primitive YAML values can be either strings or integers. Ruby
  # integers cannot be extended, so convert everything to strings
  # before inserting position information.
  record_position(TraceableString.new(String(super)), o)
end

#visit_Psych_Nodes_Sequence(o) ⇒ Object



178
179
180
# File 'lib/traceable.rb', line 178

def visit_Psych_Nodes_Sequence o
  record_position(super, o)
end