eos?()
click to toggle source
def eos?
@scanner.eos?
end
keep_back()
click to toggle source
def keep_back
start, buffer = @keeps.pop
if buffer
string = @scanner.string
keep = string[start, string.size - start]
if keep and not keep.empty?
@inputs.unshift(StringIO.new(keep))
@last_scanner = false
end
@scanner = StringScanner.new(buffer)
else
@scanner.pos = start
end
end
keep_drop()
click to toggle source
def keep_drop
@keeps.pop
end
keep_end()
click to toggle source
def keep_end
start, buffer = @keeps.pop
keep = @scanner.string[start, @scanner.pos - start]
if buffer
buffer << keep
keep = buffer
end
keep
end
keep_start()
click to toggle source
def keep_start
@keeps.push([@scanner.pos, nil])
end
rest()
click to toggle source
def rest
@scanner.rest
end
scan(pattern)
click to toggle source
def scan(pattern)
value = @scanner.scan(pattern)
return value if @last_scanner
if value
read_chunk if @scanner.eos?
return value
else
nil
end
end
scan_all(pattern)
click to toggle source
def scan_all(pattern)
value = @scanner.scan(pattern)
return value if @last_scanner
return nil if value.nil?
while @scanner.eos? and read_chunk and (sub_value = @scanner.scan(pattern))
value << sub_value
end
value
end