Class: P2::TagNode
- Inherits:
-
Prism::Node
- Object
- Prism::Node
- P2::TagNode
- Defined in:
- lib/p2/compiler/nodes.rb
Overview
Represents a tag call
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#call_node ⇒ Object
readonly
Returns the value of attribute call_node.
-
#inner_text ⇒ Object
readonly
Returns the value of attribute inner_text.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#tag_location ⇒ Object
readonly
Returns the value of attribute tag_location.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
-
#initialize(call_node, translator) ⇒ TagNode
constructor
A new instance of TagNode.
- #prepare_block(translator) ⇒ Object
Constructor Details
#initialize(call_node, translator) ⇒ TagNode
Returns a new instance of TagNode.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/p2/compiler/nodes.rb', line 21 def initialize(call_node, translator) @call_node = call_node @location = call_node.location @tag = call_node.name prepare_block(translator) args = call_node.arguments&.arguments return if !args if @tag == :tag @tag = args[0] args = args[1..] end if args.size == 1 && args.first.is_a?(Prism::KeywordHashNode) @inner_text = nil @attributes = args.first else @inner_text = args.first @attributes = args[1].is_a?(Prism::KeywordHashNode) ? args[1] : nil end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
19 20 21 |
# File 'lib/p2/compiler/nodes.rb', line 19 def attributes @attributes end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
19 20 21 |
# File 'lib/p2/compiler/nodes.rb', line 19 def block @block end |
#call_node ⇒ Object (readonly)
Returns the value of attribute call_node.
19 20 21 |
# File 'lib/p2/compiler/nodes.rb', line 19 def call_node @call_node end |
#inner_text ⇒ Object (readonly)
Returns the value of attribute inner_text.
19 20 21 |
# File 'lib/p2/compiler/nodes.rb', line 19 def inner_text @inner_text end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
19 20 21 |
# File 'lib/p2/compiler/nodes.rb', line 19 def location @location end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
19 20 21 |
# File 'lib/p2/compiler/nodes.rb', line 19 def tag @tag end |
#tag_location ⇒ Object (readonly)
Returns the value of attribute tag_location.
19 20 21 |
# File 'lib/p2/compiler/nodes.rb', line 19 def tag_location @tag_location end |
Instance Method Details
#accept(visitor) ⇒ Object
44 45 46 |
# File 'lib/p2/compiler/nodes.rb', line 44 def accept(visitor) visitor.visit_tag_node(self) end |
#prepare_block(translator) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/p2/compiler/nodes.rb', line 48 def prepare_block(translator) @block = call_node.block if @block.is_a?(Prism::BlockNode) @block = translator.visit(@block) offset = @location.start_offset length = @block.opening_loc.start_offset - offset @tag_location = @location.copy(start_offset: offset, length: length) else @tag_location = @location end end |