Class: Spoom::Sorbet::Sigs::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/spoom/sorbet/sigs.rb

Overview

Constant Summary collapse

LINE_BREAK =
T.let(0x0A, Integer)

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Scanner

: (String source) -> void



246
247
248
249
250
# File 'lib/spoom/sorbet/sigs.rb', line 246

def initialize(source)
  @current_line = T.let(0, Integer)
  @pos = T.let(0, Integer)
  @source = T.let(source.codepoints, T::Array[Integer])
end

Instance Method Details

#find_char_position(line, character) ⇒ Object

Finds the character index inside the source string for a given line and column : (Integer line, Integer character) -> Integer



254
255
256
257
258
259
260
261
262
263
264
# File 'lib/spoom/sorbet/sigs.rb', line 254

def find_char_position(line, character)
  # Find the character index for the beginning of the requested line
  until @current_line == line
    @pos += 1 until LINE_BREAK == @source[@pos]
    @pos += 1
    @current_line += 1
  end

  # The final position is the beginning of the line plus the requested column
  @pos + character
end