Bring back the lexer

This commit is contained in:
Tristan Hume
2013-07-24 14:40:29 -04:00
parent 61a6deb43b
commit 76272a1afa
3 changed files with 90 additions and 4 deletions
+15 -4
View File
@@ -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