[ruby/yarp] Split up compiler versus visitor

2e6baa3f19
This commit is contained in:
Kevin Newton 2023-09-22 11:31:45 -04:00
parent 3cec94624b
commit b18e05b18f
10 changed files with 154 additions and 36 deletions

View file

@ -229,24 +229,6 @@ module YARP
end
end
# A class that knows how to walk down the tree. None of the individual visit
# methods are implemented on this visitor, so it forces the consumer to
# implement each one that they need. For a default implementation that
# continues walking the tree, see the Visitor class.
class BasicVisitor
def visit(node)
node&.accept(self)
end
def visit_all(nodes)
nodes.map { |node| visit(node) }
end
def visit_child_nodes(node)
visit_all(node.child_nodes)
end
end
# This represents a token from the Ruby source.
class Token
attr_reader :type, :value, :location
@ -539,14 +521,17 @@ module YARP
# which means the files can end up being quite large. We autoload them to make
# our require speed faster since consuming libraries are unlikely to use all
# of these features.
autoload :DesugarVisitor, "yarp/desugar_visitor"
autoload :BasicVisitor, "yarp/visitor"
autoload :Compiler, "yarp/compiler"
autoload :DesugarCompiler, "yarp/desugar_compiler"
autoload :Dispatcher, "yarp/dispatcher"
autoload :DSL, "yarp/dsl"
autoload :MutationVisitor, "yarp/mutation_visitor"
autoload :MutationCompiler, "yarp/mutation_compiler"
autoload :RipperCompat, "yarp/ripper_compat"
autoload :Pack, "yarp/pack"
autoload :Pattern, "yarp/pattern"
autoload :Serialize, "yarp/serialize"
autoload :Visitor, "yarp/visitor"
# Load the serialized AST using the source as a reference into a tree.
def self.load(source, serialized)

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
module YARP
class DesugarVisitor < MutationVisitor
class DesugarCompiler < MutationCompiler
# @@foo &&= bar
#
# becomes

View file

@ -59,12 +59,13 @@ Gem::Specification.new do |spec|
"include/yarp/util/yp_strpbrk.h",
"include/yarp/version.h",
"lib/yarp.rb",
"lib/yarp/desugar_visitor.rb",
"lib/yarp/compiler.rb",
"lib/yarp/desugar_compiler.rb",
"lib/yarp/dispatcher.rb",
"lib/yarp/dsl.rb",
"lib/yarp/ffi.rb",
"lib/yarp/lex_compat.rb",
"lib/yarp/mutation_visitor.rb",
"lib/yarp/mutation_compiler.rb",
"lib/yarp/node.rb",
"lib/yarp/pack.rb",
"lib/yarp/pattern.rb",
@ -72,6 +73,7 @@ Gem::Specification.new do |spec|
"lib/yarp/serialize.rb",
"lib/yarp/parse_result/comments.rb",
"lib/yarp/parse_result/newlines.rb",
"lib/yarp/visitor.rb",
"src/diagnostic.c",
"src/enc/yp_big5.c",
"src/enc/yp_euc_jp.c",