Class: RParsec::CodeLocator

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

Overview

:nodoc:

Constant Summary collapse

LF =
?\n

Instance Method Summary collapse

Methods included from DefHelper

def_readable

Instance Method Details

#_locateEofObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rparsec/locator.rb', line 31

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

#locate(ind) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rparsec/locator.rb', line 14

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