Class: AjLisp::StringSource

Inherits:
Object
  • Object
show all
Defined in:
lib/ajlisp/string_source.rb

Direct Known Subclasses

FileSource

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ StringSource

Returns a new instance of StringSource.



5
6
7
8
9
# File 'lib/ajlisp/string_source.rb', line 5

def initialize(text)
  @text = text
  @position = 0
  @chars = []
end

Instance Method Details

#nextCharObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ajlisp/string_source.rb', line 11

def nextChar
  char = @chars.pop
  
  if char
    return char
  end

  char = @text[@position]
  @position += 1
  return char
end

#pushChar(ch) ⇒ Object



23
24
25
# File 'lib/ajlisp/string_source.rb', line 23

def pushChar(ch)
  @chars.push ch
end