mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Clean up lexer logic
This commit is contained in:
+4
-5
@@ -18,16 +18,14 @@ module Liquid
|
|||||||
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains/
|
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains/
|
||||||
|
|
||||||
def initialize(input)
|
def initialize(input)
|
||||||
@ss = StringScanner.new(input)
|
@ss = StringScanner.new(input.rstrip)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tokenize
|
def tokenize
|
||||||
@output = []
|
@output = []
|
||||||
|
|
||||||
loop do
|
while !@ss.eos?
|
||||||
@ss.skip(/\s*/)
|
@ss.skip(/\s*/)
|
||||||
return @output.push([:end_of_string]) if @ss.eos?
|
|
||||||
|
|
||||||
tok = case
|
tok = case
|
||||||
when t = @ss.scan(COMPARISON_OPERATOR) then [:comparison, t]
|
when t = @ss.scan(COMPARISON_OPERATOR) then [:comparison, t]
|
||||||
when t = @ss.scan(SINGLE_STRING_LITERAL) then [:string, t]
|
when t = @ss.scan(SINGLE_STRING_LITERAL) then [:string, t]
|
||||||
@@ -42,9 +40,10 @@ module Liquid
|
|||||||
raise SyntaxError, "Unexpected character #{c}"
|
raise SyntaxError, "Unexpected character #{c}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@output << tok
|
@output << tok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@output << [:end_of_string]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user