Flow\JSONPath\JSONPathLexer::parseExpressionTokens PHP Метод

parseExpressionTokens() публичный Метод

    public function parseExpressionTokens()
    {
        $dotIndexDepth = 0;
        $squareBracketDepth = 0;
        $capturing = false;
        $tokenValue = '';
        $tokens = [];
        for ($i = 0; $i < $this->expressionLength; $i++) {
            $char = $this->expression[$i];
            if ($squareBracketDepth === 0) {
                if ($char === '.') {
                    if ($this->lookAhead($i, 1) === ".") {
                        $tokens[] = new JSONPathToken(JSONPathToken::T_RECURSIVE, null);
                    }
                    continue;
                }
            }
            if ($char === '[') {
                $squareBracketDepth += 1;
                if ($squareBracketDepth === 1) {
                    continue;
                }
            }
            if ($char === ']') {
                $squareBracketDepth -= 1;
                if ($squareBracketDepth === 0) {
                    continue;
                }
            }
            /*
             * Within square brackets
             */
            if ($squareBracketDepth > 0) {
                $tokenValue .= $char;
                if ($this->lookAhead($i, 1) === ']' && $squareBracketDepth === 1) {
                    $tokens[] = $this->createToken($tokenValue);
                    $tokenValue = '';
                }
            }
            /*
             * Outside square brackets
             */
            if ($squareBracketDepth === 0) {
                $tokenValue .= $char;
                // Double dot ".."
                if ($char === "." && $dotIndexDepth > 1) {
                    $tokens[] = $this->createToken($tokenValue);
                    $tokenValue = '';
                    continue;
                }
                if ($this->lookAhead($i, 1) === '.' || $this->lookAhead($i, 1) === '[' || $this->atEnd($i)) {
                    $tokens[] = $this->createToken($tokenValue);
                    $tokenValue = '';
                    $dotIndexDepth -= 1;
                }
            }
        }
        if ($tokenValue !== '') {
            $tokens[] = $this->createToken($tokenValue);
            $tokenValue = '';
        }
        return $tokens;
    }