Class: NsMacroProcessor::Tokens
- Inherits:
-
Object
- Object
- NsMacroProcessor::Tokens
- Defined in:
- lib/ns_macro_processor/tokens.rb
Constant Summary collapse
- EOF =
-1
Instance Method Summary collapse
- #advance ⇒ Object
-
#initialize(input) ⇒ Tokens
constructor
A new instance of Tokens.
- #peek ⇒ Object
- #push_back(str) ⇒ Object
Constructor Details
#initialize(input) ⇒ Tokens
Returns a new instance of Tokens.
7 8 9 |
# File 'lib/ns_macro_processor/tokens.rb', line 7 def initialize(input) @input = input end |
Instance Method Details
#advance ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ns_macro_processor/tokens.rb', line 11 def advance if @input.nil? || @input.empty? @current = EOF return end ix = 0 if whitespace?(@input[ix]) while ix < @input.length && whitespace?(@input[ix]) ix += 1 end @current = ' ' @input = @input[ix..-1] return end if ident_start?(@input[ix]) while ix < @input.length && ident?(@input[ix]) ix += 1 end @current = @input[0, ix] @input = @input[ix..-1] return end @current = @input[0] @input = @input[1..-1] end |
#peek ⇒ Object
37 38 39 |
# File 'lib/ns_macro_processor/tokens.rb', line 37 def peek @current end |
#push_back(str) ⇒ Object
41 42 43 44 |
# File 'lib/ns_macro_processor/tokens.rb', line 41 def push_back(str) @input = (@current == EOF) ? str + @input : str + @current + @input advance end |