Class: XfOOrth::AbstractSource
- Includes:
- ReadPoint
- Defined in:
- lib/fOOrth/compiler/source.rb
Overview
The Source class used to contain code common to most sources.
Direct Known Subclasses
Instance Attribute Summary
Attributes included from ReadPoint
Instance Method Summary collapse
-
#close ⇒ Object
Close the source.
-
#eof? ⇒ Boolean
Has the source reached the end of the available data?
Returns: * True if the end is reached else false. -
#get ⇒ Object
Get the next character of input data
Returns: * The next character or nil if none are available. -
#initialize ⇒ AbstractSource
constructor
Initialize the abstract base class.
-
#peek ⇒ Object
Peek ahead by one character.
Methods included from ReadPoint
#eoln?, #read, #reset_read_point
Constructor Details
#initialize ⇒ AbstractSource
Initialize the abstract base class.
13 14 15 16 17 |
# File 'lib/fOOrth/compiler/source.rb', line 13 def initialize reset_read_point @eof = false @peek_buffer = nil end |
Instance Method Details
#close ⇒ Object
Close the source.
20 21 22 23 24 |
# File 'lib/fOOrth/compiler/source.rb', line 20 def close @eoln = true @eof = true @peek_buffer = nil end |
#eof? ⇒ Boolean
Has the source reached the end of the available data?
Returns:
-
True if the end is reached else false.
54 55 56 |
# File 'lib/fOOrth/compiler/source.rb', line 54 def eof? @eof end |
#get ⇒ Object
Get the next character of input data
Returns:
-
The next character or nil if none are available.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 ⇒ Object
Peek ahead by one character.
Returns:
-
A peek at next character or nil if none are available.
47 48 49 |
# File 'lib/fOOrth/compiler/source.rb', line 47 def peek @peek_buffer ||= get unless eoln? end |