Class: Prism::InterpolatedRegularExpressionNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::InterpolatedRegularExpressionNode
- Defined in:
- lib/prism/node.rb,
lib/prism/node_ext.rb,
lib/prism/parse_result/newlines.rb,
ext/prism/api_node.c
Overview
Represents a regular expression literal that contains interpolation.
/foo #{bar} baz/
^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode].
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.
-
#ascii_8bit? ⇒ Boolean
def ascii_8bit?: () -> bool.
-
#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, parts: self.parts, closing_loc: self.closing_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], ?closing_loc: Location) -> InterpolatedRegularExpressionNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location, parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], closing_loc: Location }.
-
#each_child_node ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#euc_jp? ⇒ Boolean
def euc_jp?: () -> bool.
-
#extended? ⇒ Boolean
def extended?: () -> bool.
-
#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.
-
#ignore_case? ⇒ Boolean
def ignore_case?: () -> bool.
-
#initialize(source, node_id, location, flags, opening_loc, parts, closing_loc) ⇒ InterpolatedRegularExpressionNode
constructor
Initialize a new InterpolatedRegularExpressionNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#multi_line? ⇒ Boolean
def multi_line?: () -> bool.
-
#newline_flag!(lines) ⇒ Object
:nodoc:.
-
#once? ⇒ Boolean
def once?: () -> bool.
-
#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.
-
#type ⇒ Object
Return a symbol representation of this node type.
-
#utf_8? ⇒ Boolean
def utf_8?: () -> bool.
-
#windows_31j? ⇒ Boolean
def windows_31j?: () -> bool.
Constructor Details
#initialize(source, node_id, location, flags, opening_loc, parts, closing_loc) ⇒ InterpolatedRegularExpressionNode
Initialize a new InterpolatedRegularExpressionNode node.
11423 11424 11425 11426 11427 11428 11429 11430 11431 |
# File 'lib/prism/node.rb', line 11423 def initialize(source, node_id, location, flags, opening_loc, parts, closing_loc) @source = source @node_id = node_id @location = location @flags = flags @opening_loc = opening_loc @parts = parts @closing_loc = closing_loc end |
Instance Attribute Details
#parts ⇒ Object (readonly)
attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]
11542 11543 11544 |
# File 'lib/prism/node.rb', line 11542 def parts @parts end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See Node::type.
11578 11579 11580 |
# File 'lib/prism/node.rb', line 11578 def self.type :interpolated_regular_expression_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.
11584 11585 11586 11587 11588 11589 11590 11591 |
# File 'lib/prism/node.rb', line 11584 def ===(other) other.is_a?(InterpolatedRegularExpressionNode) && (flags === other.flags) && (opening_loc.nil? == other.opening_loc.nil?) && (parts.length == other.parts.length) && parts.zip(other.parts).all? { |left, right| left === right } && (closing_loc.nil? == other.closing_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
11434 11435 11436 |
# File 'lib/prism/node.rb', line 11434 def accept(visitor) visitor.visit_interpolated_regular_expression_node(self) end |
#ascii_8bit? ⇒ Boolean
def ascii_8bit?: () -> bool
11499 11500 11501 |
# File 'lib/prism/node.rb', line 11499 def ascii_8bit? flags.anybits?(RegularExpressionFlags::ASCII_8BIT) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
11439 11440 11441 |
# File 'lib/prism/node.rb', line 11439 def child_nodes [*parts] end |
#closing ⇒ Object
def closing: () -> String
11563 11564 11565 |
# File 'lib/prism/node.rb', line 11563 def closing closing_loc.slice end |
#closing_loc ⇒ Object
attr_reader closing_loc: Location
11545 11546 11547 11548 11549 |
# File 'lib/prism/node.rb', line 11545 def closing_loc location = @closing_loc return location if location.is_a?(Location) @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
11456 11457 11458 |
# File 'lib/prism/node.rb', line 11456 def comment_targets [opening_loc, *parts, closing_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
11451 11452 11453 |
# File 'lib/prism/node.rb', line 11451 def compact_child_nodes [*parts] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], ?closing_loc: Location) -> InterpolatedRegularExpressionNode
11461 11462 11463 |
# File 'lib/prism/node.rb', line 11461 def copy(node_id: self.node_id, location: self.location, flags: self.flags, opening_loc: self.opening_loc, parts: self.parts, closing_loc: self.closing_loc) InterpolatedRegularExpressionNode.new(source, node_id, location, flags, opening_loc, parts, closing_loc) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, opening_loc: Location, parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], closing_loc: Location }
11469 11470 11471 |
# File 'lib/prism/node.rb', line 11469 def deconstruct_keys(keys) { node_id: node_id, location: location, opening_loc: opening_loc, parts: parts, closing_loc: closing_loc } end |
#each_child_node ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator
11444 11445 11446 11447 11448 |
# File 'lib/prism/node.rb', line 11444 def each_child_node return to_enum(:each_child_node) unless block_given? parts.each { |node| yield node } end |
#euc_jp? ⇒ Boolean
def euc_jp?: () -> bool
11494 11495 11496 |
# File 'lib/prism/node.rb', line 11494 def euc_jp? flags.anybits?(RegularExpressionFlags::EUC_JP) end |
#extended? ⇒ Boolean
def extended?: () -> bool
11479 11480 11481 |
# File 'lib/prism/node.rb', line 11479 def extended? flags.anybits?(RegularExpressionFlags::EXTENDED) end |
#forced_binary_encoding? ⇒ Boolean
def forced_binary_encoding?: () -> bool
11519 11520 11521 |
# File 'lib/prism/node.rb', line 11519 def forced_binary_encoding? flags.anybits?(RegularExpressionFlags::FORCED_BINARY_ENCODING) end |
#forced_us_ascii_encoding? ⇒ Boolean
def forced_us_ascii_encoding?: () -> bool
11524 11525 11526 |
# File 'lib/prism/node.rb', line 11524 def forced_us_ascii_encoding? flags.anybits?(RegularExpressionFlags::FORCED_US_ASCII_ENCODING) end |
#forced_utf8_encoding? ⇒ Boolean
def forced_utf8_encoding?: () -> bool
11514 11515 11516 |
# File 'lib/prism/node.rb', line 11514 def forced_utf8_encoding? flags.anybits?(RegularExpressionFlags::FORCED_UTF8_ENCODING) end |
#ignore_case? ⇒ Boolean
def ignore_case?: () -> bool
11474 11475 11476 |
# File 'lib/prism/node.rb', line 11474 def ignore_case? flags.anybits?(RegularExpressionFlags::IGNORE_CASE) end |
#inspect ⇒ Object
def inspect -> String
11568 11569 11570 |
# File 'lib/prism/node.rb', line 11568 def inspect InspectVisitor.compose(self) end |
#multi_line? ⇒ Boolean
def multi_line?: () -> bool
11484 11485 11486 |
# File 'lib/prism/node.rb', line 11484 def multi_line? flags.anybits?(RegularExpressionFlags::MULTI_LINE) end |
#newline_flag!(lines) ⇒ Object
:nodoc:
129 130 131 132 |
# File 'lib/prism/parse_result/newlines.rb', line 129 def newline_flag!(lines) # :nodoc: first = parts.first first.newline_flag!(lines) if first end |
#once? ⇒ Boolean
def once?: () -> bool
11489 11490 11491 |
# File 'lib/prism/node.rb', line 11489 def once? flags.anybits?(RegularExpressionFlags::ONCE) end |
#opening ⇒ Object
def opening: () -> String
11558 11559 11560 |
# File 'lib/prism/node.rb', line 11558 def opening opening_loc.slice end |
#opening_loc ⇒ Object
attr_reader opening_loc: Location
11529 11530 11531 11532 11533 |
# File 'lib/prism/node.rb', line 11529 def opening_loc location = @opening_loc return location if location.is_a?(Location) @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#save_closing_loc(repository) ⇒ Object
Save the closing_loc location using the given saved source so that it can be retrieved later.
11553 11554 11555 |
# File 'lib/prism/node.rb', line 11553 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) end |
#save_opening_loc(repository) ⇒ Object
Save the opening_loc location using the given saved source so that it can be retrieved later.
11537 11538 11539 |
# File 'lib/prism/node.rb', line 11537 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
11573 11574 11575 |
# File 'lib/prism/node.rb', line 11573 def type :interpolated_regular_expression_node end |
#utf_8? ⇒ Boolean
def utf_8?: () -> bool
11509 11510 11511 |
# File 'lib/prism/node.rb', line 11509 def utf_8? flags.anybits?(RegularExpressionFlags::UTF_8) end |
#windows_31j? ⇒ Boolean
def windows_31j?: () -> bool
11504 11505 11506 |
# File 'lib/prism/node.rb', line 11504 def windows_31j? flags.anybits?(RegularExpressionFlags::WINDOWS_31J) end |