Class: P2::RenderNode

Inherits:
Object
  • Object
show all
Includes:
Prism::DSL
Defined in:
lib/p2/compiler/nodes.rb

Overview

Represents a render call

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(call_node, translator) ⇒ RenderNode

Returns a new instance of RenderNode.



67
68
69
70
71
72
73
74
# File 'lib/p2/compiler/nodes.rb', line 67

def initialize(call_node, translator)
  @call_node = call_node
  @location = call_node.location
  @translator = translator
  @block = call_node.block && translator.visit(call_node.block)

  lambda = call_node.arguments && call_node.arguments.arguments[0]
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



63
64
65
# File 'lib/p2/compiler/nodes.rb', line 63

def block
  @block
end

#call_nodeObject (readonly)

Returns the value of attribute call_node.



63
64
65
# File 'lib/p2/compiler/nodes.rb', line 63

def call_node
  @call_node
end

#locationObject (readonly)

Returns the value of attribute location.



63
64
65
# File 'lib/p2/compiler/nodes.rb', line 63

def location
  @location
end

Instance Method Details

#accept(visitor) ⇒ Object



89
90
91
# File 'lib/p2/compiler/nodes.rb', line 89

def accept(visitor)
  visitor.visit_render_node(self)
end

#ad_hoc_string_location(str) ⇒ Object



76
77
78
79
# File 'lib/p2/compiler/nodes.rb', line 76

def ad_hoc_string_location(str)
  src = source(str)
  Prism::DSL.location(source: src, start_offset: 0, length: str.bytesize)
end

#transform(node) ⇒ Object



81
82
83
# File 'lib/p2/compiler/nodes.rb', line 81

def transform(node)
  node && @translator.visit(node)
end

#transform_array(array) ⇒ Object



85
86
87
# File 'lib/p2/compiler/nodes.rb', line 85

def transform_array(array)
  array ? array.map { @translator.visit(it) } : []
end