Class: Prism::InterpolatedMatchLastLineNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::InterpolatedMatchLastLineNode
- Defined in:
- lib/prism/node.rb,
lib/prism/node_ext.rb,
lib/prism/parse_result/newlines.rb,
sig/generated/prism/node.rbs,
sig/generated/prism/node_ext.rbs,
sig/generated/prism/parse_result/newlines.rbs,
ext/prism/api_node.c
Overview
Represents a regular expression literal that contains interpolation that is being used in the predicate of a conditional to implicitly match against the last line read by an IO object.
if /foo #{bar} baz/ then end
^^^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :interpolated_match_last_line_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#ascii_8bit? ⇒ Boolean
:category: Flags n - forces the ASCII-8BIT encoding.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#closing ⇒ String
:call-seq: closing -> String.
-
#closing_loc ⇒ Location
:category: Locations :call-seq: closing_loc -> Location.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#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) ⇒ InterpolatedMatchLastLineNode
:call-seq: copy(**fields) -> InterpolatedMatchLastLineNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#euc_jp? ⇒ Boolean
:category: Flags e - forces the EUC-JP encoding.
-
#extended? ⇒ Boolean
:category: Flags x - ignores whitespace and allows comments in regular expressions.
-
#forced_binary_encoding? ⇒ Boolean
:category: Flags internal bytes forced the encoding to binary.
-
#forced_us_ascii_encoding? ⇒ Boolean
:category: Flags internal bytes forced the encoding to US-ASCII.
-
#forced_utf8_encoding? ⇒ Boolean
:category: Flags internal bytes forced the encoding to UTF-8.
-
#ignore_case? ⇒ Boolean
:category: Flags i - ignores the case of characters when matching.
-
#initialize(source, node_id, location, flags, opening_loc, parts, closing_loc) ⇒ InterpolatedMatchLastLineNode
constructor
Initialize a new InterpolatedMatchLastLineNode node.
-
#inspect ⇒ String
: () -> String.
-
#multi_line? ⇒ Boolean
:category: Flags m - allows $ to match the end of lines within strings.
-
#newline_flag!(lines) ⇒ void
: (Array lines) -> void.
-
#once? ⇒ Boolean
:category: Flags o - only interpolates values into the regular expression once.
-
#opening ⇒ String
:call-seq: opening -> String.
-
#opening_loc ⇒ Location
:category: Locations :call-seq: opening_loc -> Location.
-
#options ⇒ Integer
Returns a numeric value that represents the flags that were used to create the regular expression.
-
#parts ⇒ Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]
:call-seq: parts -> Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode].
-
#save_closing_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
-
#save_opening_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :interpolated_match_last_line_node
See
Node#type. -
#utf_8? ⇒ Boolean
:category: Flags u - forces the UTF-8 encoding.
-
#windows_31j? ⇒ Boolean
:category: Flags s - forces the Windows-31J encoding.
Constructor Details
#initialize(source, node_id, location, flags, opening_loc, parts, closing_loc) ⇒ InterpolatedMatchLastLineNode
Initialize a new InterpolatedMatchLastLineNode node.
: (Source source, Integer node_id, Location location, Integer flags, Location opening_loc, Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode] parts, Location closing_loc) -> void
19289 19290 19291 19292 19293 19294 19295 19296 19297 |
# File 'lib/prism/node.rb', line 19289 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 |
Class Method Details
.type ⇒ :interpolated_match_last_line_node
See Node.type.
: () -> :interpolated_match_last_line_node
19380 19381 19382 |
# File 'lib/prism/node.rb', line 19380 def self.type :interpolated_match_last_line_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
19558 19559 19560 19561 19562 19563 19564 19565 |
# File 'lib/prism/node.rb', line 19558 def ===(other) # :nodoc: other.is_a?(InterpolatedMatchLastLineNode) && (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
See Node.accept.
: (_Visitor visitor) -> untyped
19313 19314 19315 |
# File 'lib/prism/node.rb', line 19313 def accept(visitor) visitor.visit_interpolated_match_last_line_node(self) end |
#ascii_8bit? ⇒ Boolean
:category: Flags n - forces the ASCII-8BIT encoding
: () -> bool
19435 19436 19437 |
# File 'lib/prism/node.rb', line 19435 def ascii_8bit? flags.anybits?(RegularExpressionFlags::ASCII_8BIT) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
19320 19321 19322 |
# File 'lib/prism/node.rb', line 19320 def child_nodes [*parts] end |
#closing ⇒ String
:call-seq:
closing -> String
Slice the location of closing_loc from the source.
: () -> String
19551 19552 19553 |
# File 'lib/prism/node.rb', line 19551 def closing closing_loc.slice end |
#closing_loc ⇒ Location
:category: Locations :call-seq:
closing_loc -> Location
Returns the Location represented by closing_loc.
: () -> Location
19518 19519 19520 19521 19522 |
# File 'lib/prism/node.rb', line 19518 def closing_loc location = @closing_loc return location if location.is_a?(Location) @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
19337 19338 19339 |
# File 'lib/prism/node.rb', line 19337 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) ⇒ InterpolatedMatchLastLineNode
:call-seq:
copy(**fields) -> InterpolatedMatchLastLineNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?opening_loc: Location, ?parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode], ?closing_loc: Location) -> InterpolatedMatchLastLineNode
19347 19348 19349 |
# File 'lib/prism/node.rb', line 19347 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) InterpolatedMatchLastLineNode.new(source, node_id, location, flags, opening_loc, parts, closing_loc) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
19354 19355 19356 19357 19358 19359 19360 19361 19362 19363 19364 19365 19366 19367 19368 |
# File 'lib/prism/node.rb', line 19354 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location opening_loc parts closing_loc opening closing]).each_with_object( {} #: Hash[Symbol, untyped] ) do |key, deconstructed| case key when :node_id then deconstructed[:node_id] = self.node_id when :location then deconstructed[:location] = self.location when :opening_loc then deconstructed[:opening_loc] = self.opening_loc when :parts then deconstructed[:parts] = self.parts when :closing_loc then deconstructed[:closing_loc] = self.closing_loc when :opening then deconstructed[:opening] = self.opening when :closing then deconstructed[:closing] = self.closing end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
19328 19329 19330 19331 19332 |
# File 'lib/prism/node.rb', line 19328 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? parts.each { |node| yield node } end |
#euc_jp? ⇒ Boolean
:category: Flags e - forces the EUC-JP encoding
: () -> bool
19427 19428 19429 |
# File 'lib/prism/node.rb', line 19427 def euc_jp? flags.anybits?(RegularExpressionFlags::EUC_JP) end |
#extended? ⇒ Boolean
:category: Flags x - ignores whitespace and allows comments in regular expressions
: () -> bool
19403 19404 19405 |
# File 'lib/prism/node.rb', line 19403 def extended? flags.anybits?(RegularExpressionFlags::EXTENDED) end |
#forced_binary_encoding? ⇒ Boolean
:category: Flags internal bytes forced the encoding to binary
: () -> bool
19467 19468 19469 |
# File 'lib/prism/node.rb', line 19467 def forced_binary_encoding? flags.anybits?(RegularExpressionFlags::FORCED_BINARY_ENCODING) end |
#forced_us_ascii_encoding? ⇒ Boolean
:category: Flags internal bytes forced the encoding to US-ASCII
: () -> bool
19475 19476 19477 |
# File 'lib/prism/node.rb', line 19475 def forced_us_ascii_encoding? flags.anybits?(RegularExpressionFlags::FORCED_US_ASCII_ENCODING) end |
#forced_utf8_encoding? ⇒ Boolean
:category: Flags internal bytes forced the encoding to UTF-8
: () -> bool
19459 19460 19461 |
# File 'lib/prism/node.rb', line 19459 def forced_utf8_encoding? flags.anybits?(RegularExpressionFlags::FORCED_UTF8_ENCODING) end |
#ignore_case? ⇒ Boolean
:category: Flags i - ignores the case of characters when matching
: () -> bool
19395 19396 19397 |
# File 'lib/prism/node.rb', line 19395 def ignore_case? flags.anybits?(RegularExpressionFlags::IGNORE_CASE) end |
#inspect ⇒ String
: () -> String
19385 19386 19387 |
# File 'lib/prism/node.rb', line 19385 def inspect # :nodoc: InspectVisitor.compose(self) end |
#multi_line? ⇒ Boolean
:category: Flags m - allows $ to match the end of lines within strings
: () -> bool
19411 19412 19413 |
# File 'lib/prism/node.rb', line 19411 def multi_line? flags.anybits?(RegularExpressionFlags::MULTI_LINE) end |
#newline_flag!(lines) ⇒ void
This method returns an undefined value.
: (Array lines) -> void
382 383 384 385 |
# File 'lib/prism/parse_result/newlines.rb', line 382 def newline_flag!(lines) # :nodoc: first = parts.first first.newline_flag!(lines) if first end |
#once? ⇒ Boolean
:category: Flags o - only interpolates values into the regular expression once
: () -> bool
19419 19420 19421 |
# File 'lib/prism/node.rb', line 19419 def once? flags.anybits?(RegularExpressionFlags::ONCE) end |
#opening ⇒ String
:call-seq:
opening -> String
Slice the location of opening_loc from the source.
: () -> String
19541 19542 19543 |
# File 'lib/prism/node.rb', line 19541 def opening opening_loc.slice end |
#opening_loc ⇒ Location
:category: Locations :call-seq:
opening_loc -> Location
Returns the Location represented by opening_loc.
: () -> Location
19486 19487 19488 19489 19490 |
# File 'lib/prism/node.rb', line 19486 def opening_loc location = @opening_loc return location if location.is_a?(Location) @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#options ⇒ Integer
Returns a numeric value that represents the flags that were used to create the regular expression.
: () -> Integer
46 47 48 |
# File 'lib/prism/node_ext.rb', line 46 def RegularExpressionOptions.(flags) end |
#parts ⇒ Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]
:call-seq:
parts -> Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]
Returns the parts attribute.
: () -> Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]
19507 19508 19509 |
# File 'lib/prism/node.rb', line 19507 def parts @parts end |
#save_closing_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the closing_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
19529 19530 19531 |
# File 'lib/prism/node.rb', line 19529 def save_closing_loc(repository) repository.enter(node_id, :closing_loc) end |
#save_opening_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the opening_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
19497 19498 19499 |
# File 'lib/prism/node.rb', line 19497 def save_opening_loc(repository) repository.enter(node_id, :opening_loc) end |
#type ⇒ :interpolated_match_last_line_node
See Node#type.
: () -> :interpolated_match_last_line_node
19373 19374 19375 |
# File 'lib/prism/node.rb', line 19373 def type :interpolated_match_last_line_node end |
#utf_8? ⇒ Boolean
:category: Flags u - forces the UTF-8 encoding
: () -> bool
19451 19452 19453 |
# File 'lib/prism/node.rb', line 19451 def utf_8? flags.anybits?(RegularExpressionFlags::UTF_8) end |
#windows_31j? ⇒ Boolean
:category: Flags s - forces the Windows-31J encoding
: () -> bool
19443 19444 19445 |
# File 'lib/prism/node.rb', line 19443 def windows_31j? flags.anybits?(RegularExpressionFlags::WINDOWS_31J) end |