public function parse(\Pinocchio\Pinocchio $pinocchio, \Pinocchio\Highlighter\HighlighterInterface $highlighter = null) {
        if (null === $highlighter) {
            $highlighter = new Pygments();
        }

        $code      = '';
        // $docBlocks is initialized with an empty element for the '<?php' start of the code
        $docBlocks = array('');

        $previousToken   = null;
        $commentRegexSet = $this->getCommentRegexSet();

        foreach ($this->tokenize($pinocchio->getSource()) as $token) {
            if (is_array($token)) {
                if ($this->isComment(token_name($token[0]))) {
                    $last     = '';
                    $token[1] = str_replace("\t", self::TAB_AS_SPACES, $token[1]);

                    if (token_name($previousToken[0]) === self::TOKEN_NAME_COMMENT && token_name($token[0]) === self::TOKEN_NAME_COMMENT) {
                        $last = array_pop($docBlocks);
                    } else {
                        $code .= self::CODEBLOCK_DELIMITER;
                    }

                    $docBlocks[] = $last . preg_replace($commentRegexSet, '$1', $token[1]);
                } else {
                    $code .= $token[1];
                }
            } else {
                $code .= $token;
            }

            $previousToken = $token;
        }

        $codeBlocks = explode(
            self::HIGHLIGHTED_CODEBLOCK_DELIMITER,
            $highlighter->highlight('php', $code)
        );

        foreach ($codeBlocks as $codeBlock) {
            $pinocchio->addCodeBlock(
                sprintf(
                    self::HIGHLIGHT_BLOCK_HTML_PATTERN,
                    str_replace("\t", ' ', $codeBlock)
                )
            );
        }

        $pinocchio->setDocBlocks($this->parseDocblocks($docBlocks));

        return $pinocchio;
    }