Class: Herb::AST::CDATANode

Inherits:
Node
  • Object
show all
Includes:
Colors
Defined in:
lib/herb/ast/nodes.rb,
ext/herb/nodes.c

Overview

: type serialized_cdata_node = { | tag_opening: Herb::Token?, | children: Array, | tag_closing: Herb::Token?, | }

Constant Summary

Constants included from Colors

Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR

Instance Attribute Summary collapse

Attributes inherited from Node

#errors, #location, #source, #type

Instance Method Summary collapse

Methods included from Colors

bold, bright_magenta, cyan, dimmed, enabled?, fg, fg_bg, green, magenta, red, white, yellow

Methods inherited from Node

#class_name, #inspect_array, #inspect_errors, #node_name, #recursive_errors, #to_json

Constructor Details

#initialize(type, location, errors, tag_opening, children, tag_closing) ⇒ CDATANode

: (String, Location, Array, Herb::Token, Array, Herb::Token) -> void



1567
1568
1569
1570
1571
1572
# File 'lib/herb/ast/nodes.rb', line 1567

def initialize(type, location, errors, tag_opening, children, tag_closing)
  super(type, location, errors)
  @tag_opening = tag_opening
  @children = children
  @tag_closing = tag_closing
end

Instance Attribute Details

#childrenObject (readonly)

: Array



1563
1564
1565
# File 'lib/herb/ast/nodes.rb', line 1563

def children
  @children
end

#tag_closingObject (readonly)

: Herb::Token?



1564
1565
1566
# File 'lib/herb/ast/nodes.rb', line 1564

def tag_closing
  @tag_closing
end

#tag_openingObject (readonly)

: Herb::Token?



1562
1563
1564
# File 'lib/herb/ast/nodes.rb', line 1562

def tag_opening
  @tag_opening
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



1584
1585
1586
# File 'lib/herb/ast/nodes.rb', line 1584

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

#child_nodesObject

: () -> Array



1589
1590
1591
# File 'lib/herb/ast/nodes.rb', line 1589

def child_nodes
  [*(children || [])]
end

#compact_child_nodesObject

: () -> Array



1594
1595
1596
# File 'lib/herb/ast/nodes.rb', line 1594

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



1599
1600
1601
# File 'lib/herb/ast/nodes.rb', line 1599

def inspect
  tree_inspect.rstrip.gsub(/\s+$/, "")
end

#to_hashObject

: () -> serialized_cdata_node



1575
1576
1577
1578
1579
1580
1581
# File 'lib/herb/ast/nodes.rb', line 1575

def to_hash
  super.merge({
    tag_opening: tag_opening,
    children: children,
    tag_closing: tag_closing,
  }) #: Herb::serialized_cdata_node
end

#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object

: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String



1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
# File 'lib/herb/ast/nodes.rb', line 1604

def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
  output = +""

  output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
  output += "\n"

  if depth >= depth_limit
    output += dimmed("└── [depth limit reached ...]\n\n")

    return output.gsub(/^/, "    " * indent)
  end

  output += inspect_errors(prefix: "")

  output += white("├── tag_opening: ")
  output += tag_opening ? tag_opening.tree_inspect : magenta("")
  output += "\n"
  output += white("├── children: ")
  output += inspect_array(children, prefix: "", indent: indent, depth: depth + 1, depth_limit: depth_limit)
  output += white("└── tag_closing: ")
  output += tag_closing ? tag_closing.tree_inspect : magenta("")
  output += "\n"
  output += "\n"

  output.gsub(/^/, "    " * indent)
end