class Liquid::Lexer
def initialize(input)
def initialize(input) @ss = StringScanner.new(input) end
def tokenize
def tokenize @output = [] until @ss.eos? @ss.skip(WHITESPACE_OR_NOTHING) break if @ss.eos? tok = if (t = @ss.scan(COMPARISON_OPERATOR)) [:comparison, t] elsif (t = @ss.scan(STRING_LITERAL)) [:string, t] elsif (t = @ss.scan(NUMBER_LITERAL)) [:number, t] elsif (t = @ss.scan(IDENTIFIER)) [:id, t] elsif (t = @ss.scan(DOTDOT)) [:dotdot, t] else c = @ss.getch if (s = SPECIALS[c]) [s, c] else raise SyntaxError, "Unexpected character #{c}" end end @output << tok end @output << [:end_of_string] end