Source for file TutorialHighlightParser.inc
Documentation is available at TutorialHighlightParser.inc
* Source Code Highlighting
* The classes in this file are responsible for the dynamic @example, and
* <programlisting role="tutorial"> tags output. Using the
* WordParser, the phpDocumentor_TutorialHighlightParser
* retrieves PHP tokens one by one from the array generated by
* {@link WordParser} source retrieval functions
* and then highlights them individually.
* It accomplishes this highlighting through the assistance of methods in
* the output Converter passed to its parse() method, and then returns the
* fully highlighted source as a string
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2003-2006 Gregory Beaver
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @copyright 2003-2006 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: TutorialHighlightParser.inc,v 1.4 2006/05/01 04:13:51 cellog Exp $
* @tutorial tags.example.pkg, tags.filesource.pkg
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
* Highlights source code using {@link parse()}
/**#@+ @access private */
* Highlighted source is built up in this string
* contents of the current source code line as it is parsed
* Used to retrieve highlighted tokens
* @var Converter a descendant of Converter
* Path to file being highlighted, if this is from a @filesource tag
* @var false|stringfull path
var $eventHandlers = array(
TUTORIAL_EVENT_NOEVENTS => 'defaultHandler',
TUTORIAL_EVENT_ITAG => 'defaultHandler',
TUTORIAL_EVENT_ATTRIBUTE => 'attrHandler',
TUTORIAL_EVENT_OPENTAG => 'defaultHandler',
TUTORIAL_EVENT_CLOSETAG => 'defaultHandler',
TUTORIAL_EVENT_ENTITY => 'defaultHandler',
TUTORIAL_EVENT_COMMENT => 'defaultHandler',
TUTORIAL_EVENT_SINGLEQUOTE => 'defaultHandler',
TUTORIAL_EVENT_DOUBLEQUOTE => 'defaultHandler',
* @uses Converter::SourceLine() encloses {@link $_line} in a
* converter-specific format
$this->_line .= $this->_converter->flushHighlightCache();
$this->_output .= $this->_converter->SourceLine($this->_pv_curline + 1, $this->_line, $this->_path);
* Start the parsing at a certain line number
$this->_wp->linenum = $num;
* The parse() method is a do...while() loop that retrieves tokens one by
* one from the {@link $_event_stack}, and uses the token event array set up
* by the class constructor to call event handlers.
* The event handlers each process the tokens passed to them, and use the
* {@link _addoutput()} method to append the processed tokens to the
* {@link $_line} variable. The word parser calls {@link newLineNum()}
* every time a line is reached.
* In addition, the event handlers use special linking functions
* {@link _link()} and its cousins (_classlink(), etc.) to create in-code
* hyperlinks to the documentation for source code elements that are in the
* @uses setupStates() initialize parser state variables
* @uses configWordParser() pass $parse_data to prepare retrieval of tokens
* @param false|stringfull path to file with @filesource tag, if this
* @param false|integerstarting line number from {@}source linenum}
* @staticvar integer used for recursion limiting if a handler for
function parse ($parse_data, &$converter, $filesourcepath = false, $linenum = false)
$parse_data = str_replace(array("\r\n", "\t"), array("\n", ' '), $parse_data);
$this->_converter = &$converter;
$converter->startHighlight();
$this->_path = $filesourcepath;
if ($linenum !== false) $this->setLineNum($linenum);
// initialize variables so E_ALL error_reporting doesn't complain
$pevent = $this->_event_stack->getEvent();
$this->_last_pevent = $lpevent;
$this->_wp->setWhitespace(true);
$dbg_linenum = $this->_wp->linenum;
$dbg_pos = $this->_wp->getPos();
$this->_pv_last_word = $word;
$this->_pv_curline = $this->_wp->linenum;
$word = $this->_wp->getWord();
if (0)//PHPDOCUMENTOR_DEBUG == true)
echo "|" . $this->_pv_last_word;
// echo "LINE: ".$this->_line."\n";
// echo "OUTPUT: ".$this->_output."\n";
echo $dbg_linenum. '-'. $dbg_pos . ": ";
echo "-------------------\n\n\n";
if (isset ($this->eventHandlers[$pevent]))
$handle = $this->eventHandlers[$pevent];
$this->$handle($word, $pevent);
debug('WARNING: possible error, no handler for event number '. $pevent);
die("FATAL ERROR, recursion limit reached");
} while (!($word === false));
* All Event Handlers use {@link checkEventPush()} and
* {@link checkEventPop()} to set up the event stack and parser state.
* @param string|arraytoken value
* @param integer parser event from {@link Parser.inc}
* Most tokens only need highlighting, and this method handles them
function defaultHandler($word, $pevent)
$this->_wp->backupPos($word);
$this->_addoutput($word);
* Most tokens only need highlighting, and this method handles them
function attrHandler($word, $pevent)
$this->_addoutput($word);
$this->_wp->backupPos($word);
$this->_addoutput($word);
* This method adds output to {@link $_line}
* If a string with variables like "$test this" is present, then special
* handling is used to allow processing of the variable in context.
function _addoutput($word, $preformatted = false)
$a = $this->_event_stack->getEvent();
$this->_line .= $this->_converter->highlightTutorialSource($type[$a], $word);
$this->_line .= $this->_converter->flushHighlightCache();
$this->_line .= $this->_converter->postProcess($word);
* tell the parser's WordParser {@link $wp} to set up tokens to parse words by.
* tokens are word separators. In English, a space or punctuation are examples of tokens.
* In PHP, a token can be a ;, a parenthesis, or even the word "function"
* @param $value integer an event number
$this->_wp->setSeperator($this->tokens[($e + 100)]);
* this function checks whether parameter $word is a token for pushing a new event onto the Event Stack.
* @return mixed returns false, or the event number
$this->_event_stack->pushEvent($e);
* this function checks whether parameter $word is a token for popping the current event off of the Event Stack.
* @return mixed returns false, or the event number popped off of the stack
if (!isset ($this->popEvent[$pevent])) return false;
return $this->_event_stack->popEvent();
* Initialize all parser state variables
* @param boolean true if we are highlighting an inline {@}source} tag's
* @param false|stringname of class we are going to start from
* @uses $_wp sets to a new {@link phpDocumentor_HighlightWordParser}
$this->_wp->setup($parsedata);
$this->_event_stack->popEvent();
$this->_pv_linenum = null;
$this->_pv_next_word = false;
* Initialize the {@link $tokenpushEvent, $wordpushEvent} arrays
$this->allowableInlineTags = $GLOBALS['_phpDocumentor_inline_tutorial_tags_allowed'];
$this->inlineTagHandlers = array('*' => 'handleDefaultInlineTag');
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
if (isset ($lookup[$value]))
define("TUTORIAL_EVENT_NOEVENTS" , 1);
/** currently in starting state */
define("STATE_TUTORIAL_NOEVENTS" , 101);
/** used when an {@}inline tag} is found */
define("TUTORIAL_EVENT_ITAG" , 2);
/** currently parsing an {@}inline tag} */
define("STATE_TUTORIAL_ITAG" , 102);
/** used when an open <tag> is found */
define("TUTORIAL_EVENT_OPENTAG" , 3);
/** currently parsing an open <tag> */
define("STATE_TUTORIAL_OPENTAG" , 103);
/** used when a <tag attr="attribute"> is found */
define("TUTORIAL_EVENT_ATTRIBUTE" , 4);
/** currently parsing an open <tag> */
define("STATE_TUTORIAL_ATTRIBUTE" , 104);
/** used when a close </tag> is found */
define("TUTORIAL_EVENT_CLOSETAG" , 5);
/** currently parsing a close </tag> */
define("STATE_TUTORIAL_CLOSETAG" , 105);
/** used when an &entity; is found */
define("TUTORIAL_EVENT_ENTITY" , 6);
/** currently parsing an &entity; */
define("STATE_TUTORIAL_ENTITY" , 106);
/** used when a <!-- comment --> is found */
define("TUTORIAL_EVENT_COMMENT" , 7);
/** currently parsing a <!-- comment --> */
define("STATE_TUTORIAL_COMMENT" , 107);
/** used when a <!-- comment --> is found */
define("TUTORIAL_EVENT_SINGLEQUOTE" , 8);
/** currently parsing a <!-- comment --> */
define("STATE_TUTORIAL_SINGLEQUOTE" , 108);
/** used when a <!-- comment --> is found */
define("TUTORIAL_EVENT_DOUBLEQUOTE" , 9);
/** currently parsing a <!-- comment --> */
define("STATE_TUTORIAL_DOUBLEQUOTE" , 109);
|