[ruby/yarp] Move DSL into its own file
https://github.com/ruby/yarp/commit/3d34404d80
This commit is contained in:
parent
1c049c64c0
commit
2a4a55f896
@ -541,6 +541,7 @@ module YARP
|
|||||||
# of these features.
|
# of these features.
|
||||||
autoload :DesugarVisitor, "yarp/desugar_visitor"
|
autoload :DesugarVisitor, "yarp/desugar_visitor"
|
||||||
autoload :Dispatcher, "yarp/dispatcher"
|
autoload :Dispatcher, "yarp/dispatcher"
|
||||||
|
autoload :DSL, "yarp/dsl"
|
||||||
autoload :MutationVisitor, "yarp/mutation_visitor"
|
autoload :MutationVisitor, "yarp/mutation_visitor"
|
||||||
autoload :RipperCompat, "yarp/ripper_compat"
|
autoload :RipperCompat, "yarp/ripper_compat"
|
||||||
autoload :Pack, "yarp/pack"
|
autoload :Pack, "yarp/pack"
|
||||||
|
@ -61,6 +61,7 @@ Gem::Specification.new do |spec|
|
|||||||
"lib/yarp.rb",
|
"lib/yarp.rb",
|
||||||
"lib/yarp/desugar_visitor.rb",
|
"lib/yarp/desugar_visitor.rb",
|
||||||
"lib/yarp/dispatcher.rb",
|
"lib/yarp/dispatcher.rb",
|
||||||
|
"lib/yarp/dsl.rb",
|
||||||
"lib/yarp/ffi.rb",
|
"lib/yarp/ffi.rb",
|
||||||
"lib/yarp/lex_compat.rb",
|
"lib/yarp/lex_compat.rb",
|
||||||
"lib/yarp/mutation_visitor.rb",
|
"lib/yarp/mutation_visitor.rb",
|
||||||
|
45
yarp/templates/lib/yarp/dsl.rb.erb
Normal file
45
yarp/templates/lib/yarp/dsl.rb.erb
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
module YARP
|
||||||
|
# The DSL module provides a set of methods that can be used to create YARP
|
||||||
|
# nodes in a more concise manner. For example, instead of writing:
|
||||||
|
#
|
||||||
|
# source = YARP::Source.new("[1]")
|
||||||
|
#
|
||||||
|
# YARP::ArrayNode.new(
|
||||||
|
# [
|
||||||
|
# YARP::IntegerNode.new(
|
||||||
|
# YARP::IntegerBaseFlags::DECIMAL,
|
||||||
|
# YARP::Location.new(source, 1, 1),
|
||||||
|
# )
|
||||||
|
# ],
|
||||||
|
# YARP::Location.new(source, 0, 1),
|
||||||
|
# YARP::Location.new(source, 2, 1)
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# you could instead write:
|
||||||
|
#
|
||||||
|
# source = YARP::Source.new("[1]")
|
||||||
|
#
|
||||||
|
# ArrayNode(
|
||||||
|
# IntegerNode(YARP::IntegerBaseFlags::DECIMAL, Location(source, 1, 1))),
|
||||||
|
# Location(source, 0, 1),
|
||||||
|
# Location(source, 2, 1)
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# This is mostly helpful in the context of writing tests, but can also be used
|
||||||
|
# to generate trees programmatically.
|
||||||
|
module DSL
|
||||||
|
private
|
||||||
|
|
||||||
|
# Create a new Location object
|
||||||
|
def Location(source = nil, start_offset = 0, length = 0)
|
||||||
|
Location.new(source, start_offset, length)
|
||||||
|
end
|
||||||
|
<%- nodes.each do |node| -%>
|
||||||
|
|
||||||
|
# Create a new <%= node.name %> node
|
||||||
|
def <%= node.name %>(<%= (node.fields.map(&:name) + ["location = Location()"]).join(", ") %>)
|
||||||
|
<%= node.name %>.new(<%= (node.fields.map(&:name) + ["location"]).join(", ") %>)
|
||||||
|
end
|
||||||
|
<%- end -%>
|
||||||
|
end
|
||||||
|
end
|
@ -181,20 +181,4 @@ module YARP
|
|||||||
<%= "\n" if node != nodes.last -%>
|
<%= "\n" if node != nodes.last -%>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
end
|
end
|
||||||
|
|
||||||
module DSL
|
|
||||||
private
|
|
||||||
|
|
||||||
# Create a new Location object
|
|
||||||
def Location(source = nil, start_offset = 0, length = 0)
|
|
||||||
Location.new(source, start_offset, length)
|
|
||||||
end
|
|
||||||
<%- nodes.each do |node| -%>
|
|
||||||
|
|
||||||
# Create a new <%= node.name %> node
|
|
||||||
def <%= node.name %>(<%= (node.fields.map(&:name) + ["location = Location()"]).join(", ") %>)
|
|
||||||
<%= node.name %>.new(<%= (node.fields.map(&:name) + ["location"]).join(", ") %>)
|
|
||||||
end
|
|
||||||
<%- end -%>
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -367,6 +367,7 @@ module YARP
|
|||||||
"java/org/yarp/Nodes.java",
|
"java/org/yarp/Nodes.java",
|
||||||
"java/org/yarp/AbstractNodeVisitor.java",
|
"java/org/yarp/AbstractNodeVisitor.java",
|
||||||
"lib/yarp/dispatcher.rb",
|
"lib/yarp/dispatcher.rb",
|
||||||
|
"lib/yarp/dsl.rb",
|
||||||
"lib/yarp/mutation_visitor.rb",
|
"lib/yarp/mutation_visitor.rb",
|
||||||
"lib/yarp/node.rb",
|
"lib/yarp/node.rb",
|
||||||
"lib/yarp/serialize.rb",
|
"lib/yarp/serialize.rb",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user