Class: Herb::AST::WhitespaceNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_whitespace_node = { | value: Herb::Token?, | }
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
: Herb::Token?.
Attributes inherited from Node
#errors, #location, #source, #type
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
: (Visitor) -> void.
-
#child_nodes ⇒ Object
: () -> Array.
-
#compact_child_nodes ⇒ Object
: () -> Array.
-
#initialize(type, location, errors, value) ⇒ WhitespaceNode
constructor
: (String, Location, Array, Herb::Token) -> void.
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_whitespace_node.
-
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String.
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, value) ⇒ WhitespaceNode
: (String, Location, Array, Herb::Token) -> void
1641 1642 1643 1644 |
# File 'lib/herb/ast/nodes.rb', line 1641 def initialize(type, location, errors, value) super(type, location, errors) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
: Herb::Token?
1638 1639 1640 |
# File 'lib/herb/ast/nodes.rb', line 1638 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
1654 1655 1656 |
# File 'lib/herb/ast/nodes.rb', line 1654 def accept(visitor) visitor.visit_whitespace_node(self) end |
#child_nodes ⇒ Object
: () -> Array
1659 1660 1661 |
# File 'lib/herb/ast/nodes.rb', line 1659 def child_nodes [] end |
#compact_child_nodes ⇒ Object
: () -> Array
1664 1665 1666 |
# File 'lib/herb/ast/nodes.rb', line 1664 def compact_child_nodes child_nodes.compact end |
#inspect ⇒ Object
: () -> String
1669 1670 1671 |
# File 'lib/herb/ast/nodes.rb', line 1669 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_whitespace_node
1647 1648 1649 1650 1651 |
# File 'lib/herb/ast/nodes.rb', line 1647 def to_hash super.merge({ value: value, }) #: Herb::serialized_whitespace_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 |
# File 'lib/herb/ast/nodes.rb', line 1674 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("└── value: ") output += value ? value.tree_inspect : magenta("∅") output += "\n" output += "\n" output.gsub(/^/, " " * indent) end |