module Prism::DSL

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.for("[1]")

Prism::ArrayNode.new(
  source,
  0,
  Prism::Location.new(source, 0, 3),
  0,
  [
    Prism::IntegerNode.new(
      source,
      0,
      Prism::Location.new(source, 1, 1),
      Prism::IntegerBaseFlags::DECIMAL,
      1
    )
  ],
  Prism::Location.new(source, 0, 1),
  Prism::Location.new(source, 2, 1)
)

you could instead write:

class Builder
  include Prism::DSL

  attr_reader :default_source

  def initialize
    @default_source = source("[1]")
  end

  def build
    array_node(
      location: location(start_offset: 0, length: 3),
      elements: [
        integer_node(
          location: location(start_offset: 1, length: 1),
          flags: integer_base_flag(:decimal),
          value: 1
        )
      ],
      opening_loc: location(start_offset: 0, length: 1),
      closing_loc: location(start_offset: 2, length: 1)
    )
  end
end

This is mostly helpful in the context of generating trees programmatically.