Class: XfOOrth::AbstractSource

Inherits:
Object
  • Object
show all
Includes:
ReadPoint
Defined in:
lib/fOOrth/compiler/source.rb

Overview

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

Direct Known Subclasses

FileSource, StringSource

Instance Attribute Summary

Attributes included from ReadPoint

#read_buffer

Instance Method Summary collapse

Methods included from ReadPoint

#eoln?, #read, #reset_read_point

Constructor Details

#initializeAbstractSource

Initialize the abstract base class.



13
14
15
16
# File 'lib/fOOrth/compiler/source.rb', line 13

def initialize
  reset_read_point
  @eof = false
end

Instance Method Details

#closeObject

Close the source.



19
20
21
22
# File 'lib/fOOrth/compiler/source.rb', line 19

def close
  @eoln = true
  @eof = true
end

#eof?Boolean

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

  • True if the end is reached else false.

Returns:

  • (Boolean)


43
44
45
# File 'lib/fOOrth/compiler/source.rb', line 43

def eof?
  @eof
end

#getObject

Get the next character of input data
Returns:

  • The next character or nil if none are available.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fOOrth/compiler/source.rb', line 27

def get
  return nil if @eof

  read do
    begin
      @read_step.next.rstrip
    rescue StopIteration
      @eof = true
      nil
    end
  end
end