Class: Prism::InterpolatedRegularExpressionNode

Inherits:
PrismNode
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, opening_loc, parts, closing_loc) ⇒ InterpolatedRegularExpressionNode

Initialize a new InterpolatedRegularExpressionNode node.



9513
9514
9515
9516
9517
9518
9519
9520
9521
# File 'lib/prism/node.rb', line 9513

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

#partsObject (readonly)

attr_reader parts: Array[StringNode | EmbeddedStatementsNode | EmbeddedVariableNode]



9619
9620
9621
# File 'lib/prism/node.rb', line 9619

def parts
  @parts
end

Class Method Details

.typeObject

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



9649
9650
9651
# File 'lib/prism/node.rb', line 9649

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.



9655
9656
9657
9658
9659
9660
9661
9662
# File 'lib/prism/node.rb', line 9655

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



9524
9525
9526
# File 'lib/prism/node.rb', line 9524

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

#ascii_8bit?Boolean

def ascii_8bit?: () -> bool

Returns:

  • (Boolean)


9582
9583
9584
# File 'lib/prism/node.rb', line 9582

def ascii_8bit?
  flags.anybits?(RegularExpressionFlags::ASCII_8BIT)
end

#child_nodesObject Also known as: deconstruct

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



9529
9530
9531
# File 'lib/prism/node.rb', line 9529

def child_nodes
  [*parts]
end

#closingObject

def closing: () -> String



9634
9635
9636
# File 'lib/prism/node.rb', line 9634

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



9622
9623
9624
9625
9626
# File 'lib/prism/node.rb', line 9622

def closing_loc
  location = @closing_loc
  return location if location.is_a?(Location)
  @closing_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#comment_targetsObject

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



9539
9540
9541
# File 'lib/prism/node.rb', line 9539

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



9534
9535
9536
# File 'lib/prism/node.rb', line 9534

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



9544
9545
9546
# File 'lib/prism/node.rb', line 9544

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 }



9552
9553
9554
# File 'lib/prism/node.rb', line 9552

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

#euc_jp?Boolean

def euc_jp?: () -> bool

Returns:

  • (Boolean)


9577
9578
9579
# File 'lib/prism/node.rb', line 9577

def euc_jp?
  flags.anybits?(RegularExpressionFlags::EUC_JP)
end

#extended?Boolean

def extended?: () -> bool

Returns:

  • (Boolean)


9562
9563
9564
# File 'lib/prism/node.rb', line 9562

def extended?
  flags.anybits?(RegularExpressionFlags::EXTENDED)
end

#forced_binary_encoding?Boolean

def forced_binary_encoding?: () -> bool

Returns:

  • (Boolean)


9602
9603
9604
# File 'lib/prism/node.rb', line 9602

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

#forced_us_ascii_encoding?Boolean

def forced_us_ascii_encoding?: () -> bool

Returns:

  • (Boolean)


9607
9608
9609
# File 'lib/prism/node.rb', line 9607

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

#forced_utf8_encoding?Boolean

def forced_utf8_encoding?: () -> bool

Returns:

  • (Boolean)


9597
9598
9599
# File 'lib/prism/node.rb', line 9597

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

#ignore_case?Boolean

def ignore_case?: () -> bool

Returns:

  • (Boolean)


9557
9558
9559
# File 'lib/prism/node.rb', line 9557

def ignore_case?
  flags.anybits?(RegularExpressionFlags::IGNORE_CASE)
end

#inspectObject

def inspect -> String



9639
9640
9641
# File 'lib/prism/node.rb', line 9639

def inspect
  InspectVisitor.compose(self)
end

#multi_line?Boolean

def multi_line?: () -> bool

Returns:

  • (Boolean)


9567
9568
9569
# File 'lib/prism/node.rb', line 9567

def multi_line?
  flags.anybits?(RegularExpressionFlags::MULTI_LINE)
end

#newline_flag!(lines) ⇒ Object

:nodoc:



128
129
130
131
# File 'lib/prism/parse_result/newlines.rb', line 128

def newline_flag!(lines) # :nodoc:
  first = parts.first
  first.newline_flag!(lines) if first
end

#once?Boolean

def once?: () -> bool

Returns:

  • (Boolean)


9572
9573
9574
# File 'lib/prism/node.rb', line 9572

def once?
  flags.anybits?(RegularExpressionFlags::ONCE)
end

#openingObject

def opening: () -> String



9629
9630
9631
# File 'lib/prism/node.rb', line 9629

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



9612
9613
9614
9615
9616
# File 'lib/prism/node.rb', line 9612

def opening_loc
  location = @opening_loc
  return location if location.is_a?(Location)
  @opening_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#typeObject

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



9644
9645
9646
# File 'lib/prism/node.rb', line 9644

def type
  :interpolated_regular_expression_node
end

#utf_8?Boolean

def utf_8?: () -> bool

Returns:

  • (Boolean)


9592
9593
9594
# File 'lib/prism/node.rb', line 9592

def utf_8?
  flags.anybits?(RegularExpressionFlags::UTF_8)
end

#windows_31j?Boolean

def windows_31j?: () -> bool

Returns:

  • (Boolean)


9587
9588
9589
# File 'lib/prism/node.rb', line 9587

def windows_31j?
  flags.anybits?(RegularExpressionFlags::WINDOWS_31J)
end