Class: Packcr::Parser::Location
- Inherits:
-
Object
- Object
- Packcr::Parser::Location
- Defined in:
- lib/packcr/parser.rb
Instance Attribute Summary collapse
-
#charnum ⇒ Object
readonly
Returns the value of attribute charnum.
-
#linenum ⇒ Object
readonly
Returns the value of attribute linenum.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #forward(buffer, cur, n) ⇒ Object
- #forward!(buffer, cur, n) ⇒ Object
-
#initialize(charnum = 0, linenum = 0) ⇒ Location
constructor
A new instance of Location.
Constructor Details
#initialize(charnum = 0, linenum = 0) ⇒ Location
Returns a new instance of Location.
8 9 10 11 |
# File 'lib/packcr/parser.rb', line 8 def initialize(charnum = 0, linenum = 0) @charnum = charnum @linenum = linenum end |
Instance Attribute Details
#charnum ⇒ Object (readonly)
Returns the value of attribute charnum.
6 7 8 |
# File 'lib/packcr/parser.rb', line 6 def charnum @charnum end |
#linenum ⇒ Object (readonly)
Returns the value of attribute linenum.
6 7 8 |
# File 'lib/packcr/parser.rb', line 6 def linenum @linenum end |
Instance Method Details
#+(other) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/packcr/parser.rb', line 13 def +(other) if other.linenum.zero? Location.new(@charnum + other.charnum, @linenum + other.linenum) else Location.new( other.charnum, @linenum + other.linenum) end end |
#-(other) ⇒ Object
21 22 23 24 25 |
# File 'lib/packcr/parser.rb', line 21 def -(other) raise "unexpected location #{inspect} - #{other.inspect}" unless other.linenum == linenum || other.charnum.zero? Location.new(@charnum - other.charnum, @linenum - other.linenum) end |
#forward(buffer, cur, n) ⇒ Object
27 28 29 |
# File 'lib/packcr/parser.rb', line 27 def forward(buffer, cur, n) Location.new(@charnum, @linenum).forward!(buffer, cur, n) end |
#forward!(buffer, cur, n) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/packcr/parser.rb', line 31 def forward!(buffer, cur, n) buffer[cur, n].scan(/(.*)(\n)?/) do if Regexp.last_match[2] @linenum += 1 @charnum = 0 else @charnum += Regexp.last_match[1].length end end self end |