Class: Prism::SymbolNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::SymbolNode
- 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
-
#unescaped ⇒ Object
readonly
attr_reader unescaped: String.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#closing ⇒ Object
def closing: () -> String?.
-
#closing_loc ⇒ Object
attr_reader closing_loc: Location?.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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.
-
#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 }.
-
#each_child_node ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#forced_binary_encoding? ⇒ Boolean
def forced_binary_encoding?: () -> bool.
-
#forced_us_ascii_encoding? ⇒ Boolean
def forced_us_ascii_encoding?: () -> bool.
-
#forced_utf8_encoding? ⇒ Boolean
def forced_utf8_encoding?: () -> bool.
-
#initialize(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped) ⇒ SymbolNode
constructor
Initialize a new SymbolNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#opening ⇒ Object
def opening: () -> String?.
-
#opening_loc ⇒ Object
attr_reader opening_loc: Location?.
-
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Object
Save the opening_loc location using the given saved source so that it can be retrieved later.
-
#save_value_loc(repository) ⇒ Object
Save the value_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
-
#value ⇒ Object
def value: () -> String?.
-
#value_loc ⇒ Object
attr_reader value_loc: Location?.
Constructor Details
#initialize(source, node_id, location, flags, opening_loc, value_loc, closing_loc, unescaped) ⇒ SymbolNode
Initialize a new SymbolNode node.
18459 18460 18461 18462 18463 18464 18465 18466 18467 18468 |
# File 'lib/prism/node.rb', line 18459 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
#unescaped ⇒ Object (readonly)
attr_reader unescaped: String
18582 18583 18584 |
# File 'lib/prism/node.rb', line 18582 def unescaped @unescaped end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
18610 18611 18612 |
# File 'lib/prism/node.rb', line 18610 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.
18616 18617 18618 18619 18620 18621 18622 18623 |
# File 'lib/prism/node.rb', line 18616 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
18471 18472 18473 |
# File 'lib/prism/node.rb', line 18471 def accept(visitor) visitor.visit_symbol_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
18476 18477 18478 |
# File 'lib/prism/node.rb', line 18476 def child_nodes [] end |
#closing ⇒ Object
def closing: () -> String?
18595 18596 18597 |
# File 'lib/prism/node.rb', line 18595 def closing closing_loc&.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location?
18563 18564 18565 18566 18567 18568 18569 18570 18571 18572 18573 |
# File 'lib/prism/node.rb', line 18563 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_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
18492 18493 18494 |
# File 'lib/prism/node.rb', line 18492 def comment_targets [*opening_loc, *value_loc, *closing_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
18487 18488 18489 |
# File 'lib/prism/node.rb', line 18487 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
18497 18498 18499 |
# File 'lib/prism/node.rb', line 18497 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 }
18505 18506 18507 |
# File 'lib/prism/node.rb', line 18505 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 |
#each_child_node ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator
18481 18482 18483 18484 |
# File 'lib/prism/node.rb', line 18481 def each_child_node return to_enum(:each_child_node) unless block_given? end |
#forced_binary_encoding? ⇒ Boolean
def forced_binary_encoding?: () -> bool
18515 18516 18517 |
# File 'lib/prism/node.rb', line 18515 def forced_binary_encoding? flags.anybits?(SymbolFlags::FORCED_BINARY_ENCODING) end |
#forced_us_ascii_encoding? ⇒ Boolean
def forced_us_ascii_encoding?: () -> bool
18520 18521 18522 |
# File 'lib/prism/node.rb', line 18520 def forced_us_ascii_encoding? flags.anybits?(SymbolFlags::FORCED_US_ASCII_ENCODING) end |
#forced_utf8_encoding? ⇒ Boolean
def forced_utf8_encoding?: () -> bool
18510 18511 18512 |
# File 'lib/prism/node.rb', line 18510 def forced_utf8_encoding? flags.anybits?(SymbolFlags::FORCED_UTF8_ENCODING) end |
#inspect ⇒ Object
def inspect -> String
18600 18601 18602 |
# File 'lib/prism/node.rb', line 18600 def inspect InspectVisitor.compose(self) end |
#opening ⇒ Object
def opening: () -> String?
18585 18586 18587 |
# File 'lib/prism/node.rb', line 18585 def opening opening_loc&.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location?
18525 18526 18527 18528 18529 18530 18531 18532 18533 18534 18535 |
# File 'lib/prism/node.rb', line 18525 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 |
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
18577 18578 18579 |
# File 'lib/prism/node.rb', line 18577 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) unless @closing_loc.nil? end |
#save_opening_loc(repository) ⇒ Object
Save the opening_loc location using the given saved source so that it can be retrieved later.
18539 18540 18541 |
# File 'lib/prism/node.rb', line 18539 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) unless @opening_loc.nil? end |
#save_value_loc(repository) ⇒ Object
Save the value_loc location using the given saved source so that it can be retrieved later.
18558 18559 18560 |
# File 'lib/prism/node.rb', line 18558 def save_value_loc(repository) repository.enter(node_id, :value_loc) unless @value_loc.nil? end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
18605 18606 18607 |
# File 'lib/prism/node.rb', line 18605 def type :symbol_node end |
#value ⇒ Object
def value: () -> String?
18590 18591 18592 |
# File 'lib/prism/node.rb', line 18590 def value value_loc&.slice end |
#value_loc ⇒ Object
attr_reader value_loc: Location?
18544 18545 18546 18547 18548 18549 18550 18551 18552 18553 18554 |
# File 'lib/prism/node.rb', line 18544 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 |