Refactor Condition so that it takes a parsed expression.

This commit is contained in:
Dylan Thacker-Smith
2014-10-18 15:03:40 -04:00
parent d502b9282a
commit a1a128db19
4 changed files with 69 additions and 69 deletions
+3 -3
View File
@@ -3,7 +3,7 @@ module Liquid
#
# Example:
#
# c = Condition.new('1', '==', '1')
# c = Condition.new(1, '==', 1)
# c.evaluate #=> true
#
class Condition #:nodoc:
@@ -28,9 +28,9 @@ module Liquid
attr_accessor :left, :operator, :right
def initialize(left = nil, operator = nil, right = nil)
@left = Expression.parse(left)
@left = left
@operator = operator
@right = Expression.parse(right)
@right = right
@child_relation = nil
@child_condition = nil
end
+2 -2
View File
@@ -8,7 +8,7 @@ module Liquid
@blocks = []
if markup =~ Syntax
@left = $1
@left = Expression.parse($1)
else
raise SyntaxError.new(options[:locale].t("errors.syntax.case".freeze))
end
@@ -58,7 +58,7 @@ module Liquid
markup = $2
block = Condition.new(@left, '=='.freeze, $1)
block = Condition.new(@left, '=='.freeze, Expression.parse($1))
block.attach(@nodelist)
@blocks.push(block)
end
+4 -4
View File
@@ -60,14 +60,14 @@ module Liquid
expressions = markup.scan(ExpressionsAndOperators)
raise(SyntaxError.new(options[:locale].t("errors.syntax.if".freeze))) unless expressions.pop =~ Syntax
condition = Condition.new($1, $2, $3)
condition = Condition.new(Expression.parse($1), $2, Expression.parse($3))
while not expressions.empty?
operator = expressions.pop.to_s.strip
raise(SyntaxError.new(options[:locale].t("errors.syntax.if".freeze))) unless expressions.pop.to_s =~ Syntax
new_condition = Condition.new($1, $2, $3)
new_condition = Condition.new(Expression.parse($1), $2, Expression.parse($3))
raise(SyntaxError.new(options[:locale].t("errors.syntax.if".freeze))) unless BOOLEAN_OPERATORS.include?(operator)
new_condition.send(operator, condition)
condition = new_condition
@@ -92,9 +92,9 @@ module Liquid
end
def parse_comparison(p)
a = p.expression
a = Expression.parse(p.expression)
if op = p.consume?(:comparison)
b = p.expression
b = Expression.parse(p.expression)
Condition.new(a, op, b)
else
Condition.new(a)