class NsMacroProcessor::Tokens
Constants
- EOF
Public Class Methods
new(input)
click to toggle source
# File lib/ns_macro_processor/tokens.rb, line 7 def initialize(input) @input = input end
Public Instance Methods
advance()
click to toggle source
# 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()
click to toggle source
# File lib/ns_macro_processor/tokens.rb, line 37 def peek @current end
push_back(str)
click to toggle source
# File lib/ns_macro_processor/tokens.rb, line 41 def push_back(str) @input = (@current == EOF) ? str + @input : str + @current + @input advance end
Private Instance Methods
ident?(ch)
click to toggle source
# File lib/ns_macro_processor/tokens.rb, line 52 def ident?(ch) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/_".include?(ch) end
ident_start?(ch)
click to toggle source
# File lib/ns_macro_processor/tokens.rb, line 48 def ident_start?(ch) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_/".include?(ch) end
whitespace?(ch)
click to toggle source
# File lib/ns_macro_processor/tokens.rb, line 56 def whitespace?(ch) " \t\n\r".include?(ch) end