mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -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
|
||||
|
||||
+38
-17
@@ -45,28 +45,49 @@ module Liquid
|
||||
block = if tag == 'else'
|
||||
ElseCondition.new
|
||||
else
|
||||
|
||||
expressions = markup.scan(ExpressionsAndOperators).reverse
|
||||
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
||||
|
||||
condition = Condition.new($1, $2, $3)
|
||||
|
||||
while not expressions.empty?
|
||||
operator = (expressions.shift).to_s.strip
|
||||
|
||||
raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax
|
||||
|
||||
new_condition = Condition.new($1, $2, $3)
|
||||
new_condition.send(operator.to_sym, condition)
|
||||
condition = new_condition
|
||||
end
|
||||
|
||||
condition
|
||||
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
|
||||
|
||||
condition = Condition.new($1, $2, $3)
|
||||
|
||||
while not expressions.empty?
|
||||
operator = (expressions.shift).to_s.strip
|
||||
|
||||
raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax
|
||||
|
||||
new_condition = Condition.new($1, $2, $3)
|
||||
new_condition.send(operator.to_sym, condition)
|
||||
condition = new_condition
|
||||
end
|
||||
|
||||
condition
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
Template.register_tag('if', If)
|
||||
|
||||
Reference in New Issue
Block a user