class IDL::Scanner::In
Public Class Methods
new(src, name = '', line = 0, column = 1)
click to toggle source
# File lib/ridl/scanner.rb, line 47 def initialize(src, name = '', line = 0, column = 1) @src = src @fwd = src.getc # look ahead character @bwd = nil # look back character @pos = Position.new(name, line, column) @mark = nil end
Public Instance Methods
close()
click to toggle source
# File lib/ridl/scanner.rb, line 151 def close @src.close # close input source end
column()
click to toggle source
# File lib/ridl/scanner.rb, line 59 def column @pos.column end
getc()
click to toggle source
# File lib/ridl/scanner.rb, line 73 def getc cur = @fwd @fwd = @src.getc unless @src.nil? @mark << cur unless @mark.nil? if [nil, "\n", "\r"].include? @bwd if @bwd == "\r" and cur == "\n" else @pos.line += 1 @pos.column = 1 end else @pos.column += 1 end if false if not @bwd.nil? or cur.nil? or @fwd.nil? printf("%c(%02x), %c(%02x), %c(%02x) @(l:%d,c:%d)\n", @bwd, @bwd, cur, cur, @fwd, @fwd, @pos.line, @pos.column) end end @bwd = cur end
Also aliased as: skipc
getregion()
click to toggle source
# File lib/ridl/scanner.rb, line 145 def getregion ret = @mark @mark = nil ret end
gets()
click to toggle source
# File lib/ridl/scanner.rb, line 96 def gets return nil if @fwd.nil? s = '' s << getc until [nil, "\n", "\r"].include? lookc s << getc while ["\n", "\r"].include? lookc @mark << s unless @mark.nil? s end
lookc()
click to toggle source
# File lib/ridl/scanner.rb, line 69 def lookc @fwd end
mark(*ini)
click to toggle source
# File lib/ridl/scanner.rb, line 130 def mark(*ini) @mark = '' ini.each { |i| case i when nil when String @mark << i.dup when Fixnum @mark << i when Array i.each { |j| @mark << j } # array of array is not incoming. end } end
position()
click to toggle source
# File lib/ridl/scanner.rb, line 55 def position @pos end
skipuntil(*_chars, &block)
click to toggle source
# File lib/ridl/scanner.rb, line 119 def skipuntil(*_chars, &block) if block until (ch = lookc).nil? return ch if block.call(ch) skipc end end nil end
skipwhile(*_chars, &block)
click to toggle source
# File lib/ridl/scanner.rb, line 108 def skipwhile(*_chars, &block) if block until (ch = lookc).nil? return ch unless block.call(ch) skipc end end nil end
to_s()
click to toggle source
cursor set at last gotten character. ex: after initialization, position is (0,0).
# File lib/ridl/scanner.rb, line 65 def to_s @src.to_s end