Source for file XMLpackagePageParser.inc
Documentation is available at XMLpackagePageParser.inc
* Parser for XML DocBook-based phpDocumentor tutorials
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2002-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 2002-2006 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: XMLpackagePageParser.inc,v 1.10 2006/05/22 01:07:28 cellog Exp $
* @tutorial tutorials.pkg
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
/** when <programlisting> is found */
define('PHPDOCUMENTOR_PDP_EVENT_PROGRAMLISTING', 600);
/** when <programlisting> is found */
define('PHPDOCUMENTOR_PDP_STATE_PROGRAMLISTING', 700);
/** when a DocBook <tag> is found */
define('PHPDOCUMENTOR_PDP_EVENT_TAG', 601);
/** when a DocBook <tag> is found */
define('PHPDOCUMENTOR_PDP_STATE_TAG', 701);
/** when <![CDATA[ ]]> is found */
define('PHPDOCUMENTOR_PDP_EVENT_CDATA', 602);
/** when <![CDATA[ ]]> is found */
define('PHPDOCUMENTOR_PDP_STATE_CDATA', 702);
/** when tag attributes name="value" are found */
define('PHPDOCUMENTOR_PDP_EVENT_ATTRIBUTES', 603);
/** when tag attributes name="value" are found */
define('PHPDOCUMENTOR_PDP_STATE_ATTRIBUTES', 703);
/** when tag attributes name="value" are found */
define('PHPDOCUMENTOR_PDP_EVENT_ENTITY', 604);
/** when tag attributes name="value" are found */
define('PHPDOCUMENTOR_PDP_STATE_ENTITY', 704);
* Used to parse XML DocBook-based tutorials
PHPDOCUMENTOR_PDP_EVENT_TAG => 'handleTag',
PHPDOCUMENTOR_PDP_EVENT_ATTRIBUTES => 'handleAttributes',
PHPDOCUMENTOR_PDP_EVENT_CDATA => 'handleCData',
PARSER_EVENT_NOEVENTS => 'defaultHandler',
PARSER_EVENT_COMMENTBLOCK => 'ignoreHandler',
PARSER_EVENT_OUTPHP => 'ignoreHandler',
PARSER_EVENT_QUOTE => 'handleQuote',
PHPDOCUMENTOR_PDP_EVENT_ENTITY => 'handleEntity',
* @var array the tag stack
/**#@+ @access private */
* @param string $parse_data
* @param array $tutorial for format, see {@link Io::getTutorials()}
* @staticvar integer used for recursion limiting if a handler for an event is not found
* @uses parserTutorial using {@link Publisher::PublishEvent()}, a new tutorial
* is created from the file parsed, and passed to the
function parse ($parse_data, $tutorial)
$parse_data = $tempparse->parse($parse_data,true,$tutorial['package'],$tutorial['subpackage'],
basename($tutorial['path']),$tutorial['category'], $tutorial['path']);
if (!is_array($parse_data) || count($parse_data) == 0)
// initialize variables so E_ALL error_reporting doesn't complain
$this->p_vars['start'] = true;
$this->wp->setup($parse_data,false);
$this->wp->setWhitespace(true);
if (isset ($this->curtag)) unset ($this->curtag);
$pevent = $this->p_vars['event_stack']->getEvent();
$this->p_vars['last_pevent'] = $lpevent;
if ($this->p_vars['last_pevent'] != $pevent)
// its a new event so the word parser needs to be reconfigured
$this->p_vars['last_word'] = $word;
$word = $this->wp->getWord();
if (0)//PHPDOCUMENTOR_DEBUG == true)
echo "----------------\n";
echo "LAST: |" . $this->p_vars['last_word'] . "|\n";
// echo "INDEX: ".$this->p_vars['curpar']."\n";
echo $this->wp->getPos() . " WORD: |$word|\n\n";
// echo '"'.$this->p_vars['quote_data']."\"\n";
if ($word !== false) $this->$handle($word, $pevent);
debug('WARNING: possible error, no XMLPackagePageParser handler for event number '. $pevent);
die("FATAL ERROR, recursion limit reached");
$this->p_vars['start'] = false;
} while (!($word === false));
if (count($this->_toc) && isset ($this->p_vars['toc']))
$a = $this->curtag->getTOC($this->p_vars['toc']);
$a->setPath($tutorial['path']);
$this->curtag->setTOC($this->p_vars['toc'],$a);
* @param string|parserInlineTagtoken
* @param integer parser event
function defaultHandler($word, $pevent)
function ignoreHandler($word, $pevent)
* this handler recognizes strings defined with double quotation marks (") and handles them correctly
* in any place that they legally appear in php code
function handleQuote($word, $pevent)
if ($this->p_flags['reset_quote_data'] === true)
$this->p_flags['reset_quote_data'] = false;
$this->p_vars['quote_data'] = "";
$this->p_vars['quote_data'] = $word;
$this->p_vars['quote_data'] .= $word;
$this->p_vars['quote_data'] = '{@id '. $this->p_vars['quote_data']->id. '}';
$this->curtag->name,$this->p_vars['attrname'],$this->p_vars['quote_data']);
$this->p_flags['reset_quote_data'] = true;
* Handles all XML DocBook tags
function handleTag($word, $pevent)
if (isset ($this->curtag) && $this->curtag->hasTitle() && $this->_gettoc && $this->_gettoc->name == $this->curtag->name)
if (isset ($this->_toc[$this->_cursection]))
$this->_toc[$this->_cursection]['title'] = $this->curtag->_title;
if ($this->p_vars['last_word'] == '<')
$this->p_flags['begin_tag'] = true;
// if (isset($this->curtag)) debug("pushed ".$this->curtag->name);
if (isset ($this->curtag))
} elseif ($this->p_vars['last_word'] == '</' || $word == '/>')
if (in_array($this->curtag->name, array('refentry', 'refsect1', 'refsect2', 'refsect3')))
if (!isset ($this->curtag->_id))
if (isset ($this->curtag->_title))
$title = $this->curtag->_title->getString();
$this->p_flags['begin_tag'] = false;
// debug("popped $tag ".$curtag->name.' I am '.$this->curtag->name);
if ($this->curtag->name == 'refsect1') $this->refsect1id = false;
if ($this->curtag->name == 'refsect2') $this->refsect2id = false;
if ($this->curtag->name == 'refsect3') $this->refsect3id = false;
$curtag->add($this->curtag);
// debug("added ".$this->curtag->name." to ".$curtag->name.' '.$curtag->id);
if ($this->p_flags['begin_tag'])
$this->p_flags['in_cdata'] = false;
$this->p_flags['start_attr'] = true;
$this->p_flags['end_attr'] = false;
function handleCData($word, $pevent)
$this->p_vars['toc'] = $this->curtag->getTOC();
if (is_string($word) && !$this->p_flags['in_cdata'])
if (is_string($word) && $word == '<![CDATA[')
$this->curtag->startCData();
$this->p_flags['in_cdata'] = true;
} elseif ($this->p_flags['in_cdata'] && is_string($word) && $word == ']]>')
$this->curtag->endCData();
$this->p_flags['in_cdata'] = false;
if ($this->p_flags['in_cdata'])
$this->curtag->addCData($word);
$this->curtag->add($word);
* Handle Entities like ”
function handleEntity($word, $pevent)
if (!isset ($this->p_vars['entity_name']))
$this->p_vars['entity_name'] = '';
if ($word && !$e) $this->p_vars['entity_name'] = $word;
unset ($this->p_vars['entity_name']);
$this->curtag->add($entity);
* Handle Tag attributes name="value"
function handleAttributes($word, $pevent)
$this->p_flags['start_attr'] = false;
$this->p_vars['end_attr'] = true;
if ($this->p_flags['start_attr'])
$this->p_vars['attrname'] = $word;
if (isset ($this->p_vars['attrname']))
$value = $this->p_vars['quote_data'];
{ // "inherit" the parent section's id, so
// <refsect1 id="{@id test"}> <!-- id is 'test' -->
// <refsect2 id="{@id me}"> <!-- id is 'test.me' -->
// <refsect3 id="{@id out}"> <!-- id is 'test.me.out' -->
// <example id="{@id withexample}"> <!-- id is 'test.me.out.withexample' -->
if ($this->curtag->name == 'refsect1')
if ($this->curtag->name == 'refsect2')
if ($this->curtag->name == 'refsect3')
// debug($value->id.' is now '.$a.$value->id);
$value->id = $a . $value->id;
if (isset ($this->_toc[$this->_cursection]))
$this->_toc[$this->_cursection]['id'] = $value;
// debug("set gettoc to ".$this->curtag->name .' '. $value->id);
$this->_gettoc = $this->curtag;
$this->curtag->addAttribute($this->p_vars['attrname'],$value);
unset ($this->p_vars['attrname']);
$this->p_flags['start_attr'] = true;
$this->p_flags['end_attr'] = false;
$this->wp->setPos($this->wp->getPos() - strlen($word));
$this->wp->setPos($this->wp->getPos() - strlen($word));
$this->p_flags['start_attr'] = true;
$this->p_flags['end_attr'] = false;
$this->wp->setPos($this->wp->getPos() - strlen($word));
* setup the parser tokens, and the pushEvent/popEvent arrays
* @see $tokens, $pushEvent, $popEvent
if (isset ($this->p_vars['toc'])) unset ($this->p_vars['toc']);
// For each event word to event mapings
##########################
##########################
##########################
##########################
##########################
##########################
##########################
PHPDOCUMENTOR_PDP_EVENT_COMMENT => "PHPDOCUMENTOR_PDP_EVENT_COMMENT",
PHPDOCUMENTOR_PDP_EVENT_PI => "PHPDOCUMENTOR_PDP_EVENT_PI",
if (isset ($lookup[$value]))
|