Module: XfOOrth::ReadPoint

Included in:
AbstractSource, Console
Defined in:
lib/fOOrth/compiler/source/read_point.rb

Overview

This module is used to facilitate the reading of source code text from a buffer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#read_bufferObject (readonly)

Get the current line of text being read.



10
11
12
# File 'lib/fOOrth/compiler/source/read_point.rb', line 10

def read_buffer
  @read_buffer
end

Instance Method Details

#eoln?Boolean

Is the read point at the end of line?

Returns:

  • (Boolean)


41
42
43
# File 'lib/fOOrth/compiler/source/read_point.rb', line 41

def eoln?
  @eoln
end

#read(&block) ⇒ Object

Read the next character of data from the source. If there is nothing to read, call the block to get some more data to work with.
Parameters

  • block - A block of code that retrieves the next line of

source code to be processed.


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

def read(&block)
  unless @read_point
    return nil unless (@read_buffer = block.call)
    @read_point = @read_buffer.each_char
  end

  begin
    result, @eoln = @read_point.next, false
  rescue StopIteration
    result, @read_point, @eoln = ' ', nil, true
  end

  result
end

#reset_read_pointObject

Reset the read point to the initial conditions. Namely, no text in the buffer and not at end of line,



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

def reset_read_point
  @read_point = nil
  @eoln = false
end