class XfOOrth::AbstractSource

The Source class used to contain code common to most sources.

Public Class Methods

new() click to toggle source

Initialize the abstract base class.

# File lib/fOOrth/compiler/source.rb, line 13
def initialize
  reset_read_point
  @eof = false
  @peek_buffer = nil
end

Public Instance Methods

close() click to toggle source

Close the source.

# File lib/fOOrth/compiler/source.rb, line 20
def close
  @eoln = true
  @eof = true
  @peek_buffer = nil
end
eof?() click to toggle source

Has the source reached the end of the available data?
Returns:

  • True if the end is reached else false.

# File lib/fOOrth/compiler/source.rb, line 54
def eof?
  @eof
end
get() click to toggle source

Get the next character of input data
Returns:

  • The next character or nil if none are available.

# File lib/fOOrth/compiler/source.rb, line 29
def get
  return nil if (@eof && !@peek_buffer)

  @peek_buffer || read do
    begin
      @read_step.next.rstrip
    rescue StopIteration
      @eof = true
      nil
    end
  end
ensure
  @peek_buffer = nil
end
peek() click to toggle source

Peek ahead by one character.
Returns:

  • A peek at next character or nil if none are available.

# File lib/fOOrth/compiler/source.rb, line 47
def peek
  @peek_buffer ||= get unless eoln?
end