visitLogicalExpression

@param Expr\LogicalExpression $expr
@access public
@return void
190919
public function visitLogicalExpression(Expr\LogicalExpression $expr)
    {
        $exprs = array();
        foreach($expr->getExpressions() as $innerExpr) {
            $exprs[] = $this->visit($innerExpr);
        }

        switch($expr->getType()) {
        case Expr\LogicalExpression::TYPE_AND:
            if(1 >= count($exprs)) {
                return implode(' ', $exprs);
            }
            return Literals::L_AND . Literals::L_COLON . 
                Literals::L_PARENTHESIS_OPEN . 
                implode(' ', $exprs) .
                Literals::L_PARENTHESIS_CLOSE ;
        case Expr\LogicalExpression::TYPE_OR:
            if(1 >= count($exprs)) {
                return implode(' ', $exprs);
            }
            return Literals::L_OR . Literals::L_COLON . 
                Literals::L_PARENTHESIS_OPEN . 
                implode(' ', $exprs) .
                Literals::L_PARENTHESIS_CLOSE ;
        case Expr\LogicalExpression::TYPE_NOT:
            return Literals::L_NOT . Literals::L_COLON . 
                Literals::L_PARENTHESIS_OPEN . 
                implode(' ', $exprs) .
                Literals::L_PARENTHESIS_CLOSE ;
        default:
            throw new \RuntimeException(sprintf('Unknown type of LogicalExpression operator: [%s]', (string)$expr->getType()));
        }
    }
901303
public function not(Expr $subexpression)
    {
        $not = new Condition\Logical\Not;
        $not->add($subexpression->condition);

        return $this;
    }
676822
protected function checkExpression(DOMNode $node, $expr, Tag $tag)
	{
		$this->checkContext($node);

		if (preg_match('/^\\$(\\w+)$/', $expr, $m))
		{
			// Either this expression came from a variable that is considered safe, or it's a
			// stylesheet parameters, which are considered safe by default
			$this->checkVariable($node, $tag, $m[1]);
		}
		elseif (preg_match('/^@[-\\w]+(?:\\s*\\|\\s*@[-\\w]+)*$/', $expr))
		{
			$this->checkAttributeExpression($node, $tag, $expr);
		}
		elseif (!$this->isExpressionSafe($expr))
		{
			throw new UnsafeTemplateException("Cannot assess the safety of expression '" . $expr . "'", $node);
		}
	}
1252803
public function isAnInExpression(TreeExpression $expr)
    {
        $count = $expr->count();
        if ($count <= 1 || strtolower($expr->getValue()) != 'or' )
            return false;

        $children = $expr->getChildren();
        if (!$children[0] instanceof FieldExpression)
            return false;

        for ($i = 1; $i < $count; $i++) {
            if (!$children[$i] instanceof FieldExpression)
                return false;
            if ($children[$i]->getField() != $children[$i-1]->getField())
                return false;
        }

        return true;
    }
967628
function where($expr)
    {
        $select = $this->from();
        foreach (func_get_args() as $expr) {
            $select->where($expr);
        }
        return $select;
    }
855265
public function add(Expr\Part $part)
    {
        if(!$part instanceof ConditionalExpression) {
            throw new \RuntimeException(sprintf('ConditionalClause only accept ConditionalExpression, but "%s" is given', is_object($part) ? get_class($part) : gettype($part)));
        }

        if(!$this->expression) {
            $this->expression = $part;
        } else if(($this->expression instanceof LogicalExpression) && $this->expression->isType(LogicalExpression::TYPE_AND)) {
            // if root expression is AND logicalExpression, then append
            $this->expression->add($part);
        } else {
            // create new AND logicalExpression and append both current expression and new expresion
            $and = new Expr\LogicalExpression(array(
                    $this->expression,
                    $part
                ), Expr\LogicalExpression::TYPE_AND);

            $this->expression = $and;
        }
        return $this;
    }
529575
public function eq($expression1, $expression2) : self
    {
        $this->expr->eq($expression1, $expression2);

        return $this;
    }
500149
function parseLogicalANDExpression() {
        var expr = parseBitwiseORExpression();

        while (match('&&')) {
            lex();
            expr = {
                type: Syntax.LogicalExpression,
                operator: '&&',
                left: expr,
                right: parseBitwiseORExpression()
            };
        }

        return expr;
    }
