mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 17:15:12 -07:00
Unfinished if statement parser.
This commit is contained in:
@@ -31,6 +31,15 @@ module Liquid
|
|||||||
token.contents
|
token.contents
|
||||||
end
|
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()
|
def cur_token()
|
||||||
tok = @tokens[@p]
|
tok = @tokens[@p]
|
||||||
raise SyntaxError, 'Expected more input.' unless tok
|
raise SyntaxError, 'Expected more input.' unless tok
|
||||||
|
|||||||
+23
-2
@@ -45,7 +45,14 @@ module Liquid
|
|||||||
block = if tag == 'else'
|
block = if tag == 'else'
|
||||||
ElseCondition.new
|
ElseCondition.new
|
||||||
else
|
else
|
||||||
|
old_parse(markup)
|
||||||
|
end
|
||||||
|
|
||||||
|
@blocks.push(block)
|
||||||
|
@nodelist = block.attach(Array.new)
|
||||||
|
end
|
||||||
|
|
||||||
|
def old_parse(markup)
|
||||||
expressions = markup.scan(ExpressionsAndOperators).reverse
|
expressions = markup.scan(ExpressionsAndOperators).reverse
|
||||||
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
||||||
|
|
||||||
@@ -64,8 +71,22 @@ module Liquid
|
|||||||
condition
|
condition
|
||||||
end
|
end
|
||||||
|
|
||||||
@blocks.push(block)
|
def parse_condition(markup)
|
||||||
@nodelist = block.attach(Array.new)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user