class Prism::Location

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

# sig/prism/parse_result.rbs

class Prism::Location
  def initialize: (Prism::Source source, Integer start_offset, Integer length) -> void
  def slice: () -> String
  def start_line: () -> Integer
end

This represents a location in the source.

def self.null

do not care where it points.
the beginning of the file. Useful for when you want a location object but
Returns a null location that does not correspond to a source and points to
def self.null
  new(nil, 0, 0)
end

def ==(other)

Returns true if the given other location is equal to this location.
def ==(other)
  other.is_a?(Location) &&
    other.start_offset == start_offset &&
    other.end_offset == end_offset
end

def copy(**options)

Create a new location object with the given options.
def copy(**options)
  Location.new(
    options.fetch(:source) { source },
    options.fetch(:start_offset) { start_offset },
    options.fetch(:length) { length }
  )
end

def deconstruct_keys(keys)

Implement the hash pattern matching interface for Location.
def deconstruct_keys(keys)
  { start_offset: start_offset, end_offset: end_offset }
end

def end_character_column

the line.
The column number in characters where this location ends from the start of
def end_character_column
  source.character_column(end_offset)
end

def end_character_offset

ends.
The character offset from the beginning of the source where this location
def end_character_offset
  source.character_offset(end_offset)
end

def end_column

line.
The column number in bytes where this location ends from the start of the
def end_column
  source.column(end_offset)
end

def end_line

The line number where this location ends.
def end_line
  source.line(end_offset)
end

def end_offset

The byte offset from the beginning of the source where this location ends.
def end_offset
  start_offset + length
end

def initialize(source, start_offset, length)

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

def initialize: (Prism::Source source, Integer start_offset, Integer length) -> void

This signature was generated using 676 samples from 1 application.

byte length.
Create a new location object with the given source, start byte offset, and
def initialize(source, start_offset, length)
  @source = source
  @start_offset = start_offset
  @length = length
  @comments = []
end

def inspect

Returns a string representation of this location.
def inspect
  "#<Prism::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>"
end

def join(other)

location or if they don't share the same source.
other location. Raises an error if this location is not before the other
Returns a new location that stretches from this location to the given
def join(other)
  raise "Incompatible sources" if source != other.source
  raise "Incompatible locations" if start_offset > other.start_offset
  Location.new(source, start_offset, other.end_offset - start_offset)
end

def pretty_print(q)

Implement the pretty print interface for Location.
def pretty_print(q)
  q.text("(#{start_line},#{start_column})-(#{end_line},#{end_column})")
end

def slice

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

def slice: () -> String

This signature was generated using 59 samples from 1 application.

The source code that this location represents.
def slice
  source.slice(start_offset, length)
end

def start_character_column

the line.
The column number in characters where this location ends from the start of
def start_character_column
  source.character_column(start_offset)
end

def start_character_offset

starts.
The character offset from the beginning of the source where this location
def start_character_offset
  source.character_offset(start_offset)
end

def start_column

the line.
The column number in bytes where this location starts from the start of
def start_column
  source.column(start_offset)
end

def start_line

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

def start_line: () -> Integer

This signature was generated using 62 samples from 1 application.

The line number where this location starts.
def start_line
  source.line(start_offset)
end

def start_line_slice

The content of the line where this location starts before this location.
def start_line_slice
  offset = source.line_start(start_offset)
  source.slice(offset, start_offset - offset)
end