mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 17:30:43 -07:00
Bring back the lexer
This commit is contained in:
+15
-4
@@ -3,13 +3,24 @@ module Liquid
|
||||
# it provides helpers and encapsulates state
|
||||
class Parser
|
||||
def initialize(input)
|
||||
@tokens = tokenize(input)
|
||||
l = Lexer.new(input)
|
||||
@tokens = l.tokenize
|
||||
@p = 0 # pointer to current location
|
||||
end
|
||||
|
||||
def tokenize(input)
|
||||
# "foo.bar | filter: baz, qux" becomes ["foo", ".", "bar", "|", "filter", ":", "baz", ",", "qux"]
|
||||
input.split(/\b/).map {|tok| tok.strip}
|
||||
def consume(type)
|
||||
token = @tokens[@p]
|
||||
if match && token.type != type
|
||||
raise SyntaxError, "Expected #{match} but found #{@tokens[@p]}"
|
||||
end
|
||||
@p += 1
|
||||
token
|
||||
end
|
||||
|
||||
def look(type)
|
||||
@tokens[@p].type == type
|
||||
end
|
||||
|
||||
# === General Liquid parsing functions ===
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user