Class: Prism::RegularExpressionNode

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

Overview

Represents a regular expression literal with no interpolation.

/foo/i
^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, opening_loc, content_loc, closing_loc, unescaped) ⇒ RegularExpressionNode

Initialize a new RegularExpressionNode node.



13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
# File 'lib/prism/node.rb', line 13751

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

Instance Attribute Details

#unescapedObject (readonly)

attr_reader unescaped: String



13872
13873
13874
# File 'lib/prism/node.rb', line 13872

def unescaped
  @unescaped
end

Class Method Details

.typeObject

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



13900
13901
13902
# File 'lib/prism/node.rb', line 13900

def self.type
  :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.



13906
13907
13908
13909
13910
13911
13912
13913
# File 'lib/prism/node.rb', line 13906

def ===(other)
  other.is_a?(RegularExpressionNode) &&
    (flags === other.flags) &&
    (opening_loc.nil? == other.opening_loc.nil?) &&
    (content_loc.nil? == other.content_loc.nil?) &&
    (closing_loc.nil? == other.closing_loc.nil?) &&
    (unescaped === other.unescaped)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



13763
13764
13765
# File 'lib/prism/node.rb', line 13763

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

#ascii_8bit?Boolean

def ascii_8bit?: () -> bool

Returns:

  • (Boolean)


13821
13822
13823
# File 'lib/prism/node.rb', line 13821

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

#child_nodesObject Also known as: deconstruct

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



13768
13769
13770
# File 'lib/prism/node.rb', line 13768

def child_nodes
  []
end

#closingObject

def closing: () -> String



13885
13886
13887
# File 'lib/prism/node.rb', line 13885

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



13865
13866
13867
13868
13869
# File 'lib/prism/node.rb', line 13865

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]



13778
13779
13780
# File 'lib/prism/node.rb', line 13778

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



13773
13774
13775
# File 'lib/prism/node.rb', line 13773

def compact_child_nodes
  []
end

#contentObject

def content: () -> String



13880
13881
13882
# File 'lib/prism/node.rb', line 13880

def content
  content_loc.slice
end

#content_locObject

attr_reader content_loc: Location



13858
13859
13860
13861
13862
# File 'lib/prism/node.rb', line 13858

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

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

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



13783
13784
13785
# File 'lib/prism/node.rb', line 13783

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

#deconstruct_keys(keys) ⇒ Object

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



13791
13792
13793
# File 'lib/prism/node.rb', line 13791

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

#euc_jp?Boolean

def euc_jp?: () -> bool

Returns:

  • (Boolean)


13816
13817
13818
# File 'lib/prism/node.rb', line 13816

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

#extended?Boolean

def extended?: () -> bool

Returns:

  • (Boolean)


13801
13802
13803
# File 'lib/prism/node.rb', line 13801

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

#forced_binary_encoding?Boolean

def forced_binary_encoding?: () -> bool

Returns:

  • (Boolean)


13841
13842
13843
# File 'lib/prism/node.rb', line 13841

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

#forced_us_ascii_encoding?Boolean

def forced_us_ascii_encoding?: () -> bool

Returns:

  • (Boolean)


13846
13847
13848
# File 'lib/prism/node.rb', line 13846

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

#forced_utf8_encoding?Boolean

def forced_utf8_encoding?: () -> bool

Returns:

  • (Boolean)


13836
13837
13838
# File 'lib/prism/node.rb', line 13836

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

#ignore_case?Boolean

def ignore_case?: () -> bool

Returns:

  • (Boolean)


13796
13797
13798
# File 'lib/prism/node.rb', line 13796

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

#inspectObject

def inspect -> String



13890
13891
13892
# File 'lib/prism/node.rb', line 13890

def inspect
  InspectVisitor.compose(self)
end

#multi_line?Boolean

def multi_line?: () -> bool

Returns:

  • (Boolean)


13806
13807
13808
# File 'lib/prism/node.rb', line 13806

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

#once?Boolean

def once?: () -> bool

Returns:

  • (Boolean)


13811
13812
13813
# File 'lib/prism/node.rb', line 13811

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

#openingObject

def opening: () -> String



13875
13876
13877
# File 'lib/prism/node.rb', line 13875

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



13851
13852
13853
13854
13855
# File 'lib/prism/node.rb', line 13851

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`.



13895
13896
13897
# File 'lib/prism/node.rb', line 13895

def type
  :regular_expression_node
end

#utf_8?Boolean

def utf_8?: () -> bool

Returns:

  • (Boolean)


13831
13832
13833
# File 'lib/prism/node.rb', line 13831

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

#windows_31j?Boolean

def windows_31j?: () -> bool

Returns:

  • (Boolean)


13826
13827
13828
# File 'lib/prism/node.rb', line 13826

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