Class: RParsec::CodeLocator

Inherits:
Object
  • Object
show all
Extended by:
DefHelper
Defined in:
lib/rparsec/locator.rb

Constant Summary collapse

LF =
?\n

Instance Method Summary collapse

Methods included from DefHelper

def_ctor, def_mutable, def_readable

Instance Method Details

#_locateEofObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rparsec/locator.rb', line 27

def _locateEof
  line, col = 1, 1
  code.each_byte do |c|
    if c == LF.ord
      line, col = line + 1, 1
    else
      col = col + 1
    end
  end
  return line, col
end

#locate(ind) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rparsec/locator.rb', line 12

def locate(ind)
  return _locateEof if ind >= code.length
  line, col = 1, 1
  return line, col if ind <= 0
  for i in (0...ind)
    c = code[i]
    if c == LF
      line, col = line + 1, 1
    else
      col = col + 1
    end
  end
  return line, col
end