Class: Herb::AST::ERBCaseMatchNode

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

Overview

: type serialized_erb_case_match_node = { | tag_opening: Herb::Token?, | content: Herb::Token?, | tag_closing: Herb::Token?, | children: Array, | prism_node: String?, | conditions: Array, | else_clause: Herb::AST::ERBElseNode?, | end_node: Herb::AST::ERBEndNode?, | }

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, tag_opening, content, tag_closing, children, prism_node, conditions, else_clause, end_node) ⇒ ERBCaseMatchNode

: (String, Location, Array, Herb::Token, Herb::Token, Herb::Token, Array, String, Array, Herb::AST::ERBElseNode, Herb::AST::ERBEndNode) -> void



2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
# File 'lib/herb/ast/nodes.rb', line 2544

def initialize(type, location, errors, tag_opening, content, tag_closing, children, prism_node, conditions, else_clause, end_node)
  super(type, location, errors)
  @tag_opening = tag_opening
  @content = content
  @tag_closing = tag_closing
  @children = children
  @prism_node = prism_node
  @conditions = conditions
  @else_clause = else_clause
  @end_node = end_node
end

Instance Attribute Details

#childrenObject (readonly)

: Array



2537
2538
2539
# File 'lib/herb/ast/nodes.rb', line 2537

def children
  @children
end

#conditionsObject (readonly)

: Array



2539
2540
2541
# File 'lib/herb/ast/nodes.rb', line 2539

def conditions
  @conditions
end

#contentObject (readonly)

: Herb::Token?



2535
2536
2537
# File 'lib/herb/ast/nodes.rb', line 2535

def content
  @content
end

#else_clauseObject (readonly)

: Herb::AST::ERBElseNode?



2540
2541
2542
# File 'lib/herb/ast/nodes.rb', line 2540

def else_clause
  @else_clause
end

#end_nodeObject (readonly)

: Herb::AST::ERBEndNode?



2541
2542
2543
# File 'lib/herb/ast/nodes.rb', line 2541

def end_node
  @end_node
end

#prism_nodeObject (readonly)

: String?



2538
2539
2540
# File 'lib/herb/ast/nodes.rb', line 2538

def prism_node
  @prism_node
end

#tag_closingObject (readonly)

: Herb::Token?



2536
2537
2538
# File 'lib/herb/ast/nodes.rb', line 2536

def tag_closing
  @tag_closing
end

#tag_openingObject (readonly)

: Herb::Token?



2534
2535
2536
# File 'lib/herb/ast/nodes.rb', line 2534

def tag_opening
  @tag_opening
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



2587
2588
2589
# File 'lib/herb/ast/nodes.rb', line 2587

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

#child_nodesObject

: () -> Array



2592
2593
2594
# File 'lib/herb/ast/nodes.rb', line 2592

def child_nodes
  [*(children || []), *(conditions || []), else_clause, end_node]
end

#compact_child_nodesObject

: () -> Array



2597
2598
2599
# File 'lib/herb/ast/nodes.rb', line 2597

def compact_child_nodes
  child_nodes.compact
end

#deserialized_prism_nodeObject

: () -> Prism::node?



2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
# File 'lib/herb/ast/nodes.rb', line 2557

def deserialized_prism_node
  prism_node = @prism_node
  return nil unless prism_node
  return nil unless source

  begin
    require "prism"
  rescue LoadError
    warn "The 'prism' gem is required to deserialize Prism nodes. Add it to your Gemfile or install it with: gem install prism"
    return nil
  end

  Prism.load(source, prism_node).value
end

#inspectObject

: () -> String



2602
2603
2604
# File 'lib/herb/ast/nodes.rb', line 2602

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

#to_hashObject

: () -> serialized_erb_case_match_node



2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
# File 'lib/herb/ast/nodes.rb', line 2573

def to_hash
  super.merge({
    tag_opening: tag_opening,
    content: content,
    tag_closing: tag_closing,
    children: children,
    prism_node: prism_node,
    conditions: conditions,
    else_clause: else_clause,
    end_node: end_node,
  }) #: Herb::serialized_erb_case_match_node
end

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

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



2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
# File 'lib/herb/ast/nodes.rb', line 2607

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("├── tag_opening: ")
  output += tag_opening ? tag_opening.tree_inspect : magenta("")
  output += "\n"
  output += white("├── content: ")
  output += content ? content.tree_inspect : magenta("")
  output += "\n"
  output += white("├── tag_closing: ")
  output += tag_closing ? tag_closing.tree_inspect : magenta("")
  output += "\n"
  output += white("├── children: ")
  output += inspect_array(children, prefix: "", indent: indent, depth: depth + 1, depth_limit: depth_limit)
  if prism_node && source
    output += white("├── prism_node: ")
    output += Herb::PrismInspect.inspect_prism_serialized(prism_node, source, "")
    output += "\n"
  end
  output += white("├── conditions: ")
  output += inspect_array(conditions, prefix: "", indent: indent, depth: depth + 1, depth_limit: depth_limit)
  output += white("├── else_clause: ")
  if else_clause
    output += "\n"
    output += "│   └── "
    output += else_clause.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("└── end_node: ")
  if end_node
    output += "\n"
    output += "    └── "
    output += end_node.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