Class: Herb::AST::RubyParameterNode

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

Overview

: type serialized_ruby_parameter_node = { | name: Herb::Token?, | default_value: Herb::AST::RubyLiteralNode?, | kind: String?, | required: bool, | }

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, name, default_value, kind, required) ⇒ RubyParameterNode

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



3963
3964
3965
3966
3967
3968
3969
# File 'lib/herb/ast/nodes.rb', line 3963

def initialize(type, location, errors, name, default_value, kind, required)
  super(type, location, errors)
  @name = name
  @default_value = default_value
  @kind = kind&.force_encoding("utf-8")
  @required = required
end

Instance Attribute Details

#default_valueObject (readonly)

: Herb::AST::RubyLiteralNode?



3958
3959
3960
# File 'lib/herb/ast/nodes.rb', line 3958

def default_value
  @default_value
end

#kindObject (readonly)

: String?



3959
3960
3961
# File 'lib/herb/ast/nodes.rb', line 3959

def kind
  @kind
end

#nameObject (readonly)

: Herb::Token?



3957
3958
3959
# File 'lib/herb/ast/nodes.rb', line 3957

def name
  @name
end

#requiredObject (readonly)

: bool



3960
3961
3962
# File 'lib/herb/ast/nodes.rb', line 3960

def required
  @required
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



3982
3983
3984
# File 'lib/herb/ast/nodes.rb', line 3982

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

#child_nodesObject

: () -> Array



3987
3988
3989
# File 'lib/herb/ast/nodes.rb', line 3987

def child_nodes
  [default_value]
end

#compact_child_nodesObject

: () -> Array



3992
3993
3994
# File 'lib/herb/ast/nodes.rb', line 3992

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



3997
3998
3999
# File 'lib/herb/ast/nodes.rb', line 3997

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

#to_hashObject

: () -> serialized_ruby_parameter_node



3972
3973
3974
3975
3976
3977
3978
3979
# File 'lib/herb/ast/nodes.rb', line 3972

def to_hash
  super.merge({
    name: name,
    default_value: default_value,
    kind: kind,
    required: required,
  }) #: Herb::serialized_ruby_parameter_node
end

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

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



4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
# File 'lib/herb/ast/nodes.rb', line 4002

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("├── default_value: ")
  if default_value
    output += "\n"
    output += "│   └── "
    output += default_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 += white("├── kind: ") + green("#{kind.inspect}\n")
  output += white("└── required: ")
  output += [true, false].include?(required) ? bold(magenta(required.to_s)) : magenta("")
  output += "\n"
  output += "\n"

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