Class: Prism::SymbolNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents a symbol literal or a symbol contained within a ‘%i` list.

:foo
^^^^

%i[foo]
   ^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped) ⇒ SymbolNode

Initialize a new SymbolNode node.



15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
# File 'lib/prism/node.rb', line 15557

def initialize(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @opening_loc = opening_loc
  @value_loc = value_loc
  @closing_loc = closing_loc
  @unescaped = unescaped
end

Instance Attribute Details

#unescapedObject (readonly)

attr_reader unescaped: String



15656
15657
15658
# File 'lib/prism/node.rb', line 15656

def unescaped
  @unescaped
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



15684
15685
15686
# File 'lib/prism/node.rb', line 15684

def self.type
  :symbol_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



15690
15691
15692
15693
15694
15695
15696
15697
# File 'lib/prism/node.rb', line 15690

def ===(other)
  other.is_a?(SymbolNode) &&
    (flags === other.flags) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (value_loc.nil? == other.value_loc.nil?) &&
    (closing_loc.nil? == other.closing_loc.nil?) &&
    (unescaped === other.unescaped)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



15569
15570
15571
# File 'lib/prism/node.rb', line 15569

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



15574
15575
15576
# File 'lib/prism/node.rb', line 15574

def child_nodes
  []
end

#closingObject

def closing: () -> String?



15669
15670
15671
# File 'lib/prism/node.rb', line 15669

def closing
  closing_loc&.slice
end

#closing_locObject

attr_reader closing_loc: Location?



15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
# File 'lib/prism/node.rb', line 15643

def closing_loc
  location = @closing_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



15584
15585
15586
# File 'lib/prism/node.rb', line 15584

def comment_targets
  [*opening_loc, *value_loc, *closing_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



15579
15580
15581
# File 'lib/prism/node.rb', line 15579

def compact_child_nodes
  []
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, value_loc: self.value_loc, closing_loc: self.closing_loc, unescaped: self.unescaped) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location?, ?value_loc: Location?, ?closing_loc: Location?, ?unescaped: String) -> SymbolNode



15589
15590
15591
# File 'lib/prism/node.rb', line 15589

def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, value_loc: self.value_loc, closing_loc: self.closing_loc, unescaped: self.unescaped)
  SymbolNode.new(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location?, value_loc: Location?, closing_loc: Location?, unescaped: String }



15597
15598
15599
# File 'lib/prism/node.rb', line 15597

def deconstruct_keys(keys)
  { node_id: node_id, location: location, opening_loc: opening_loc, value_loc: value_loc, closing_loc: closing_loc, unescaped: unescaped }
end

#forced_binary_encoding?Boolean

def forced_binary_encoding?: () -> bool

Returns:

  • (Boolean)


15607
15608
15609
# File 'lib/prism/node.rb', line 15607

def forced_binary_encoding?
  flags.anybits?(SymbolFlags::FORCED_BINARY_ENCODING)
end

#forced_us_ascii_encoding?Boolean

def forced_us_ascii_encoding?: () -> bool

Returns:

  • (Boolean)


15612
15613
15614
# File 'lib/prism/node.rb', line 15612

def forced_us_ascii_encoding?
  flags.anybits?(SymbolFlags::FORCED_US_ASCII_ENCODING)
end

#forced_utf8_encoding?Boolean

def forced_utf8_encoding?: () -> bool

Returns:

  • (Boolean)


15602
15603
15604
# File 'lib/prism/node.rb', line 15602

def forced_utf8_encoding?
  flags.anybits?(SymbolFlags::FORCED_UTF8_ENCODING)
end

#inspectObject

def inspect -> String



15674
15675
15676
# File 'lib/prism/node.rb', line 15674

def inspect
  InspectVisitor.compose(self)
end

#openingObject

def opening: () -> String?



15659
15660
15661
# File 'lib/prism/node.rb', line 15659

def opening
  opening_loc&.slice
end

#opening_locObject

attr_reader opening_loc: Location?



15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
# File 'lib/prism/node.rb', line 15617

def opening_loc
  location = @opening_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



15679
15680
15681
# File 'lib/prism/node.rb', line 15679

def type
  :symbol_node
end

#valueObject

def value: () -> String?



15664
15665
15666
# File 'lib/prism/node.rb', line 15664

def value
  value_loc&.slice
end

#value_locObject

attr_reader value_loc: Location?



15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
# File 'lib/prism/node.rb', line 15630

def value_loc
  location = @value_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @value_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end