File: position.rb

package info (click to toggle)
ruby-parslet 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,264 kB
  • sloc: ruby: 6,157; sh: 6; javascript: 3; makefile: 3
file content (21 lines) | stat: -rw-r--r-- 327 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# Encapsules the concept of a position inside a string. 
#
class Parslet::Position
  attr_reader :bytepos

  include Comparable

  def initialize string, bytepos
    @string = string
    @bytepos = bytepos
  end

  def charpos
    @string.byteslice(0, @bytepos).size
  end

  def <=> b
    self.bytepos <=> b.bytepos
  end
end