Class: RPrec::ArrayStream

Inherits:
Stream
  • Object
show all
Defined in:
lib/rprec/array_stream.rb

Overview

ArrayStream is a simple implementation of RPrec::Stream with an array.

Instance Method Summary collapse

Methods inherited from Stream

#expected, #unexpected

Constructor Details

#initialize(tokens) ⇒ ArrayStream

Returns a new instance of ArrayStream.

Parameters:



9
10
11
12
13
# File 'lib/rprec/array_stream.rb', line 9

def initialize(tokens)
  super()
  @tokens = tokens
  @index = 0
end

Instance Method Details

#currentRPrec::Token

Returns:



16
17
18
19
20
# File 'lib/rprec/array_stream.rb', line 16

def current
  return Token.new('EOF') if eof?

  @tokens[@index]
end

#eof?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rprec/array_stream.rb', line 29

def eof?
  @index >= @tokens.size
end

#nextvoid

This method returns an undefined value.



23
24
25
26
# File 'lib/rprec/array_stream.rb', line 23

def next
  super
  @index += 1
end