def read_expression
result = read_single_expression
until peek_token == ')' || eof?
operator = peek_token
if binary_operator?(operator)
next_token
else
operator = 'OR'
end
next_expression = read_single_expression
if result.is_a?(Query::BinaryOperator) &&
binary_operator_precedence(operator) > binary_operator_precedence(result.operator)
new_right = Query::BinaryOperator.new(result.right, operator, next_expression)
result = Query::BinaryOperator.new(result.left, result.operator, new_right)
else
result = Query::BinaryOperator.new(result, operator, next_expression)
end
end
result
end