src/Leevel/View/Compiler.php
protected function parseExpression(string $content): string
    {
        $content = trim($content);

        $logic = [
            '+',
            '-',
            '.',
            '(',
            ')',
            '/',
            '%',
            '*',
            '?',
            ':',
            '<',
            '>',
            '=',
            '|',
            '&',
            '~',
            '!',
        ];

        $result = [];

        // 单逻辑
        $findLogic = false;

        for ($i = 0; $i < strlen($content); $i++) {
            $temp = $content[$i];

            if (0 === $i && $this->isVarExpression($temp)) {
                $result[] = '$';
            }

            if (in_array($temp, $logic, true)) {
                // . 语法作为对象连接符
                if ('.' === $temp &&
                    isset($content[$i + 1]) &&
                    $this->isVarExpression($content[$i + 1]) &&
                    !in_array($content[$i + 1], [' ', '$'], true)) {
                    $result[] = '->';
                    $findLogic = false;
                }

                // -> 语法原生对象连接符
                elseif ('>' === $temp &&
                    $i > 0 &&
                    '-' === $content[$i - 1] &&
                    isset($content[$i + 1]) &&
                    !in_array($content[$i + 1], [' ', '$'], true)) {
                    $result[] = '>';
                    $findLogic = false;
                } else {
                    $findLogic = true;
                    $result[] = $temp;
                }

                continue;
            }

            if (true === $findLogic && ' ' !== $temp) {
                if ($this->isVarExpression($temp)) {
                    $result[] = '$';
                }

                $findLogic = false;
            }

            $result[] = $temp;
        }

        $content = implode('', $result);

        // 还原函数去掉开头的美元符号
        $content = preg_replace_callback('/(\$+?[a-z0-9\\_]+?\\s*?)\\(.+?\\)/',
            function ($match) {
                return substr($match[0], 1);
            },
            $content
        );

        return $content;
    }
protected function parseExpression(string $content): string
    {
        $content = trim($content);

        $logic = [
            '+',
            '-',
            '.',
            '(',
            ')',
            '/',
            '%',
            '*',
            '?',
            ':',
            '<',
            '>',
            '=',
            '|',
            '&',
            '~',
            '!',
        ];

        $result = [];

        // 单逻辑
        $findLogic = false;

        for ($i = 0; $i < strlen($content); $i++) {
            $temp = $content[$i];

            if (0 === $i && $this->isVarExpression($temp)) {
                $result[] = '$';
            }

            if (in_array($temp, $logic, true)) {
                // . 语法作为对象连接符
                if ('.' === $temp &&
                    isset($content[$i + 1]) &&
                    $this->isVarExpression($content[$i + 1]) &&
                    !in_array($content[$i + 1], [' ', '$'], true)) {
                    $result[] = '->';
                    $findLogic = false;
                }

                // -> 语法原生对象连接符
                elseif ('>' === $temp &&
                    $i > 0 &&
                    '-' === $content[$i - 1] &&
                    isset($content[$i + 1]) &&
                    !in_array($content[$i + 1], [' ', '$'], true)) {
                    $result[] = '>';
                    $findLogic = false;
                } else {
                    $findLogic = true;
                    $result[] = $temp;
                }

                continue;
            }

            if (true === $findLogic && ' ' !== $temp) {
                if ($this->isVarExpression($temp)) {
                    $result[] = '$';
                }

                $findLogic = false;
            }

            $result[] = $temp;
        }

        $content = implode('', $result);

        // 还原函数去掉开头的美元符号
        $content = preg_replace_callback('/(\$+?[a-z0-9\\_]+?\\s*?)\\(.+?\\)/',
            function ($match) {
                return substr($match[0], 1);
            },
            $content
        );

        return $content;
    }
解析表达式语法.

@param string $content

@return string