Clean up lexer logic

This commit is contained in:
Tristan Hume
2013-08-27 16:36:22 -04:00
parent 1fa029ab67
commit 7b52dfcb95

View File

@@ -18,16 +18,14 @@ module Liquid
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains/
def initialize(input)
@ss = StringScanner.new(input)
@ss = StringScanner.new(input.rstrip)
end
def tokenize
@output = []
loop do
while !@ss.eos?
@ss.skip(/\s*/)
return @output.push([:end_of_string]) if @ss.eos?
tok = case
when t = @ss.scan(COMPARISON_OPERATOR) then [:comparison, t]
when t = @ss.scan(SINGLE_STRING_LITERAL) then [:string, t]
@@ -42,9 +40,10 @@ module Liquid
raise SyntaxError, "Unexpected character #{c}"
end
end
@output << tok
end
@output << [:end_of_string]
end
end
end