Class: WhatDyaReturn::AST::Builder

Inherits:
Parser::Builders::Default
  • Object
show all
Defined in:
lib/what_dya_return/ast/builder.rb

Overview

Constant Summary collapse

NODE_MAP =
{
  def: DefNode,
  begin: BeginNode,
  kwbegin: BeginNode,
  array: ArrayNode,
  return: ReturnNode,
  if: IfNode,
  case: CaseNode,
  when: WhenNode,
  rescue: RescueNode,
  resbody: ResbodyNode,
  ensure: EnsureNode,
  while: WhileNode,
  until: UntilNode,
  for: ForNode,
  break: BreakNode,
  next: NextNode,
  block: BlockNode
}.freeze

Instance Method Summary collapse

Instance Method Details

#n(type, children, source_map) ⇒ Node

NOTE: Reason why wrap with ArrayNode if the node is ‘return` or `break` and has multiple children.

To treat `return 1, 2` like `return [1, 2]`.

Returns:



39
40
41
42
43
# File 'lib/what_dya_return/ast/builder.rb', line 39

def n(type, children, source_map)
  children = [ArrayNode.new(:array, children)] if %i[return break].include?(type) && children.size > 1

  node_klass(type).new(type, children, location: source_map)
end