1152083
public function formatExpression(Expr $expr) {
        $field = $expr->getField();
        $operator = $expr->getOperator();
        $value = $expr->getValue();

        if ($operator === Expr::AS_ALIAS) {
            return sprintf($this->getClause(self::AS_ALIAS), $this->quote($field), $this->quote($value));

        // No value to use so exit early
        } else if (!$expr->useValue() && !($operator === Expr::NULL || $operator === Expr::NOT_NULL)) {
            return $this->quote($field);
        }

        $isSubQuery = ($value instanceof SubQuery);

        // Function as field
        if ($field instanceof Func) {
            $field = $this->formatFunction($field);

        // Raw expression as field
        } else if ($field instanceof RawExpr) {
            $field = $field->getValue();

        // Regular clause
        } else {
            $field = $this->quote($field);
        }

        // IN has special case
        if ($operator === Expr::IN || $operator === Expr::NOT_IN) {
            if ($isSubQuery) {
                $clause = sprintf($this->getClause($operator), $field, '?');
                $clause = str_replace(['(', ')'], '', $clause);
            } else {
                $clause = sprintf($this->getClause($operator), $field, implode(', ', array_fill(0, count($value), '?')));
            }

        // Operators with clauses
        } else if ($this->hasClause($operator)) {
            $clause = sprintf($this->getClause($operator), $field);

        // Basic operator
        } else {
            $clause = sprintf($this->getClause(self::EXPRESSION), $field, $operator);
        }

        // Replace ? with sub-query statement
        if ($isSubQuery) {
            /** @type \Titon\Db\Query\SubQuery $value */

            // EXISTS and NOT EXISTS doesn't have a field or operator
            if (in_array($value->getFilter(), [SubQuery::EXISTS, SubQuery::NOT_EXISTS], true)) {
                $clause = $this->formatSubQuery($value);

            } else {
                $clause = str_replace('?', $this->formatSubQuery($value), $clause);
            }
        }

        return $clause;
    }
524599
public function setExpr($expression) {
		$this->valueList = func_get_args();
		$this->expression = array_shift($this->valueList);
		return $this;
	}
401688
public static function parseUriFromBladeExpression($expr)
    {
        if (is_null($expr)) {
            // Return the current route if no argument is given.
            return app('router')->current()->getUri();
        }

        $expr = trim($expr, '()\'" ');

        if ($expr !== '/') {
            // Remove leading slash, if any.
            return ltrim($expr, '/');
        }

        return $expr;
    }
683100
public function addToQueryCondition(Expr $expr)
    {
        $expr->attr($this->getHashKey()->getPropertyMetadata()->name)->equals($this->getHashValue());
    }
572433
public void set(Expr expr) {
        this.type = expr.type;
        this.value = expr.value;
        this.left = expr.left;
        this.right = expr.right;
        this.query = expr.query;
    }
810787
public static function parseEqualityExpr($expr)
	{
		// Match an equality between a variable and a literal or the concatenation of strings
		$eq = '(?<equality>'
		    . '(?<key>@[-\\w]+|\\$\\w+|\\.)'
		    . '(?<operator>\\s*=\\s*)'
		    . '(?:'
		    . '(?<literal>(?<string>"[^"]*"|\'[^\']*\')|0|[1-9][0-9]*)'
		    . '|'
		    . '(?<concat>concat\\(\\s*(?&string)\\s*(?:,\\s*(?&string)\\s*)+\\))'
		    . ')'
		    . '|'
		    . '(?:(?<literal>(?&literal))|(?<concat>(?&concat)))(?&operator)(?<key>(?&key))'
		    . ')';

		// Match a string that is entirely composed of equality checks separated with "or"
		$regexp = '(^(?J)\\s*' . $eq . '\\s*(?:or\\s*(?&equality)\\s*)*$)';
		if (!preg_match($regexp, $expr))
		{
			return false;
		}

		preg_match_all("((?J)$eq)", $expr, $matches, PREG_SET_ORDER);

		$map = [];
		foreach ($matches as $m)
		{
			$key   = $m['key'];
			$value = (!empty($m['concat']))
			       ? self::evaluateConcat($m['concat'])
			       : self::evaluateLiteral($m['literal']);

			$map[$key][] = $value;
		}

		return $map;
	}
287887
public function compile(Expression $expr, CompilationContext $compilationContext)
    {
        $this->expression = $expr;
        $expression = $expr->getExpression();

        switch ($expression['call-type']) {
            case self::CALL_NORMAL:
                return $this->_callNormal($expression, $compilationContext);
            case self::CALL_DYNAMIC:
                return $this->_callDynamic($expression, $compilationContext);
        }

        return new CompiledExpression('null', null, $expression);
    }
1332259
public function visit(Expr\Part $expr)
    {
        $response = null;
        foreach($visitors as $visitor) {
            $response = $visitor->visit($expr);
        }

        return $response;
    }
897466
public function not($value)
    {
        if(!$value instanceof Expr\ConditionalExpression) {
            throw new \InvalidArgumentException('ExpressionBuilder::not only accept ConditionalExpression as argument 1');
        }
        //return new Expr\Not($value);
        return new Expr\LogicalExpression(array($value), Expr\LogicalExpression::TYPE_NOT);
    }