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.



13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
# File 'lib/prism/node.rb', line 13788

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



13909
13910
13911
# File 'lib/prism/node.rb', line 13909

def unescaped
  @unescaped
end

Class Method Details

.typeObject

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



13937
13938
13939
# File 'lib/prism/node.rb', line 13937

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.



13943
13944
13945
13946
13947
13948
13949
13950
# File 'lib/prism/node.rb', line 13943

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



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

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

#ascii_8bit?Boolean

def ascii_8bit?: () -> bool

Returns:

  • (Boolean)


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

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

#child_nodesObject Also known as: deconstruct

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



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

def child_nodes
  []
end

#closingObject

def closing: () -> String



13922
13923
13924
# File 'lib/prism/node.rb', line 13922

def closing
  closing_loc.slice
end

#closing_locObject

attr_reader closing_loc: Location



13902
13903
13904
13905
13906
# File 'lib/prism/node.rb', line 13902

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]



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

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



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

def compact_child_nodes
  []
end

#contentObject

def content: () -> String



13917
13918
13919
# File 'lib/prism/node.rb', line 13917

def content
  content_loc.slice
end

#content_locObject

attr_reader content_loc: Location



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

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



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

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 }



13828
13829
13830
# File 'lib/prism/node.rb', line 13828

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)


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

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

#extended?Boolean

def extended?: () -> bool

Returns:

  • (Boolean)


13838
13839
13840
# File 'lib/prism/node.rb', line 13838

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

#forced_binary_encoding?Boolean

def forced_binary_encoding?: () -> bool

Returns:

  • (Boolean)


13878
13879
13880
# File 'lib/prism/node.rb', line 13878

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

#forced_us_ascii_encoding?Boolean

def forced_us_ascii_encoding?: () -> bool

Returns:

  • (Boolean)


13883
13884
13885
# File 'lib/prism/node.rb', line 13883

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

#forced_utf8_encoding?Boolean

def forced_utf8_encoding?: () -> bool

Returns:

  • (Boolean)


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

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

#ignore_case?Boolean

def ignore_case?: () -> bool

Returns:

  • (Boolean)


13833
13834
13835
# File 'lib/prism/node.rb', line 13833

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

#inspectObject

def inspect -> String



13927
13928
13929
# File 'lib/prism/node.rb', line 13927

def inspect
  InspectVisitor.compose(self)
end

#multi_line?Boolean

def multi_line?: () -> bool

Returns:

  • (Boolean)


13843
13844
13845
# File 'lib/prism/node.rb', line 13843

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

#once?Boolean

def once?: () -> bool

Returns:

  • (Boolean)


13848
13849
13850
# File 'lib/prism/node.rb', line 13848

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

#openingObject

def opening: () -> String



13912
13913
13914
# File 'lib/prism/node.rb', line 13912

def opening
  opening_loc.slice
end

#opening_locObject

attr_reader opening_loc: Location



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

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



13932
13933
13934
# File 'lib/prism/node.rb', line 13932

def type
  :regular_expression_node
end

#utf_8?Boolean

def utf_8?: () -> bool

Returns:

  • (Boolean)


13868
13869
13870
# File 'lib/prism/node.rb', line 13868

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

#windows_31j?Boolean

def windows_31j?: () -> bool

Returns:

  • (Boolean)


13863
13864
13865
# File 'lib/prism/node.rb', line 13863

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