Module: Prism::DSL
- Defined in:
- lib/prism/dsl.rb
Overview
The DSL module provides a set of methods that can be used to create prism nodes in a more concise manner. For example, instead of writing:
source = Prism::Source.new("[1]")
Prism::ArrayNode.new(
[
Prism::IntegerNode.new(
Prism::IntegerBaseFlags::DECIMAL,
Prism::Location.new(source, 1, 1),
)
],
Prism::Location.new(source, 0, 1),
Prism::Location.new(source, 2, 1)
)
you could instead write:
source = Prism::Source.new("[1]")
ArrayNode(
IntegerNode(Prism::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.