Class: Herb::AST::RubyRenderLocalNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_ruby_render_local_node = { | name: Herb::Token?, | value: Herb::AST::RubyLiteralNode?, | }
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
: Herb::Token?.
-
#value ⇒ Object
readonly
: Herb::AST::RubyLiteralNode?.
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, name, value) ⇒ RubyRenderLocalNode
constructor
: (String, Location, Array, Herb::Token, Herb::AST::RubyLiteralNode) -> void.
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_ruby_render_local_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, name, value) ⇒ RubyRenderLocalNode
: (String, Location, Array, Herb::Token, Herb::AST::RubyLiteralNode) -> void
3519 3520 3521 3522 3523 |
# File 'lib/herb/ast/nodes.rb', line 3519 def initialize(type, location, errors, name, value) super(type, location, errors) @name = name @value = value end |
Instance Attribute Details
#name ⇒ Object (readonly)
: Herb::Token?
3515 3516 3517 |
# File 'lib/herb/ast/nodes.rb', line 3515 def name @name end |
#value ⇒ Object (readonly)
: Herb::AST::RubyLiteralNode?
3516 3517 3518 |
# File 'lib/herb/ast/nodes.rb', line 3516 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
3534 3535 3536 |
# File 'lib/herb/ast/nodes.rb', line 3534 def accept(visitor) visitor.visit_ruby_render_local_node(self) end |
#child_nodes ⇒ Object
: () -> Array
3539 3540 3541 |
# File 'lib/herb/ast/nodes.rb', line 3539 def child_nodes [value] end |
#compact_child_nodes ⇒ Object
: () -> Array
3544 3545 3546 |
# File 'lib/herb/ast/nodes.rb', line 3544 def compact_child_nodes child_nodes.compact end |
#inspect ⇒ Object
: () -> String
3549 3550 3551 |
# File 'lib/herb/ast/nodes.rb', line 3549 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_ruby_render_local_node
3526 3527 3528 3529 3530 3531 |
# File 'lib/herb/ast/nodes.rb', line 3526 def to_hash super.merge({ name: name, value: value, }) #: Herb::serialized_ruby_render_local_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 |
# File 'lib/herb/ast/nodes.rb', line 3554 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("├── name: ") output += name ? name.tree_inspect : magenta("∅") output += "\n" output += white("└── value: ") if value output += "\n" output += " └── " output += value.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ") else output += magenta("∅\n") end output += "\n" output.gsub(/^/, " " * indent) end |