Skip to content

Commit d510145

Browse files
committed
Move BasicVisitor below ParseResult in yarp.rb
1 parent 2f1f3fa commit d510145

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

lib/yarp.rb

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -202,27 +202,6 @@ def inspect
202202
end
203203
end
204204

205-
# A class that knows how to walk down the tree. None of the individual visit
206-
# methods are implemented on this visitor, so it forces the consumer to
207-
# implement each one that they need. For a default implementation that
208-
# continues walking the tree, see the Visitor class.
209-
class BasicVisitor
210-
def visit(node)
211-
node&.accept(self)
212-
end
213-
214-
def visit_all(nodes)
215-
nodes.map { |node| visit(node) }
216-
end
217-
218-
def visit_child_nodes(node)
219-
visit_all(node.child_nodes)
220-
end
221-
end
222-
223-
class Visitor < BasicVisitor
224-
end
225-
226205
# This represents the result of a call to ::parse or ::parse_file. It contains
227206
# the AST, any comments that were encounters, and any errors that were
228207
# encountered.
@@ -250,6 +229,24 @@ def failure?
250229
end
251230
end
252231

232+
# A class that knows how to walk down the tree. None of the individual visit
233+
# methods are implemented on this visitor, so it forces the consumer to
234+
# implement each one that they need. For a default implementation that
235+
# continues walking the tree, see the Visitor class.
236+
class BasicVisitor
237+
def visit(node)
238+
node&.accept(self)
239+
end
240+
241+
def visit_all(nodes)
242+
nodes.map { |node| visit(node) }
243+
end
244+
245+
def visit_child_nodes(node)
246+
visit_all(node.child_nodes)
247+
end
248+
end
249+
253250
# This represents a token from the Ruby source.
254251
class Token
255252
attr_reader :type, :value, :location
@@ -379,11 +376,6 @@ def to_str
379376
end
380377
end
381378

382-
# Load the serialized AST using the source as a reference into a tree.
383-
def self.load(source, serialized)
384-
Serialize.load(source, serialized)
385-
end
386-
387379
# This module is used for testing and debugging and is not meant to be used by
388380
# consumers of this library.
389381
module Debug
@@ -554,6 +546,11 @@ def self.parse_serialize_file(filepath)
554546
autoload :Pack, "yarp/pack"
555547
autoload :Pattern, "yarp/pattern"
556548
autoload :Serialize, "yarp/serialize"
549+
550+
# Load the serialized AST using the source as a reference into a tree.
551+
def self.load(source, serialized)
552+
Serialize.load(source, serialized)
553+
end
557554
end
558555

559556
require_relative "yarp/lex_compat"

0 commit comments

Comments
 (0)