Class: TreeHaver::Backends::Psych::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_haver/backends/psych.rb

Overview

Psych tree wrapper

Wraps a Psych::Nodes::Stream to provide TreeHaver-compatible tree interface.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, source) ⇒ Tree

Create a new tree wrapper



174
175
176
177
178
# File 'lib/tree_haver/backends/psych.rb', line 174

def initialize(stream, source)
  @inner_tree = stream
  @source = source
  @lines = source.lines
end

Instance Attribute Details

#inner_tree::Psych::Nodes::Stream (readonly)



165
166
167
# File 'lib/tree_haver/backends/psych.rb', line 165

def inner_tree
  @inner_tree
end

#sourceString (readonly)



168
169
170
# File 'lib/tree_haver/backends/psych.rb', line 168

def source
  @source
end

Instance Method Details

#commentsArray

Get comments from the document

Psych doesn’t preserve comments in the AST by default.



211
212
213
# File 'lib/tree_haver/backends/psych.rb', line 211

def comments
  []
end

#errorsArray

Get parse errors

Psych raises exceptions on parse errors rather than recording them, so this is always empty if we got a tree.



195
196
197
# File 'lib/tree_haver/backends/psych.rb', line 195

def errors
  []
end

#inspectString



216
217
218
# File 'lib/tree_haver/backends/psych.rb', line 216

def inspect
  "#<TreeHaver::Backends::Psych::Tree documents=#{@inner_tree.children&.size || 0}>"
end

#root_nodeNode

Get the root node

For YAML, the stream is the root. We wrap it as a Node.



185
186
187
# File 'lib/tree_haver/backends/psych.rb', line 185

def root_node
  Node.new(@inner_tree, @source, @lines)
end

#warningsArray

Get parse warnings



202
203
204
# File 'lib/tree_haver/backends/psych.rb', line 202

def warnings
  []
end