class SyntaxTree::RegexpLiteral

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/syntax_tree/node.rbs

class SyntaxTree::RegexpLiteral < SyntaxTree::Node
  def child_nodes: () -> untyped
  def initialize: (beginning: String, ending: String, parts: Array[SyntaxTree::TStringContent], location: SyntaxTree::Location) -> void
end


/.+/
RegexpLiteral represents a regular expression literal.

def ===(other)

def ===(other)
  other.is_a?(RegexpLiteral) && beginning === other.beginning &&
    ending === other.ending && options === other.options &&
    ArrayMatch.call(parts, other.parts)
end

def accept(visitor)

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

def ambiguous?(q)

operator, e.g. foo / bar/ or foo /=bar/
we want to use braces because otherwise we could end up with an ambiguous
or an =, and we're contained within a command or command_call node, then
If the first part of this regex is plain string content, we have a space
def ambiguous?(q)
  return false if parts.empty?
  part = parts.first
  part.is_a?(TStringContent) && part.value.start_with?(" ", "=") &&
    q.parents.any? { |node| node.is_a?(Command) || node.is_a?(CommandCall) }
end

def child_nodes

Experimental RBS support (using type sampling data from the type_fusion project).

def child_nodes: () -> untyped

This signature was generated using 1 sample from 1 application.

def child_nodes
  parts
end

def copy(beginning: nil, ending: nil, parts: nil, location: nil)

def copy(beginning: nil, ending: nil, parts: nil, location: nil)
  node =
    RegexpLiteral.new(
      beginning: beginning || self.beginning,
      ending: ending || self.ending,
      parts: parts || self.parts,
      location: location || self.location
    )
  node.comments.concat(comments.map(&:copy))
  node
end

def deconstruct_keys(_keys)

def deconstruct_keys(_keys)
  {
    beginning: beginning,
    ending: ending,
    options: options,
    parts: parts,
    location: location,
    comments: comments
  }
end

def format(q)

def format(q)
  braces = ambiguous?(q) || include?(%r{/})
  if braces && include?(/[{}]/)
    q.group do
      q.text(beginning)
      q.format_each(parts)
      q.text(ending)
    end
  elsif braces
    q.group do
      q.text("%r{")
      if beginning == "/"
        # If we're changing from a forward slash to a %r{, then we can
        # replace any escaped forward slashes with regular forward slashes.
        parts.each do |part|
          if part.is_a?(TStringContent)
            q.text(part.value.gsub("\\/", "/"))
          else
            q.format(part)
          end
        end
      else
        q.format_each(parts)
      end
      q.text("}")
      q.text(options)
    end
  else
    q.group do
      q.text("/")
      q.format_each(parts)
      q.text("/")
      q.text(options)
    end
  end
end

def include?(pattern)

def include?(pattern)
  parts.any? do |part|
    part.is_a?(TStringContent) && part.value.match?(pattern)
  end
end

def initialize(beginning:, ending:, parts:, location:)

Experimental RBS support (using type sampling data from the type_fusion project).

def initialize: (beginning: String, ending: String, parts: , location: SyntaxTree::Location) -> void

This signature was generated using 3 samples from 1 application.

def initialize(beginning:, ending:, parts:, location:)
  @beginning = beginning
  @ending = ending
  @parts = parts
  @location = location
  @comments = []
end

def options

def options
  ending[1..]
end