protected function parseTokens(array $tokens)
    {
        //Current active token
        $activeToken = [];

        //Some blocks can be named as parent. We have to make sure we closing the correct one
        $activeLevel = 0;

        //Content to represent full tag declaration (including body)
        $activeContent = [];

        foreach ($tokens as $token) {
            $tokenType = $token[HtmlTokenizer::TOKEN_TYPE];

            if (empty($activeToken)) {
                switch ($tokenType) {
                    case HtmlTokenizer::TAG_VOID:
                    case HtmlTokenizer::TAG_SHORT:
                        //Token will be clarified using Supervisor
                        $this->mountToken($token);
                        break;

                    case HtmlTokenizer::TAG_OPEN:
                        $activeToken = $token;
                        break;

                    case HtmlTokenizer::TAG_CLOSE:
                        if ($this->compiler->getSyntax()->isStrict()) {
                            throw new StrictSyntaxException(
                                "Unpaired close tag '{$token[HtmlTokenizer::TOKEN_NAME]}'.",
                                $token
                            );
                        }
                        break;
                    case HtmlTokenizer::PLAIN_TEXT:
                        //Everything outside any tag
                        $this->mountContent([$token]);
                        break;
                }

                continue;
            }

            if (
                $tokenType != HtmlTokenizer::PLAIN_TEXT
                && $token[HtmlTokenizer::TOKEN_NAME] == $activeToken[HtmlTokenizer::TOKEN_NAME]
            ) {
                if ($tokenType == HtmlTokenizer::TAG_OPEN) {
                    $activeContent[] = $token;
                    $activeLevel++;
                } elseif ($tokenType == HtmlTokenizer::TAG_CLOSE) {
                    if ($activeLevel === 0) {
                        //Closing current token
                        $this->mountToken($activeToken, $activeContent, $token);
                        $activeToken = $activeContent = [];
                    } else {
                        $activeContent[] = $token;
                        $activeLevel--;
                    }
                } else {
                    //Short tag with same name (used to call for parent content)s
                    $activeContent[] = $token;
                }

                continue;
            }

            //Collecting token content
            $activeContent[] = $token;
        }

        //Everything after last tag
        $this->mountContent($activeContent);
    }
protected function parseTokens(array $tokens)
    {
        //Current active token
        $activeToken = [];

        //Some blocks can be named as parent. We have to make sure we closing the correct one
        $activeLevel = 0;

        //Content to represent full tag declaration (including body)
        $activeContent = [];

        foreach ($tokens as $token) {
            $tokenType = $token[HtmlTokenizer::TOKEN_TYPE];

            if (empty($activeToken)) {
                switch ($tokenType) {
                    case HtmlTokenizer::TAG_VOID:
                    case HtmlTokenizer::TAG_SHORT:
                        //Token will be clarified using Supervisor
                        $this->mountToken($token);
                        break;

                    case HtmlTokenizer::TAG_OPEN:
                        $activeToken = $token;
                        break;

                    case HtmlTokenizer::TAG_CLOSE:
                        if ($this->compiler->getSyntax()->isStrict()) {
                            throw new StrictSyntaxException(
                                "Unpaired close tag '{$token[HtmlTokenizer::TOKEN_NAME]}'.",
                                $token
                            );
                        }
                        break;
                    case HtmlTokenizer::PLAIN_TEXT:
                        //Everything outside any tag
                        $this->mountContent([$token]);
                        break;
                }

                continue;
            }

            if (
                $tokenType != HtmlTokenizer::PLAIN_TEXT
                && $token[HtmlTokenizer::TOKEN_NAME] == $activeToken[HtmlTokenizer::TOKEN_NAME]
            ) {
                if ($tokenType == HtmlTokenizer::TAG_OPEN) {
                    $activeContent[] = $token;
                    $activeLevel++;
                } elseif ($tokenType == HtmlTokenizer::TAG_CLOSE) {
                    if ($activeLevel === 0) {
                        //Closing current token
                        $this->mountToken($activeToken, $activeContent, $token);
                        $activeToken = $activeContent = [];
                    } else {
                        $activeContent[] = $token;
                        $activeLevel--;
                    }
                } else {
                    //Short tag with same name (used to call for parent content)s
                    $activeContent[] = $token;
                }

                continue;
            }

            //Collecting token content
            $activeContent[] = $token;
        }

        //Everything after last tag
        $this->mountContent($activeContent);
    }
protected function parseTokens ( array $ tokens ) { //Current active token $ activeToken = [ ] ; //Some blocks can be named as parent. We have to make sure we closing the correct one $ activeLevel = 0 ; //Content to represent full tag declaration (including body) $ activeContent = [ ] ; foreach ( $ tokens as $ token ) { $ tokenType = $ token [ HtmlTokenizer :: TOKEN_TYPE ] ; if ( empty ( $ activeToken ) ) { switch ( $ tokenType ) { case HtmlTokenizer :: TAG_VOID : case HtmlTokenizer :: TAG_SHORT : //Token will be clarified using Supervisor $ this -> mountToken ( $ token ) ; break ; case HtmlTokenizer :: TAG_OPEN : $ activeToken = $ token ; break ; case HtmlTokenizer :: TAG_CLOSE : if ( $ this -> compiler -> getSyntax ( ) -> isStrict ( ) ) { throw new StrictSyntaxException ( "Unpaired close tag '{$token[HtmlTokenizer::TOKEN_NAME]}'." , $ token ) ; } break ; case HtmlTokenizer :: PLAIN_TEXT : //Everything outside any tag $ this -> mountContent ( [ $ token ] ) ; break ; } continue ; } if ( $ tokenType != HtmlTokenizer :: PLAIN_TEXT && $ token [ HtmlTokenizer :: TOKEN_NAME ] == $ activeToken [ HtmlTokenizer :: TOKEN_NAME ] ) { if ( $ tokenType == HtmlTokenizer :: TAG_OPEN ) { $ activeContent [ ] = $ token ; $ activeLevel ++ ; } elseif ( $ tokenType == HtmlTokenizer :: TAG_CLOSE ) { if ( $ activeLevel === 0 ) { //Closing current token $ this -> mountToken ( $ activeToken , $ activeContent , $ token ) ; $ activeToken = $ activeContent = [ ] ; } else { $ activeContent [ ] = $ token ; $ activeLevel -- ; } } else { //Short tag with same name (used to call for parent content)s $ activeContent [ ] = $ token ; } continue ; } //Collecting token content $ activeContent [ ] = $ token ; } //Everything after last tag $ this -> mountContent ( $ activeContent ) ; }
Parse set of tokens provided by html Tokenizer and create blocks and other control
constructions. Basically it will try to created html tree.

@param array $tokens

@throws StrictSyntaxException
Parse set of tokens provided by html Tokenizer and create blocks and other control constructions . Basically it will try to created html tree .