mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-04 09:35:14 -07:00
Unfinished if statement parser.
This commit is contained in:
@@ -31,6 +31,15 @@ module Liquid
|
||||
token.contents
|
||||
end
|
||||
|
||||
# Like consume? Except for an :id token of a certain name
|
||||
def id?(str)
|
||||
token = @tokens[@p]
|
||||
return false unless token && token.type == :id
|
||||
return false unless token.contents == str
|
||||
@p += 1
|
||||
token.contents
|
||||
end
|
||||
|
||||
def cur_token()
|
||||
tok = @tokens[@p]
|
||||
raise SyntaxError, 'Expected more input.' unless tok
|
||||
|
||||
+23
-2
@@ -45,7 +45,14 @@ module Liquid
|
||||
block = if tag == 'else'
|
||||
ElseCondition.new
|
||||
else
|
||||
old_parse(markup)
|
||||
end
|
||||
|
||||
@blocks.push(block)
|
||||
@nodelist = block.attach(Array.new)
|
||||
end
|
||||
|
||||
def old_parse(markup)
|
||||
expressions = markup.scan(ExpressionsAndOperators).reverse
|
||||
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
||||
|
||||
@@ -64,8 +71,22 @@ module Liquid
|
||||
condition
|
||||
end
|
||||
|
||||
@blocks.push(block)
|
||||
@nodelist = block.attach(Array.new)
|
||||
def parse_condition(markup)
|
||||
p = Parser.new(markup)
|
||||
|
||||
condition = parse_comparison(p)
|
||||
|
||||
while op = (p.id?('and') || p.id?('or'))
|
||||
new_cond = parse_comparison(p)
|
||||
new_cond.send(op.to_sym, condition)
|
||||
condition = new_cond
|
||||
end
|
||||
|
||||
condition
|
||||
end
|
||||
|
||||
def parse_comparison(p)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user