Flow\Lexer::lexText PHP Метод

lexText() защищенный Метод

protected lexText ( )
    protected function lexText()
    {
        $match = null;
        $tokens = array();
        // all text
        if (!preg_match('/(.*?)(' . preg_quote(self::COMMENT_START_TRIM) . '|' . preg_quote(self::COMMENT_START) . '|' . preg_quote(self::OUTPUT_START_TRIM) . '|' . preg_quote(self::OUTPUT_START) . '|' . preg_quote(self::BLOCK_START_TRIM) . '|' . preg_quote(self::BLOCK_START) . ')/As', $this->source, $match, null, $this->cursor)) {
            $text = substr($this->source, $this->cursor);
            if ($this->trim) {
                $text = preg_replace("/^[ \t]*\n?/", '', $text);
                $this->trim = false;
            }
            $tokens[] = new Token(Token::TEXT, $text, $this->line, $this->char);
            $this->adjustLineChar($text);
            $this->cursor = $this->end;
            return $tokens;
        }
        $this->cursor += strlen($match[0]);
        // text first
        $text = $match[1];
        $token = $match[2];
        if (strlen($text)) {
            if ($this->trim) {
                $text = preg_replace("/^[ \t]*\n?/", '', $text);
                $this->trim = false;
            }
            if ($token == self::COMMENT_START_TRIM || $token == self::BLOCK_START_TRIM || $token == self::OUTPUT_START_TRIM) {
                $text = rtrim($text, " \t");
            }
            $tokens[] = new Token(Token::TEXT, $text, $this->line, $this->char);
        }
        $this->adjustLineChar($match[1]);
        switch ($token) {
            case self::COMMENT_START_TRIM:
            case self::COMMENT_START:
                if (preg_match('/.*?(' . preg_quote(self::COMMENT_END_TRIM) . '|' . preg_quote(self::COMMENT_END) . ')/As', $this->source, $match, null, $this->cursor)) {
                    if ($match[1] == self::COMMENT_END_TRIM) {
                        $this->trim = true;
                    }
                    $this->cursor += strlen($match[0]);
                    $this->adjustLineChar($match[0]);
                }
                break;
            case self::BLOCK_START_TRIM:
            case self::BLOCK_START:
                if (preg_match('/(\\s*raw\\s*)(' . preg_quote(self::BLOCK_END_TRIM) . '|' . preg_quote(self::BLOCK_END) . ')(.*?)(' . preg_quote(self::BLOCK_START_TRIM) . '|' . preg_quote(self::BLOCK_START) . ')(\\s*endraw\\s*)(' . preg_quote(self::BLOCK_END_TRIM) . '|' . preg_quote(self::BLOCK_END) . ')/As', $this->source, $match, null, $this->cursor)) {
                    $raw = $match[3];
                    if ($match[2] == self::BLOCK_END_TRIM) {
                        $raw = preg_replace("/^[ \t]*\n?/", '', $raw);
                    }
                    if ($match[4] == self::BLOCK_START_TRIM) {
                        $raw = rtrim($raw, " \t");
                    }
                    if ($match[6] == self::BLOCK_END_TRIM) {
                        $this->trim = true;
                    }
                    $before = $token . $match[1] . $match[2];
                    $after = $match[3] . $match[4] . $match[5] . $match[6];
                    $this->cursor += strlen($match[0]);
                    $this->adjustLineChar($before);
                    $tokens[] = new Token(Token::TEXT, $raw, $this->line, $this->char);
                    $this->adjustLineChar($after);
                    $this->position = self::POSITION_TEXT;
                } else {
                    $tokens[] = new Token(Token::BLOCK_START, $token, $this->line, $this->char);
                    $this->adjustLineChar($token);
                    $this->position = self::POSITION_BLOCK;
                }
                break;
            case self::OUTPUT_START_TRIM:
            case self::OUTPUT_START:
                $tokens[] = new Token(Token::OUTPUT_START, $token, $this->line, $this->char);
                $this->adjustLineChar($token);
                $this->position = self::POSITION_OUTPUT;
                break;
        }
        return $tokens;
    }