Module: KPeg::Position
- Included in:
- CompiledParser, Parser
- Defined in:
- lib/kpeg/position.rb
Instance Method Summary collapse
-
#current_column(target = pos) ⇒ Object
STANDALONE START.
- #current_line(target = pos) ⇒ Object
- #lines ⇒ Object
Instance Method Details
#current_column(target = pos) ⇒ Object
STANDALONE START
4 5 6 7 8 9 10 |
# File 'lib/kpeg/position.rb', line 4 def current_column(target=pos) if c = string.rindex("\n", target-1) return target - c - 1 end target + 1 end |
#current_line(target = pos) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kpeg/position.rb', line 12 def current_line(target=pos) cur_offset = 0 cur_line = 0 string.each_line do |line| cur_line += 1 cur_offset += line.size return cur_line if cur_offset >= target end -1 end |
#lines ⇒ Object
25 26 27 28 29 |
# File 'lib/kpeg/position.rb', line 25 def lines lines = [] string.each_line { |l| lines << l } lines end |