Class: Herb::AST::RubyLiteralNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_ruby_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) ⇒ RubyLiteralNode
constructor
: (String, Location, Array, String) -> void.
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_ruby_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) ⇒ RubyLiteralNode
: (String, Location, Array, String) -> void
1043 1044 1045 1046 |
# File 'lib/herb/ast/nodes.rb', line 1043 def initialize(type, location, errors, content) super(type, location, errors) @content = content&.force_encoding("utf-8") end |
Instance Attribute Details
#content ⇒ Object (readonly)
: String?
1040 1041 1042 |
# File 'lib/herb/ast/nodes.rb', line 1040 def content @content end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
1056 1057 1058 |
# File 'lib/herb/ast/nodes.rb', line 1056 def accept(visitor) visitor.visit_ruby_literal_node(self) end |
#child_nodes ⇒ Object
: () -> Array
1061 1062 1063 |
# File 'lib/herb/ast/nodes.rb', line 1061 def child_nodes [] end |
#compact_child_nodes ⇒ Object
: () -> Array
1066 1067 1068 |
# File 'lib/herb/ast/nodes.rb', line 1066 def compact_child_nodes child_nodes.compact end |
#inspect ⇒ Object
: () -> String
1071 1072 1073 |
# File 'lib/herb/ast/nodes.rb', line 1071 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_ruby_literal_node
1049 1050 1051 1052 1053 |
# File 'lib/herb/ast/nodes.rb', line 1049 def to_hash super.merge({ content: content, }) #: Herb::serialized_ruby_literal_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 |
# File 'lib/herb/ast/nodes.rb', line 1076 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 |