From 7b52dfcb95c63e20a05cdd9ea04fc7fba3da9caf Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Tue, 27 Aug 2013 16:36:22 -0400 Subject: [PATCH] Clean up lexer logic --- lib/liquid/lexer.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/liquid/lexer.rb b/lib/liquid/lexer.rb index 8ac81a9..32991c9 100644 --- a/lib/liquid/lexer.rb +++ b/lib/liquid/lexer.rb @@ -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