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.
4391 4392 4393 4394 |
# File 'lib/packcr/parser.rb', line 4391 def initialize(charnum = 0, linenum = 0) @charnum = charnum @linenum = linenum end |
Instance Attribute Details
#charnum ⇒ Object (readonly)
Returns the value of attribute charnum.
4389 4390 4391 |
# File 'lib/packcr/parser.rb', line 4389 def charnum @charnum end |
#linenum ⇒ Object (readonly)
Returns the value of attribute linenum.
4389 4390 4391 |
# File 'lib/packcr/parser.rb', line 4389 def linenum @linenum end |
Instance Method Details
#+(other) ⇒ Object
4396 4397 4398 4399 4400 4401 4402 |
# File 'lib/packcr/parser.rb', line 4396 def +(other) if other.linenum == 0 Location.new(@charnum + other.charnum, @linenum + other.linenum) else Location.new( other.charnum, @linenum + other.linenum) end end |
#-(other) ⇒ Object
4404 4405 4406 4407 4408 4409 4410 4411 4412 |
# File 'lib/packcr/parser.rb', line 4404 def -(other) if other.linenum == self.linenum Location.new(@charnum - other.charnum, @linenum - other.linenum) elsif other.charnum == 0 Location.new(@charnum - other.charnum, @linenum - other.linenum) else raise "unexpected location #{self.inspect} - #{other.inspect}" end end |
#forward(buffer, cur, n) ⇒ Object
4414 4415 4416 |
# File 'lib/packcr/parser.rb', line 4414 def forward(buffer, cur, n) Location.new(@charnum, @linenum).forward!(buffer, cur, n) end |
#forward!(buffer, cur, n) ⇒ Object
4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 |
# File 'lib/packcr/parser.rb', line 4418 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 |