In Files

  • rbs-1.0.4/lib/rbs/location.rb

Class/Module Index [+]

Quicksearch

RBS::Location

Attributes

buffer[R]
end_pos[R]
start_pos[R]

Public Class Methods

new(buffer:, start_pos:, end_pos:) click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 7
def initialize(buffer,, start_pos,, end_pos))
  @buffer = buffer
  @start_pos = start_pos
  @end_pos = end_pos
end
            
to_string(location, default: "*:*:*...*:*") click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 53
def self.to_string(location, default: "*:*:*...*:*")
  location&.to_s || default
end
            

Public Instance Methods

+(other) click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 64
def +(other)
  if other
    raise "Invalid concat: buffer=#{buffer.name}, other.buffer=#{other.buffer.name}" unless other.buffer == buffer

    self.class.new(buffer: buffer,
                   start_pos: start_pos,
                   end_pos: other.end_pos)
  else
    self
  end
end
            
<<(other) click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 81
def <<(other)
  if other
    raise "Invalid concat: buffer=#{buffer.name}, other.buffer=#{other.buffer.name}" unless other.buffer == buffer
    @end_pos = other.end_pos
    @source = nil
    @end_loc = nil
  end
  self
end
            
==(other) click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 57
def ==(other)
  other.is_a?(Location) &&
    other.buffer == buffer &&
    other.start_pos == start_pos &&
    other.end_pos == end_pos
end
            
concat(*others) click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 76
def concat(*others)
  others.each { |other| self << other }
  self
end
            
end_column() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 33
def end_column
  end_loc[1]
end
            
end_line() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 29
def end_line
  end_loc[0]
end
            
end_loc() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 41
def end_loc
  @end_loc ||= buffer.pos_to_loc(end_pos)
end
            
inspect() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 13
def inspect
  "#<#{self.class}:#{self.__id__} @buffer=#{buffer.name}, @pos=#{start_pos}...#{end_pos}, source='#{source.lines.first}', start_line=#{start_line}, start_column=#{start_column}>"
end
            
name() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 17
def name
  buffer.name
end
            
pred?(loc) click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 91
def pred?(loc)
  loc.is_a?(Location) &&
    loc.name == name &&
    loc.start_pos == end_pos
end
            
source() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 45
def source
  @source ||= buffer.content[start_pos...end_pos] or raise
end
            
start_column() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 25
def start_column
  start_loc[1]
end
            
start_line() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 21
def start_line
  start_loc[0]
end
            
start_loc() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 37
def start_loc
  @start_loc ||= buffer.pos_to_loc(start_pos)
end
            
to_json(*args) click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 97
def to_json(*args)
  {
    start: {
      line: start_line,
      column: start_column
    },
    end
            
to_s() click to toggle source
 
               # File rbs-1.0.4/lib/rbs/location.rb, line 49
def to_s
  "#{name || "-"}:#{start_line}:#{start_column}...#{end_line}:#{end_column}"
end