Class: FAM::Syntax::TokenStream
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
Instance Method Summary collapse
- #<<(token) ⇒ Object
- #[](i) ⇒ Object
- #back ⇒ Object
- #current ⇒ Object
-
#initialize ⇒ TokenStream
constructor
A new instance of TokenStream.
- #next ⇒ Object
- #peek(i = 1) ⇒ Object
- #previous(i = 1) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ TokenStream
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
#index ⇒ Object
Returns the value of attribute index.
6 7 8 |
# File 'lib/fam/syntax/tokens.rb', line 6 def index @index end |
#tokens ⇒ Object
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 |
#back ⇒ Object
30 31 32 33 |
# File 'lib/fam/syntax/tokens.rb', line 30 def back @index -= 1 @tokens[@index] end |
#current ⇒ Object
21 22 23 |
# File 'lib/fam/syntax/tokens.rb', line 21 def current @tokens[@index] end |
#next ⇒ Object
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_s ⇒ Object
43 44 45 |
# File 'lib/fam/syntax/tokens.rb', line 43 def to_s @tokens.to_s end |