Module

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.

Instance Methods

Create a new AliasGlobalVariableNode node.

Create a new AliasMethodNode node.

Create a new AlternationPatternNode node.

Create a new AndNode node.

Create a new ArgumentsNode node.

Retrieve the value of one of the ArgumentsNodeFlags flags.

Create a new ArrayNode node.

Retrieve the value of one of the ArrayNodeFlags flags.

Create a new ArrayPatternNode node.

Create a new AssocNode node.

Create a new AssocSplatNode node.

Create a new BackReferenceReadNode node.

Create a new BeginNode node.

Create a new BlockArgumentNode node.

Create a new BlockLocalVariableNode node.

Create a new BlockNode node.

Create a new BlockParameterNode node.

Create a new BlockParametersNode node.

Create a new BreakNode node.

Create a new CallAndWriteNode node.

Create a new CallNode node.

Retrieve the value of one of the CallNodeFlags flags.

Create a new CallOperatorWriteNode node.

Create a new CallOrWriteNode node.

Create a new CallTargetNode node.

Create a new CapturePatternNode node.

Create a new CaseMatchNode node.

Create a new CaseNode node.

Create a new ClassNode node.

Create a new ClassVariableAndWriteNode node.

Create a new ClassVariableOperatorWriteNode node.

Create a new ClassVariableOrWriteNode node.

Create a new ClassVariableReadNode node.

Create a new ClassVariableTargetNode node.

Create a new ClassVariableWriteNode node.

Create a new ConstantAndWriteNode node.

Create a new ConstantOperatorWriteNode node.

Create a new ConstantOrWriteNode node.

Create a new ConstantPathAndWriteNode node.

Create a new ConstantPathNode node.

Create a new ConstantPathOperatorWriteNode node.

Create a new ConstantPathOrWriteNode node.

Create a new ConstantPathTargetNode node.

Create a new ConstantPathWriteNode node.

Create a new ConstantReadNode node.

Create a new ConstantTargetNode node.

Create a new ConstantWriteNode node.

Create a new DefNode node.

The default location object that gets attached to nodes if no location is specified, which uses the given source.

The default node that gets attached to nodes if no node is specified for a required node field.

The default source object that gets attached to nodes and locations if no source is specified.

Create a new DefinedNode node.

Create a new ElseNode node.

Create a new EmbeddedStatementsNode node.

Create a new EmbeddedVariableNode node.

Retrieve the value of one of the EncodingFlags flags.

Create a new EnsureNode node.

Create a new FalseNode node.

Create a new FindPatternNode node.

Create a new FlipFlopNode node.

Create a new FloatNode node.

Create a new ForNode node.

Create a new ForwardingArgumentsNode node.

Create a new ForwardingParameterNode node.

Create a new ForwardingSuperNode node.

Create a new GlobalVariableAndWriteNode node.

Create a new GlobalVariableOperatorWriteNode node.

Create a new GlobalVariableOrWriteNode node.

Create a new GlobalVariableReadNode node.

Create a new GlobalVariableTargetNode node.

Create a new GlobalVariableWriteNode node.

Create a new HashNode node.

Create a new HashPatternNode node.

Create a new IfNode node.

Create a new ImaginaryNode node.

Create a new ImplicitNode node.

Create a new ImplicitRestNode node.

Create a new InNode node.

Create a new IndexAndWriteNode node.

Create a new IndexOperatorWriteNode node.

Create a new IndexOrWriteNode node.

Create a new IndexTargetNode node.

Create a new InstanceVariableAndWriteNode node.

Create a new InstanceVariableOrWriteNode node.

Create a new InstanceVariableReadNode node.

Create a new InstanceVariableTargetNode node.

Create a new InstanceVariableWriteNode node.

Retrieve the value of one of the IntegerBaseFlags flags.

Create a new IntegerNode node.

Create a new InterpolatedMatchLastLineNode node.

Create a new InterpolatedStringNode node.

Retrieve the value of one of the InterpolatedStringNodeFlags flags.

Create a new InterpolatedSymbolNode node.

Create a new InterpolatedXStringNode node.

Create a new ItLocalVariableReadNode node.

Create a new ItParametersNode node.

Create a new KeywordHashNode node.

Retrieve the value of one of the KeywordHashNodeFlags flags.

Create a new KeywordRestParameterNode node.

Create a new LambdaNode node.

Create a new LocalVariableAndWriteNode node.

Create a new LocalVariableOperatorWriteNode node.

Create a new LocalVariableOrWriteNode node.

Create a new LocalVariableReadNode node.

Create a new LocalVariableTargetNode node.

Create a new LocalVariableWriteNode node.

Create a new Location object.

Retrieve the value of one of the LoopFlags flags.

Create a new MatchLastLineNode node.

Create a new MatchPredicateNode node.

Create a new MatchRequiredNode node.

Create a new MatchWriteNode node.

Create a new MissingNode node.

Create a new ModuleNode node.

Create a new MultiTargetNode node.

Create a new MultiWriteNode node.

Create a new NextNode node.

Create a new NilNode node.

Create a new NoKeywordsParameterNode node.

Create a new NumberedParametersNode node.

Create a new NumberedReferenceReadNode node.

Create a new OptionalKeywordParameterNode node.

Create a new OptionalParameterNode node.

Create a new OrNode node.

Retrieve the value of one of the ParameterFlags flags.

Create a new ParametersNode node.

Create a new ParenthesesNode node.

Create a new PinnedExpressionNode node.

Create a new PinnedVariableNode node.

Create a new PostExecutionNode node.

Create a new PreExecutionNode node.

Create a new ProgramNode node.

Retrieve the value of one of the RangeFlags flags.

Create a new RangeNode node.

Create a new RationalNode node.

Create a new RedoNode node.

Retrieve the value of one of the RegularExpressionFlags flags.

Create a new RegularExpressionNode node.

Create a new RequiredKeywordParameterNode node.

Create a new RequiredParameterNode node.

Create a new RescueModifierNode node.

Create a new RescueNode node.

Create a new RestParameterNode node.

Create a new RetryNode node.

Create a new ReturnNode node.

Create a new SelfNode node.

Create a new ShareableConstantNode node.

Retrieve the value of one of the ShareableConstantNodeFlags flags.

Create a new SingletonClassNode node.

Create a new Source object.

Create a new SourceEncodingNode node.

Create a new SourceFileNode node.

Create a new SourceLineNode node.

Create a new SplatNode node.

Create a new StatementsNode node.

Retrieve the value of one of the StringFlags flags.

Create a new StringNode node.

Create a new SuperNode node.

Retrieve the value of one of the SymbolFlags flags.

Create a new SymbolNode node.

Create a new TrueNode node.

Create a new UndefNode node.

Create a new UnlessNode node.

Create a new UntilNode node.

Create a new WhenNode node.

Create a new WhileNode node.

Create a new XStringNode node.

Create a new YieldNode node.