class Parse::StringScannerPosition

@!visibility private

A {Position} optimized for using with {StringScanner}.

Attributes

file[R]

(see Position#file)

text[R]

@!visibility private

text_pos[R]

@!visibility private

Public Class Methods

new(text_pos, text, file) click to toggle source

@param [Integer] text_pos {StringScanner#pos} in text. @param [StringScanner] text @param [String] file see {Position#file}.

# File lib/parse.rb, line 483
def initialize(text_pos, text, file)
  @text = text
  @text_pos = text_pos
  @file = file
end

Public Instance Methods

<=>(other) click to toggle source

(see Position#<=>)

Calls superclass method Parse::Position#<=>
# File lib/parse.rb, line 503
def <=> other
  case other
  when StringScannerPosition
    return nil unless self.file == other.file
    return self.text_pos <=> other.text_pos
  else
    super(other)
  end
end
column() click to toggle source

(see Position#column)

# File lib/parse.rb, line 498
def column
  line_and_column[1]
end
line() click to toggle source

(see Position#line)

# File lib/parse.rb, line 493
def line
  line_and_column[0]
end

Private Instance Methods

line_and_column() click to toggle source
# File lib/parse.rb, line 521
def line_and_column
  @line_and_column ||= begin
    s = @text.substr(0, @text_pos)
    lines = s.split("\n", -1).to_a
    [
      line = if lines.size == 0 then 0 else lines.size - 1 end,
      column = (lines.last || "").size
    ]
  end
end