Class: FAM::Syntax::TokenStream

Inherits:
Object
  • Object
show all
Defined in:
lib/fam/syntax/tokens.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTokenStream

Returns a new instance of TokenStream.



8
9
10
11
# File 'lib/fam/syntax/tokens.rb', line 8

def initialize
  @tokens = []
  @index = 0
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



6
7
8
# File 'lib/fam/syntax/tokens.rb', line 6

def index
  @index
end

#tokensObject

Returns the value of attribute tokens.



5
6
7
# File 'lib/fam/syntax/tokens.rb', line 5

def tokens
  @tokens
end

Instance Method Details

#<<(token) ⇒ Object



13
14
15
# File 'lib/fam/syntax/tokens.rb', line 13

def <<(token)
  @tokens << token
end

#[](i) ⇒ Object



17
18
19
# File 'lib/fam/syntax/tokens.rb', line 17

def [](i)
  @tokens[i]
end

#backObject



30
31
32
33
# File 'lib/fam/syntax/tokens.rb', line 30

def back
  @index -= 1
  @tokens[@index]
end

#currentObject



21
22
23
# File 'lib/fam/syntax/tokens.rb', line 21

def current
  @tokens[@index]
end

#nextObject



25
26
27
28
# File 'lib/fam/syntax/tokens.rb', line 25

def next
  @index += 1
  @tokens[@index]
end

#peek(i = 1) ⇒ Object



35
36
37
# File 'lib/fam/syntax/tokens.rb', line 35

def peek i=1
  @tokens[i + @index]
end

#previous(i = 1) ⇒ Object



39
40
41
# File 'lib/fam/syntax/tokens.rb', line 39

def previous i=1
  @tokens[@index - i]
end

#to_sObject



43
44
45
# File 'lib/fam/syntax/tokens.rb', line 43

def to_s
  @tokens.to_s
end