Class: RDoc::Markup::Parser::MyStringScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc/markup/parser.rb

Overview

A simple wrapper of StringScanner that is aware of the current column and lineno

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ MyStringScanner

Returns a new instance of MyStringScanner.



423
424
425
426
# File 'lib/rdoc/markup/parser.rb', line 423

def initialize(input)
  @line = @column = 0
  @s = StringScanner.new input
end

Instance Method Details

#[](i) ⇒ Object



456
457
458
# File 'lib/rdoc/markup/parser.rb', line 456

def [](i)
  @s[i]
end

#eos?Boolean

Returns:

  • (Boolean)


448
449
450
# File 'lib/rdoc/markup/parser.rb', line 448

def eos?
  @s.eos?
end

#matchedObject



452
453
454
# File 'lib/rdoc/markup/parser.rb', line 452

def matched
  @s.matched
end

#newline!Object



443
444
445
446
# File 'lib/rdoc/markup/parser.rb', line 443

def newline!
  @column = 0
  @line += 1
end

#posObject



439
440
441
# File 'lib/rdoc/markup/parser.rb', line 439

def pos
  [@column, @line]
end

#scan(re) ⇒ Object



428
429
430
431
432
# File 'lib/rdoc/markup/parser.rb', line 428

def scan(re)
  ret = @s.scan(re)
  @column += ret.length if ret
  ret
end

#unscan(s) ⇒ Object



434
435
436
437
# File 'lib/rdoc/markup/parser.rb', line 434

def unscan(s)
  @s.pos -= s.bytesize
  @column -= s.length
end