Class: Herb::AST::LiteralNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_literal_node = { | content: String?, | }
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
: String?.
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, content) ⇒ LiteralNode
constructor
: (String, Location, Array, String) -> void.
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_literal_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, content) ⇒ LiteralNode
: (String, Location, Array, String) -> void
115 116 117 118 |
# File 'lib/herb/ast/nodes.rb', line 115 def initialize(type, location, errors, content) super(type, location, errors) @content = content&.force_encoding("utf-8") end |
Instance Attribute Details
#content ⇒ Object (readonly)
: String?
112 113 114 |
# File 'lib/herb/ast/nodes.rb', line 112 def content @content end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
128 129 130 |
# File 'lib/herb/ast/nodes.rb', line 128 def accept(visitor) visitor.visit_literal_node(self) end |
#child_nodes ⇒ Object
: () -> Array
133 134 135 |
# File 'lib/herb/ast/nodes.rb', line 133 def child_nodes [] end |
#compact_child_nodes ⇒ Object
: () -> Array
138 139 140 |
# File 'lib/herb/ast/nodes.rb', line 138 def compact_child_nodes child_nodes.compact end |
#inspect ⇒ Object
: () -> String
143 144 145 |
# File 'lib/herb/ast/nodes.rb', line 143 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_literal_node
121 122 123 124 125 |
# File 'lib/herb/ast/nodes.rb', line 121 def to_hash super.merge({ content: content, }) #: Herb::serialized_literal_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/herb/ast/nodes.rb', line 148 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("└── content: ") + green("#{content.inspect}\n") output += "\n" output.gsub(/^/, " " * indent) end |