home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / ParserDescCleanup.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  56.8 KB  |  1,456 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | phpDocumentor                                                          |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |
  7. // | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |
  8. // | Web           http://www.phpdoc.org                                    |
  9. // | Mirror        http://phpdocu.sourceforge.net/                          |
  10. // | PEAR          http://pear.php.net/package-info.php?pacid=137           |
  11. // +------------------------------------------------------------------------+
  12. // | This source file is subject to version 3.00 of the PHP License,        |
  13. // | that is available at http://www.php.net/license/3_0.txt.               |
  14. // | If you did not receive a copy of the PHP license and are unable to     |
  15. // | obtain it through the world-wide-web, please send a note to            |
  16. // | license@php.net so we can mail you a copy immediately.                 |
  17. // +------------------------------------------------------------------------+
  18. //
  19.  
  20. /**
  21.  * All of the functions to clean up and handle the long description
  22.  * of a DocBlock are in this file.
  23.  *
  24.  * The primary functionality is based on Parser and WordParser, and modified to recognize
  25.  * only the tokens defined in the PHPDOCUMENTOR_PDP_* constants
  26.  * @see Parser, WordParser
  27.  * @package phpDocumentor
  28.  * @subpackage Parsers
  29.  * @author Greg Beaver <cellog@users.sourceforge.net>
  30.  * @since 1.2
  31.  */
  32. /**#@+
  33.  * {@link parserDescParser} token constants
  34.  */
  35. /** when <<code>> is found in a desc */
  36. define('PHPDOCUMENTOR_PDP_EVENT_CODE', 600);
  37. /** when <<code>> is found in a desc */
  38. define('PHPDOCUMENTOR_PDP_STATE_CODE', 700);
  39. /** when <<p>> is found in a desc */
  40. define('PHPDOCUMENTOR_PDP_EVENT_P', 601);
  41. /** when <<p>> is found in a desc */
  42. define('PHPDOCUMENTOR_PDP_STATE_P', 701);
  43. /** when \n\n is found in a desc */
  44. define('PHPDOCUMENTOR_PDP_EVENT_DOUBLECR', 602);
  45. /** when \n\n is found in a desc */
  46. define('PHPDOCUMENTOR_PDP_STATE_DOUBLECR', 702);
  47. /** when <<pre>> is found in a desc */
  48. define('PHPDOCUMENTOR_PDP_EVENT_PRE', 603);
  49. /** when <<pre>> is found in a desc */
  50. define('PHPDOCUMENTOR_PDP_STATE_PRE', 703);
  51. /** when <<ul>>/<<ol>> is found in a desc */
  52. define('PHPDOCUMENTOR_PDP_EVENT_LIST', 604);
  53. /** when <<ul>>/<<ol>> is found in a desc */
  54. define('PHPDOCUMENTOR_PDP_STATE_LIST', 704);
  55. /** when <<b>> is found in a desc */
  56. define('PHPDOCUMENTOR_PDP_EVENT_B', 605);
  57. /** when <<b>> is found in a desc */
  58. define('PHPDOCUMENTOR_PDP_STATE_B', 705);
  59. /** when <<i>> is found in a desc */
  60. define('PHPDOCUMENTOR_PDP_EVENT_I', 606);
  61. /** when <<i>> is found in a desc */
  62. define('PHPDOCUMENTOR_PDP_STATE_I', 706);
  63. /** when <<br>> is found in a desc */
  64. define('PHPDOCUMENTOR_PDP_EVENT_BR', 607);
  65. /** when <<br>> is found in a desc */
  66. define('PHPDOCUMENTOR_PDP_STATE_BR', 707);
  67. /** when the << potential escape for tags is found in a desc */
  68. define('PHPDOCUMENTOR_PDP_EVENT_ESCAPE',608);
  69. /** when the << potential escape for tags is found in a desc */
  70. define('PHPDOCUMENTOR_PDP_STATE_ESCAPE',708);
  71. /** when << /pre>> is found in a <<pre>><</pre>> section */
  72. define('PHPDOCUMENTOR_PDP_EVENT_ESCAPE_PRE',609);
  73. /** when << /pre>> is found in a <<pre>><</pre>> section */
  74. define('PHPDOCUMENTOR_PDP_STATE_ESCAPE_PRE',709);
  75. /** when << /code>> is found in a <<code>><</code>> section  */
  76. define('PHPDOCUMENTOR_PDP_EVENT_ESCAPE_CODE',610);
  77. /** when << /code>> is found in a <<code>><</code>> section  */
  78. define('PHPDOCUMENTOR_PDP_STATE_ESCAPE_CODE',710);
  79. /** when <<var>> is found in a desc  */
  80. define('PHPDOCUMENTOR_PDP_EVENT_VAR',611);
  81. /** when <<var>> is found in a desc  */
  82. define('PHPDOCUMENTOR_PDP_STATE_VAR',711);
  83. /** when <<samp>> is found in a desc  */
  84. define('PHPDOCUMENTOR_PDP_EVENT_SAMP',612);
  85. /** when <<samp>> is found in a desc  */
  86. define('PHPDOCUMENTOR_PDP_STATE_SAMP',712);
  87. /** when <<kbd>> is found in a desc  */
  88. define('PHPDOCUMENTOR_PDP_EVENT_KBD',613);
  89. /** when <<kbd>> is found in a desc  */
  90. define('PHPDOCUMENTOR_PDP_STATE_KBD',713);
  91. /** when a simple list is found in a desc
  92.  *
  93.  * like
  94.  * <pre>
  95.  *  o item 1
  96.  *  o item 2
  97.  * </pre>
  98.  */
  99. define('PHPDOCUMENTOR_PDP_EVENT_SIMLIST',614);
  100. /** when a simple list is found in a desc
  101.  *
  102.  * like
  103.  * <pre>
  104.  *  o item 1
  105.  *  o item 2
  106.  * </pre>
  107.  */
  108. define('PHPDOCUMENTOR_PDP_STATE_SIMLIST',714);
  109. /**#@-*/
  110. /**
  111. * Like WordParser but designed to handle an array with strings and
  112. * {@link parserInlineTag}s
  113. * @package phpDocumentor
  114. * @subpackage WordParsers
  115. * @author Greg Beaver <cellog@users.sourceforge.net>
  116. * @since 1.2
  117. */
  118. class ObjectWordParser extends WordParser
  119. {
  120.     /**
  121.      * Determines whether text searching is case-sensitive or not
  122.      * @access private
  123.      */
  124.     var $_casesensitive = false;
  125.     
  126.     function ObjectWordParser($casesensitive = false)
  127.     {
  128.         $this->_casesensitive = $casesensitive;
  129.     }
  130.     
  131.     /**
  132.      * Set the word parser to go.
  133.      *
  134.      * @param array {@link parserStringWithInlineTags::$value} style-array, with
  135.      *              alternating text and inline tags
  136.      */
  137.     function setup(&$input)
  138.     {
  139. //        if (is_string($input[0])) $input[0] = ltrim($input[0]);
  140.         $this->data = & $input;
  141.         $this->pos = 0;
  142.         $this->linenum = 0;
  143.         $this->linenumpos = 0;
  144.         $this->cache = array();
  145.         reset($this->data);
  146.         list($this->index,) = each($this->data);
  147.         if (!is_object($this->data[$this->index]))
  148.         $this->size = strlen($this->data[$this->index]);
  149.         else $this->size = 0;
  150.         //$this->run = 0;
  151.         //$this->word = WORD_PARSER_RET_WORD;
  152.     }
  153.     
  154.     function getWord()
  155.     {
  156.         if (!isset($this->data[$this->index])) return false;
  157.         // return any inline tags unchanged
  158.         if (is_object($this->data[$this->index]))
  159.         {
  160.             $index = $this->index;
  161.             list($this->index,) = each($this->data);
  162.             $this->pos = 0;
  163.             if ($this->index)
  164.             {
  165.                 if (!is_object($this->data[$this->index]))
  166.                 $this->size = strlen($this->data[$this->index]);
  167.                 else $this->size = 0;
  168.                 $this->cache = array();
  169.                 return $this->data[$index];
  170.             } else
  171.             {
  172.                 return false;
  173.             }
  174.         }
  175.         //$st = $this->mtime();
  176.         if ($this->size == $this->pos)
  177.         {
  178.             // cycle to next line in the array
  179.             list($this->index,) = each($this->data);
  180.             if (!$this->index) return false;
  181.             $this->pos = 0;
  182.             if (!is_object($this->data[$this->index]))
  183.             $this->size = strlen($this->data[$this->index]);
  184.             else $this->size = 0;
  185.             $this->cache = array();
  186.             return $this->getWord();
  187.         }
  188.  
  189.         $npos = $this->size;
  190.         if (is_array($this->wordseperators))
  191.         {
  192.             //$this->wordseperators = array();
  193.             foreach($this->wordseperators as $sep)
  194.             {
  195.                 if (isset($this->cache[$sep]))
  196.                 $tpos = $this->cache[$sep];
  197.                 else
  198.                 $tpos = false;
  199.                 if ($tpos < $this->pos || !is_int($tpos))
  200.                 {
  201.                     if ($this->_casesensitive)
  202.                         $tpos = strpos($this->data[$this->index],$sep,$this->pos);
  203.                     else
  204.                         $tpos = strpos(strtolower($this->data[$this->index]),$sep,$this->pos);
  205.                 }
  206.             
  207.                 if ( ($tpos < $npos) && !($tpos === false))
  208.                 {
  209.                     //echo trim($sep) . "=$tpos\n";
  210.                     $npos = $tpos;
  211.                     $seplen = strlen($sep);
  212.                 } 
  213.                   else if (!($tpos === false))
  214.                 {
  215.                     $this->cache[$sep] = $tpos;
  216.                 }
  217.             }
  218.         } else {
  219.             // its time to cycle
  220.             return "";
  221.         }
  222.  
  223.         $len = $npos - $this->pos;
  224.         if ($len == 0)
  225.         {
  226.             $len = $seplen;
  227.         }
  228.  
  229.         //$st3 = $this->mtime();
  230.         $word = substr($this->data[$this->index],$this->pos,$len);
  231.         
  232.         // Change random other os newlines to the unix one
  233.         if ($word == "\r" || $word == "\r\n")
  234.         {
  235.             $word = "\n";
  236.         }
  237.         
  238.         if ($this->linenumpos <= $this->pos)
  239.         {
  240.             $this->linenumpos = $this->pos + $len;
  241.             $this->linenum += count(explode("\n",$word)) - 1;
  242.         }
  243.  
  244.         if ($this->getsource)
  245.         {
  246.             $this->source .= $word;
  247.         }
  248.         $this->pos = $this->pos + $len;
  249.         //$this->word = WORD_PARSER_RET_SEP;
  250.  
  251.         // Things like // commenats rely on the newline to find their end so im going to have to return them
  252.         // never return worthless white space /t ' '
  253.         if ($this->returnWhiteSpace == false)
  254.         {
  255.             if (strlen(trim($word)) == 0 && $word != "\n") 
  256.             {
  257.                 $word = $this->getWord();
  258.             }
  259.         }
  260.         //$this->time3 = $this->time3 + ($this->mtime() - $st3);
  261.         //$this->time = $this->time + ($this->mtime() - $st);
  262.         return $word;
  263.     }
  264.     
  265.     /**
  266.      * Determine if the next word is an inline tag
  267.      * @return boolean
  268.      */
  269.     function nextIsObjectOrNonNL()
  270.     {
  271.         return (($this->size == $this->pos) && isset($this->data[$this->index + 1])
  272.             && is_object($this->data[$this->index + 1])) ||
  273.                (($this->size > $this->pos) && !in_array($this->data[$this->index]{$this->pos}, array("\n", "\r")));
  274.     }
  275. }
  276.  
  277. /**
  278.  * Parses a DocBlock description to retrieve abstract representations of
  279.  * <<pre>>,<<code>>,<<p>>,<<ul>>,<<ol>>,<<li>>,<<b>>,<<i>>
  280.  * @tutorial phpDocumentor.howto.pkg#basics.desc
  281.  * @package phpDocumentor
  282.  * @subpackage Parsers
  283.  * @author Greg Beaver <cellog@users.sourceforge.net>
  284.  * @since 1.2
  285.  */
  286. class parserDescParser extends Parser
  287. {
  288.     /**#@+
  289.      * @access private
  290.      */
  291.     /**
  292.      * @var array
  293.      */
  294.     var $eventHandlers = array(PHPDOCUMENTOR_PDP_EVENT_CODE => 'handleCode',
  295.                                PHPDOCUMENTOR_PDP_EVENT_PRE => 'handlePre',
  296.                                PHPDOCUMENTOR_PDP_EVENT_P => 'handleP',
  297.                                PHPDOCUMENTOR_PDP_EVENT_DOUBLECR => 'handleDoubleCR',
  298.                                PHPDOCUMENTOR_PDP_EVENT_LIST => 'handleList',
  299.                                PHPDOCUMENTOR_PDP_EVENT_B => 'handleB',
  300.                                PHPDOCUMENTOR_PDP_EVENT_I => 'handleI',
  301.                                PHPDOCUMENTOR_PDP_EVENT_VAR => 'handleVar',
  302.                                PHPDOCUMENTOR_PDP_EVENT_KBD => 'handleKbd',
  303.                                PHPDOCUMENTOR_PDP_EVENT_SAMP => 'handleSamp',
  304.                                PHPDOCUMENTOR_PDP_EVENT_BR => 'handleBr',
  305.                                PHPDOCUMENTOR_PDP_EVENT_ESCAPE => 'handleEscape',
  306.                                PHPDOCUMENTOR_PDP_EVENT_ESCAPE_CODE => 'handleEscapeCode',
  307.                                PHPDOCUMENTOR_PDP_EVENT_ESCAPE_PRE => 'handleEscapePre',
  308.                                PHPDOCUMENTOR_PDP_EVENT_SIMLIST => 'handleSimpleList',
  309.                                PARSER_EVENT_NOEVENTS => 'defaultHandler',
  310.                                );
  311.     
  312.     /**
  313.      * @var array
  314.      */
  315.     var $pars = array();
  316.     /**
  317.      * Determines whether parsing of <p> tags will occur, or double CR will
  318.      * be used
  319.      * @var boolean
  320.      */
  321.     var $parse_Ps;
  322.     /**
  323.      * Context stack.
  324.      *
  325.      * Values can be 'normal', or any tag container like 'my_i', 'my_b'.  This
  326.      * is used to determine which tag text or nested tags should be added to
  327.      * @var array
  328.      */
  329.     var $_context = array('normal');
  330.     /**#@-*/
  331.     
  332.     /**
  333.      * sets $wp to be a {@link ObjectWordParser}
  334.      * 
  335.      * $wp is the word parser that retrieves tokens
  336.      */
  337.     function parserDescParser()
  338.     {
  339.         $this->wp = new ObjectWordParser;
  340.     }
  341.     
  342.     /**
  343.      * Parse a long or short description for tags
  344.      *
  345.      * @param array array of strings or {@link parserInlineTag}s
  346.      * @param boolean true if the description is a short description. (only 1 paragraph allowed in short desc)
  347.      * @param string name of the class to instantiate for each paragraph.  parserDesc for desc/sdesc,
  348.      *               parserStringWithInlineTags for tag data
  349.      * @staticvar integer used for recursion limiting if a handler for an event is not found
  350.      */
  351.     function parse (&$parse_data,$sdesc = false,$ind_type = 'parserDesc')
  352.     {
  353.         static $endrecur = 0;
  354.         global $_phpDocumentor_setting;
  355.         if (!is_array($parse_data) || count($parse_data) == 0)
  356.         {
  357.             return false;
  358.         }
  359.         $this->p_vars['indtype'] = $ind_type;
  360.         $this->setupStates($sdesc);
  361.         if (isset($_phpDocumentor_setting['javadocdesc']) && $_phpDocumentor_setting['javadocdesc'] == 'on')
  362.             $this->parse_Ps = true;
  363.  
  364.         // initialize variables so E_ALL error_reporting doesn't complain
  365.         $pevent = 0;
  366.         $word = 0;
  367.         $this->p_vars['curpar'] = 0;
  368.         $this->pars = array();
  369.         $this->p_vars['start'] = true;
  370.         $this->p_vars['event_stack'] = new EventStack;
  371.  
  372.         $this->wp->setup($parse_data,$sdesc);
  373.         $this->wp->setWhitespace(true);
  374.         $this->p_vars['list_count'] = 0;
  375.         if ($sdesc) $this->p_vars['start'] = false;
  376.         do
  377.         {
  378.             if (!isset($this->pars[$this->p_vars['curpar']])) $this->pars[$this->p_vars['curpar']] = new $ind_type;
  379.             $lpevent = $pevent;
  380.             $pevent = $this->p_vars['event_stack']->getEvent();
  381.             if ($lpevent != $pevent)
  382.             {
  383.                 $this->p_vars['last_pevent'] = $lpevent;
  384.             }
  385.  
  386.             if ($this->p_vars['last_pevent'] != $pevent)
  387.             {
  388.                 // its a new event so the word parser needs to be reconfigured 
  389.                 $this->configWordParser($pevent);
  390.             }
  391.  
  392.  
  393.             $this->p_vars['last_word'] = $word;
  394.             $word = $this->wp->getWord();
  395.  
  396.             if (0)//PHPDOCUMENTOR_DEBUG == true)
  397.             {
  398.                 echo "----------------\n";
  399.                 echo "LAST: |" . $this->p_vars['last_word'] . "|\n";
  400. //                echo "INDEX: ".$this->p_vars['curpar']."\n";
  401.                 echo "PEVENT: " . $this->getParserEventName($pevent) . "\n";
  402.                 echo "LASTPEVENT: " . $this->getParserEventName($this->p_vars['last_pevent']) . "\n";
  403.                 echo $this->wp->getPos() . " WORD: |".htmlentities($word)."|\n\n";
  404.                 var_dump($this->_context);
  405.             }
  406.             if (isset($this->eventHandlers[$pevent]))
  407.             {
  408.                 $handle = $this->eventHandlers[$pevent];
  409.                 if ($word !== false) $this->$handle($word, $pevent);
  410.                 else
  411.                 {
  412.                     if (!count($this->pars[$this->p_vars['curpar']]->value)) unset($this->pars[$this->p_vars['curpar']]);
  413.                 }
  414.             } else
  415.             {
  416.                 debug('WARNING: possible error, no ParserDescParser handler for event number '.$pevent);
  417.                 if ($endrecur++ == 25)
  418.                 {
  419.                     die("FATAL ERROR, recursion limit reached");
  420.                 }
  421.             }
  422.             if (is_object($word) || trim($word) != '')
  423.             {
  424.                 $this->p_vars['start'] = false;
  425.             }
  426.         } while (!($word === false) && $word != '');
  427.         $context = $this->getContext();
  428.         if ($context != 'normal')
  429.         {
  430.             if ($context == 'list' && $this->p_flags['simplelist'])
  431.             {
  432.                 $this->p_vars['lists'][0]->addItem($this->p_vars['list_item'][0]);
  433.                 unset($this->p_vars['list_item'][0]);
  434.                 $this->setContext('normal');
  435.                 $this->addText($this->p_vars['lists'][0]);
  436.             } else addError(PDERROR_UNCLOSED_TAG,str_replace('my_','',$context));
  437.         }
  438.         if ($this->p_vars['list_count'] > 0) addError(PDERROR_UNMATCHED_LIST_TAG);
  439.         if ($sdesc)
  440.         $this->publishEvent(2,$this->pars);
  441.         else
  442.         $this->publishEvent(1,$this->pars);
  443.     }
  444.     /**#@+ @access private */
  445.     /**
  446.      * basic handling
  447.      *
  448.      * This function checks to see if the first thing in
  449.      * a description is the <p> tag.  If so, it will switch
  450.      * into a mode of parsing out paragraphs by <p> instead
  451.      * of a double line-break
  452.      *
  453.      * It also removes extra whitespace
  454.      * @uses doSimpleList()
  455.      */
  456.     function defaultHandler($word, $pevent)
  457.     {
  458.         $context = $this->getContext();
  459.         if ($context != 'normal') $this->setContext('normal');
  460.         if ($this->p_vars['start'] && is_string($word) && strtolower($word) == '<p>')
  461.         {
  462.             $this->parse_Ps = true;
  463.         }
  464.         if (is_string($word) && $this->checkEventPush($word, $pevent)) return;
  465. //        if (!isset($this->parse_Ps) || !$this->parse_Ps)
  466.         {
  467.             if ($word == ' ' && $this->p_vars['last_word'] == ' ') return;
  468.             if ($pevent == PARSER_EVENT_NOEVENTS)
  469.             {
  470.                 if ($this->doSimpleList($word)) return;
  471.             }
  472.             $this->addText($word);
  473.         }
  474.     }
  475.     
  476.     /**
  477.      * Retrieve the current top-level tag to add text into
  478.      * @uses $_context
  479.      */
  480.     function getContext()
  481.     {
  482.         array_push($this->_context,$a = array_pop($this->_context));
  483.         return $a;
  484.     }
  485.     
  486.     /**
  487.      * Pop a context off of the context stack
  488.      * @uses $_context
  489.      */
  490.     function dropContext()
  491.     {
  492.         array_pop($this->_context);
  493.         if (count($this->_context) == 0)
  494.         $this->_context = array('normal');
  495.     }
  496.     
  497.     /**
  498.      * @uses $_context
  499.      * @param string context name
  500.      */
  501.     function setContext($context)
  502.     {
  503.         array_push($this->_context,$context);
  504.     }
  505.     
  506.     /**
  507.      * add input as text to the current paragraph or list
  508.      * @param string|parserInlineTag
  509.      */
  510.     function addText($text)
  511.     {
  512.         $context = $this->getContext();
  513.         if ($context == 'list')
  514.         {
  515. //            debug('aded to '.$context);
  516.             $this->p_vars['list_item'][$this->p_vars['list_count']]->add($text);
  517.         } elseif ($context != 'normal')
  518.         {
  519. //            debug('added to '.$context);
  520.             $this->p_vars[$context]->add($text);
  521.         } else
  522.         {
  523. //            debug('added to normal ');
  524.             $indtype = $this->p_vars['indtype'];
  525.             if (!isset($this->pars[$this->p_vars['curpar']]))
  526.                 $this->pars[$this->p_vars['curpar']] = new $indtype;
  527.             $this->pars[$this->p_vars['curpar']]->add($text);
  528.         }
  529.     }
  530.     
  531.     /**#@-*/
  532.     /**#@+
  533.      * @access private
  534.      * @param string|parserInlineTag token from the ObjectWordParser
  535.      * @param integer parser event from {@link ParserDescCleanup.inc}
  536.      */
  537.     /**
  538.      * Handles special case where a description needs the text "<tag>" and tag
  539.      * is one of code, b, i, pre, var, or any other valid in-DocBlock html tag.
  540.      *
  541.      * the text <<<code>>> in a DocBlock will parse out as <<code>>, instead
  542.      * of being parsed as markup.
  543.      */
  544.     function handleEscape($word, $pevent)
  545.     {
  546.         $this->p_vars['event_stack']->popEvent();
  547.         if (!in_array($word, $this->tokens[PHPDOCUMENTOR_PDP_STATE_ESCAPE]))
  548.         {
  549.             if ($word == '<')
  550.             {
  551.                 $this->addText($word);
  552.                 $this->wp->backupPos($word.$word);
  553.             } else
  554.             $this->wp->backupPos($word);
  555.             return;
  556.         }
  557.         $this->addText('<'.str_replace('>>','>',$word));
  558.     }
  559.     
  560.     /**
  561.      * Just like {@link handleEscape}, except the only valid escape is
  562.      * <<</pre>>>
  563.      */
  564.     function handleEscapePre($word, $pevent)
  565.     {
  566.         $this->p_vars['event_stack']->popEvent();
  567.         $this->addText('</pre>');
  568.     }
  569.     
  570.     /**
  571.      * Just like {@link handleEscape}, except the only valid escape is
  572.      * <<</code>>>
  573.      */
  574.     function handleEscapeCode($word, $pevent)
  575.     {
  576.         $this->p_vars['event_stack']->popEvent();
  577.         $this->addText('</code>');
  578.     }
  579.     
  580.     /**
  581.      * Handle "<<br>>"
  582.      * Add a new {@link parserBr}
  583.      * @uses addText()
  584.      */
  585.     function handleBr($word, $pevent)
  586.     {
  587.         if (is_string($word) && $this->checkEventPop($word, $pevent))
  588.         {
  589.             $this->addText(new parserBr);
  590.         }
  591.     }
  592.     
  593.     /**
  594.      * Handles simple lists
  595.      *
  596.      * phpEdit has an ingenious facility to handle simple lists used in a
  597.      * DocBlock like this:
  598.      *
  599.      * - item 1
  600.      * - item 2
  601.      * - item 3
  602.      *
  603.      * The DocBlock is:
  604.      * <pre>
  605.      * * - item 1
  606.      * * - item 2
  607.      * * - item 3
  608.      * </pre>
  609.      * This function converts these simple lists into the parserList class
  610.      * @param boolean true if this is the first list item in the list
  611.      */
  612.     function handleSimpleList($word, $pevent, $start = false)
  613.     {
  614.         if (is_object($word) && $this->p_flags['in_item'])
  615.         {
  616.             $this->p_vars['list_item'][0]->add($word);
  617.             return;
  618.         }
  619.         if (is_string($word) && $this->checkEventPush($word, $pevent))
  620.         {
  621.             $this->p_flags['in_event'] = true;
  622.             return;
  623.         }
  624.         $ltrimword = @substr($word, @strpos($word, ltrim($word)));
  625.         $is_valid = false;
  626.         if (strlen(trim($word)) == 0)
  627.         {
  628.             if ($this->wp->nextIsObjectOrNonNL())
  629.             {
  630.                 $is_valid = true;
  631.             }
  632.         }
  633.         if ($word == "\n" && is_string($this->p_vars['last_word'])
  634.             && $this->p_vars['last_word']{strlen($this->p_vars['last_word']) - 1}
  635.                 == "\n")
  636.         {
  637.             if ($this->p_flags['in_item'])
  638.             {
  639.                 $this->p_vars['lists'][0]->addItem($this->p_vars['list_item'][0]);
  640.                 unset($this->p_vars['list_item'][0]);
  641.                 $this->setContext('normal');
  642.                 $this->p_flags['simplelist'] = false;
  643.                 $this->addText($this->p_vars['lists'][0]);
  644.                 unset($this->p_vars['lists']);
  645.                 unset($this->p_vars['last_list']);
  646.                 $this->wp->backuppos($word);
  647.                 $this->p_vars['event_stack']->popEvent();
  648.                 $this->p_flags['in_item'] = false;
  649. //                debug('end of list 3');
  650.                 return;
  651.             } else
  652.             {
  653.                 $this->wp->backuppos($word);
  654.                 $this->p_vars['event_stack']->popEvent();
  655.                 $this->p_flags['in_item'] = false;
  656. //                debug('not a list 2');
  657.                 return;
  658.             }
  659.         }
  660.         $start_list = $this->getStartList($word);
  661.         if (substr($ltrimword,0,strlen($start_list)) != $start_list 
  662.              || $this->p_flags['in_event'] || is_object($this->p_vars['last_word']))
  663.         {
  664.             if (((strlen($this->p_vars['whitespace']) + 1) < strlen(substr($word,0,strpos($word, $ltrimword))))
  665.                    || $word == "\n"
  666.                    || $is_valid
  667.                    || $this->p_flags['in_event']
  668.                    || (is_object($this->p_vars['last_word']) && $this->p_flags['in_item']))
  669.             {
  670.                 $this->p_vars['list_item'][0]->add($word);
  671.                 $this->resetStartList($start_list);
  672.                 $this->p_flags['in_event'] = false;
  673. //                debug('middle of list');
  674.             } else
  675.             {
  676.                 if ($this->p_flags['in_item'])
  677.                 {
  678.                     $this->p_vars['lists'][0]->addItem($this->p_vars['list_item'][0]);
  679.                     unset($this->p_vars['list_item'][0]);
  680.                     $this->setContext('normal');
  681.                     $this->p_flags['simplelist'] = false;
  682.                     $this->addText($this->p_vars['lists'][0]);
  683.                     unset($this->p_vars['lists']);
  684.                     unset($this->p_vars['last_list']);
  685.                     $this->wp->backuppos($word);
  686.                     $this->p_vars['event_stack']->popEvent();
  687.                     $this->p_flags['in_item'] = false;
  688. //                    debug('end of list 1');
  689.                     return;
  690.                 } else
  691.                 {
  692.                     $this->wp->backuppos($word);
  693.                     $this->p_vars['event_stack']->popEvent();
  694.                     $this->p_flags['in_item'] = false;
  695. //                    debug('not a list');
  696.                     return;
  697.                 }
  698.             }
  699.         } else
  700.         {
  701.             if ($this->p_vars['whitespace'] != substr($word,0,strpos($word, $start_list)))
  702.             { // if the whitespace is greater than that preceding the list
  703.               // delimiter, it's a multi-line list item
  704.                 $this->setContext('normal');
  705.                 $this->p_flags['simplelist'] = false;
  706.                 $this->addText($this->p_vars['lists'][0]);
  707.                 unset($this->p_vars['lists']);
  708.                 $this->wp->backuppos($word);
  709.                 $this->p_vars['event_stack']->popEvent();
  710.                 unset($this->p_vars['last_list']);
  711.                 $this->p_flags['in_item'] = false;
  712. //                debug('end of list 2');
  713.                 return;
  714.             } else
  715.             {
  716.                 if ($this->p_flags['in_item'])
  717.                 {
  718.                     // end of a list item, add it to the list
  719.                     $this->p_vars['lists'][0]->addItem($this->p_vars['list_item'][0]);
  720.                     unset($this->p_vars['list_item'][0]);
  721.                 }
  722. //                debug('next list item');
  723.                 $this->p_vars['list_item'][0] = new parserStringWithInlineTags;
  724.                 $this->p_vars['list_item'][0]->add(ltrim(substr($ltrimword,strlen($start_list))));
  725.                 $this->p_flags['in_item'] = true;
  726.             }
  727.         }
  728.     }
  729.     /**#@-*/
  730.     /**
  731.      * Get the next list marker
  732.      *
  733.      * In unordered lists, this will be something like "o", "-"
  734.      *
  735.      * In ordered lists, this will be either the number "3", "5" or "3.", "5."
  736.      * @return string text of the next list marker to look for
  737.      * @param string current word from the parser
  738.      * @access private
  739.      */
  740.     function getStartList($word)
  741.     {
  742.         // unordered, return the first marker found
  743.         if (!$this->p_flags['orderedlist']) return $this->p_vars['start_list'];
  744.         if (isset($this->p_vars['last_list']))
  745.         {
  746.             $this->p_vars['save_list'] = $this->p_vars['last_list'];
  747.             $next = $this->p_vars['last_list'];
  748.             // increment to next list number, convert to string
  749.             if (substr($this->p_vars['start_list'], strlen($this->p_vars['start_list']) - 1) == '.')
  750.                 $next = (substr($next, 0, strpos($next,'.')) + 1) . '.';
  751.             else
  752.                 $next = ($next + 1) . '';
  753. //                debug("next is '$next'");
  754.             if ($this->p_vars['whitespace'] == substr($word,0,strpos($word, $next)))
  755.                 return $this->p_vars['last_list'] = $next;
  756.             // the next number is not in this word, so return but don't save
  757.             return $next;
  758.         } else
  759.         {
  760.             $this->p_vars['last_list'] = $this->p_vars['start_list'];
  761.             return $this->p_vars['start_list'];
  762.         }
  763.     }
  764.     
  765.     /**
  766.      * Set the next list marker to the current list marker
  767.      *
  768.      * In ordered lists, this will ensure that the next number returned is the
  769.      * right number
  770.      * @param string token for next list marker
  771.      * @access private
  772.      */
  773.     function resetStartList($start)
  774.     {
  775.         if (!isset($this->p_vars['save_list'])) return false;
  776.         $this->p_vars['last_list'] = $this->p_vars['save_list'];
  777.     }
  778.     
  779.     /**#@+
  780.      * @access private
  781.      * @param string|parserInlineTag token from the ObjectWordParser
  782.      * @param integer parser event from {@link ParserDescCleanup.inc}
  783.      */
  784.     /**
  785.      * Handles <<ol>>,<<li>>,<<ul>>
  786.      *
  787.      * This allows parsing of lists nested to any level.  Using
  788.      * the lists and list_item temporary variables and using
  789.      * list_count to control nesting, the method creates a {@link parserList}
  790.      * for each <<ol>> or <<ul>> tag, and a
  791.      * standard {@link parserStringWithInlineTags} for all the text, adding
  792.      * in nested lists as if they were inline tags (the conversion interface
  793.      * is the same for both object types)
  794.      */
  795.     function handleList($word, $pevent)
  796.     {
  797.         if (is_string($word) && $this->checkEventPush($word, $pevent))
  798.         {
  799.             return;
  800.         }
  801.         $ordered = false;
  802.         if (!is_object($this->p_vars['last_word']) && strtolower($this->p_vars['last_word']) == '<ol>')
  803.         {
  804.             // ordered list
  805.             $ordered = true;
  806.         }
  807.         // start a new list
  808.         if (!is_object($this->p_vars['last_word']) && (strtolower($this->p_vars['last_word']) == '<ol>' || strtolower($this->p_vars['last_word']) == '<ul>'))
  809.         {
  810.             $this->p_flags['in_item'] = false;
  811.             $this->setContext('list');
  812.             $this->p_vars['lists'][++$this->p_vars['list_count']] = new parserList($ordered);
  813.         }
  814.         if (!is_object($word) && strtolower($word) == '<li>')
  815.         {
  816.             if ($this->p_flags['in_item'])
  817.             {
  818.                 // end of a list item (no end tag), add it to the list
  819.                 $this->p_vars['lists'][$this->p_vars['list_count']]->addItem($this->p_vars['list_item'][$this->p_vars['list_count']]);
  820.                 unset($this->p_vars['list_item'][$this->p_vars['list_count']]);
  821.             }
  822.             // start a new list item
  823.             $this->p_vars['list_item'][$this->p_vars['list_count']] = new parserStringWithInlineTags;
  824.             $this->p_flags['in_item'] = true;
  825.         } else
  826.         {
  827.             if (is_object($word) || (strtolower($word) != '</li>'))
  828.             {
  829.                 if (is_object($word) || (strtolower($word) != '</ul>' && strtolower($word) != '</ol>'))
  830.                 {
  831.                     // item text
  832.                     if (isset($this->p_vars['list_item'][$this->p_vars['list_count']]))
  833.                     {
  834.                         if ($word == ' ' && $this->p_vars['last_word'] == ' ') return;
  835.                         $this->p_vars['list_item'][$this->p_vars['list_count']]->add($word);
  836.                     }
  837.                 } else
  838.                 {
  839.                     if ($this->p_flags['in_item'])
  840.                     {
  841.                         // end the current list item before ending a list
  842.                         $this->p_vars['lists'][$this->p_vars['list_count']]->addItem($this->p_vars['list_item'][$this->p_vars['list_count']]);
  843.                         unset($this->p_vars['list_item'][$this->p_vars['list_count']]);
  844.                         $this->p_flags['in_item'] = false;
  845.                     }
  846.                     if (is_string($word) && $this->checkEventPop($word, $pevent))
  847.                     {
  848.                         if ($this->p_vars['list_count'] > 1)
  849.                         {
  850.                             // this is a sublist, add it to the list item of the parent list
  851.                             $this->p_vars['list_item'][$this->p_vars['list_count'] - 1]->add($this->p_vars['lists'][$this->p_vars['list_count']]);
  852.                             // remove the sublist item and sublist, drop to parent list
  853.                             unset($this->p_vars['lists'][$this->p_vars['list_count']]);
  854.                             unset($this->p_vars['lists'][$this->p_vars['list_count']]);
  855.                             $this->p_vars['list_count']--;
  856.                             $this->p_flags['in_item'] = true;
  857.                         } else
  858.                         {
  859.                             // this is a primary list and it has concluded
  860.                             $this->pars[$this->p_vars['curpar']]->add($this->p_vars['lists'][$this->p_vars['list_count']]);
  861.                             unset($this->p_vars['lists']);
  862.                             unset($this->p_vars['list_item']);
  863.                             $this->p_vars['list_count'] = 0;
  864.                             $this->dropContext();
  865.                         }
  866.                     }
  867.                 }
  868.             } else
  869.             {
  870.                 // check to make sure our list item is not unclosed
  871.                 if (!$this->p_flags['in_item'])
  872.                 {
  873.                     addError(PDERROR_TEXT_OUTSIDE_LI);
  874.                 } else
  875.                 {
  876.                     // end of a list item, add it to the list
  877.                     $this->p_vars['lists'][$this->p_vars['list_count']]->addItem($this->p_vars['list_item'][$this->p_vars['list_count']]);
  878.                     unset($this->p_vars['list_item'][$this->p_vars['list_count']]);
  879.                     $this->p_flags['in_item'] = false;
  880.                 }
  881.             }
  882.         }
  883.     }
  884.  
  885.     /**
  886.      * Handles <<code>><</code>> blocks
  887.      */
  888.     function handleCode($word, $pevent)
  889.     {
  890.         if (!isset($this->p_vars['my_code']))
  891.         {
  892.             $this->setContext('my_code');
  893.             $this->p_vars['my_code'] = new parserCode;
  894.         }
  895.         if (is_string($word) && $this->checkEventPush($word, $pevent)) return;
  896.         if (is_object($word) || strtolower($word) != '</code>') $this->p_vars['my_code']->add($word);
  897.         if (is_string($word))
  898.         {
  899.             if ($this->checkEventPop($word,$pevent))
  900.             {
  901.                 $this->dropContext();
  902.                 $this->addText($this->p_vars['my_code']);
  903.                 unset($this->p_vars['my_code']);
  904.             }
  905.         }
  906.     }
  907.     
  908.     /**
  909.      * Handles <<pre>><</pre>> blocks
  910.      */
  911.     function handlePre($word, $pevent)
  912.     {
  913.         if (!isset($this->p_vars['my_pre']))
  914.         {
  915.             $this->setContext('my_pre');
  916.             $this->p_vars['my_pre'] = new parserPre;
  917.         }
  918.         if (is_string($word) && $this->checkEventPush($word, $pevent)) return;
  919.         if (is_object($word) || strtolower($word) != '</pre>') $this->p_vars['my_pre']->add($word);
  920.         if (is_string($word))
  921.         {
  922.             if ($this->checkEventPop($word,$pevent))
  923.             {
  924.                 $this->dropContext();
  925.                 $this->addText($this->p_vars['my_pre']);
  926.                 unset($this->p_vars['my_pre']);
  927.             }
  928.         }
  929.     }
  930.     
  931.     /**
  932.      * Handles <<b>><</b>> blocks
  933.      */
  934.     function handleB($word, $pevent)
  935.     {
  936.         if (!isset($this->p_vars['my_b']))
  937.         {
  938.             $this->setContext('my_b');
  939.             $this->p_vars['my_b'] = new parserB;
  940.         }
  941.         if (is_string($word))
  942.         {
  943.             if ($this->checkEventPop($word,$pevent))
  944.             {
  945.                 $this->dropContext();
  946.                 $this->addText($this->p_vars['my_b']);
  947.                 unset($this->p_vars['my_b']);
  948.             } else
  949.             {
  950.                 $this->p_vars['my_b']->add($word);
  951.             }
  952.         } else $this->p_vars['my_b']->add($word);
  953.     }
  954.     
  955.     /**
  956.      * Handles <<i>><</i>> blocks
  957.      */
  958.     function handleI($word, $pevent)
  959.     {
  960.         if (!isset($this->p_vars['my_i']))
  961.         {
  962.             $this->p_vars['my_i'] = new parserI;
  963.             $this->setContext('my_i');
  964.         }
  965.         if (is_string($word))
  966.         {
  967.             if ($this->checkEventPop($word,$pevent))
  968.             {
  969.                 $this->dropContext();
  970.                 $this->addText($this->p_vars['my_i']);
  971.                 unset($this->p_vars['my_i']);
  972.             } else
  973.             {
  974.                 $this->p_vars['my_i']->add($word);
  975.             }
  976.         } else $this->p_vars['my_i']->add($word);
  977.     }
  978.     
  979.     /**
  980.      * Handles <<var>><</var>> blocks
  981.      */
  982.     function handleVar($word, $pevent)
  983.     {
  984.         if (!isset($this->p_vars['my_var']))
  985.         {
  986.             $this->setContext('my_var');
  987.             $this->p_vars['my_var'] = new parserDescVar;
  988.         }
  989.         if (is_string($word))
  990.         {
  991.             if ($this->checkEventPop($word,$pevent))
  992.             {
  993.                 $this->dropContext();
  994.                 $this->addText($this->p_vars['my_var']);
  995.                 unset($this->p_vars['my_var']);
  996.             } else
  997.             {
  998.                 $this->p_vars['my_var']->add($word);
  999.             }
  1000.         } else $this->p_vars['my_var']->add($word);
  1001.     }
  1002.     
  1003.     /**
  1004.      * Handles <<samp>><</samp>> blocks
  1005.      */
  1006.     function handleSamp($word, $pevent)
  1007.     {
  1008.         if (!isset($this->p_vars['my_samp']))
  1009.         {
  1010.             $this->setContext('my_samp');
  1011.             $this->p_vars['my_samp'] = new parserSamp;
  1012.         }
  1013.         if (is_string($word))
  1014.         {
  1015.             if ($this->checkEventPop($word,$pevent))
  1016.             {
  1017.                 $this->dropContext();
  1018.                 $this->addText($this->p_vars['my_samp']);
  1019.                 unset($this->p_vars['my_samp']);
  1020.             } else
  1021.             {
  1022.                 $this->p_vars['my_samp']->add($word);
  1023.             }
  1024.         } else $this->p_vars['my_samp']->add($word);
  1025.     }
  1026.     
  1027.     /**
  1028.      * Handles <<kbd>><</kbd>> blocks
  1029.      */
  1030.     function handleKbd($word, $pevent)
  1031.     {
  1032.         if (!isset($this->p_vars['my_kbd']))
  1033.         {
  1034.             $this->setContext('my_kbd');
  1035.             $this->p_vars['my_kbd'] = new parserKbd;
  1036.         }
  1037.         if (is_string($word))
  1038.         {
  1039.             if ($this->checkEventPop($word,$pevent))
  1040.             {
  1041.                 $this->dropContext();
  1042.                 $this->addText($this->p_vars['my_kbd']);
  1043.                 unset($this->p_vars['my_kbd']);
  1044.             } else
  1045.             {
  1046.                 $this->p_vars['my_kbd']->add($word);
  1047.             }
  1048.         } else $this->p_vars['my_kbd']->add($word);
  1049.     }
  1050.     
  1051.     /**
  1052.      * Handles <<p>><</p>> blocks
  1053.      *
  1054.      * Note that the only time <<p>> will be interpreted as delimiting a
  1055.      * paragraph is if it is the first thing in the description.
  1056.      */
  1057.     function handleP($word, $pevent)
  1058.     {
  1059.         if (!isset($this->parse_Ps)) $this->parse_Ps = false;
  1060.         if (is_string($word))
  1061.         {
  1062.             if (is_string($word) && $this->checkEventPush($word, $pevent)) return;
  1063.         }
  1064.         if (!$this->parse_Ps)
  1065.         {
  1066.             $this->p_vars['event_stack']->popEvent();
  1067.             if (!is_object($word) && strtolower($this->p_vars['last_word']) == '<p>') $this->addText('<p>');
  1068.             $this->addText($word);
  1069.             return;
  1070.         }
  1071.         if ($word == "\n") $word = " ";
  1072.         if (is_string($word))
  1073.         {
  1074.             if ($this->checkEventPop($word, $pevent))
  1075.             {
  1076.                 $this->p_vars['curpar']++;
  1077.                 return;
  1078.             }
  1079.             // if no closing tag, pretend there was one
  1080.             if (!is_object($word) && strtolower($word) == '<p>' && $this->parse_Ps)
  1081.             {
  1082.                 $this->p_vars['curpar']++;
  1083.                 return;
  1084.             }
  1085.         }
  1086.         if ($this->p_vars['start'])
  1087.         {
  1088.             $this->addText($word);
  1089.         } else
  1090.         {// if the <p> is not at the beginning of the desc, then it is not
  1091.          // possible to parse into paragraphs using this tag
  1092.             if ($word == ' ' && $this->p_vars['last_word'] == ' ') return;
  1093.             $this->addText($word);
  1094.         }
  1095.     }
  1096.     
  1097.     /**
  1098.      * Handles \n\n as a paragraph marker
  1099.      * @uses doSimpleList()
  1100.      */
  1101.     function handleDoubleCR($word, $pevent)
  1102.     {
  1103.         $this->p_vars['event_stack']->popEvent();
  1104.         if ($word == "\n")
  1105.         {
  1106.             // only use this if <p> isn't being used
  1107.             if ((!isset($this->parse_Ps) || !$this->parse_Ps))
  1108.             {
  1109.                 if ($this->p_vars['last_word'] == "\n")
  1110.                 {
  1111.                     $this->p_vars['curpar']++;
  1112.                     $this->parse_Ps = false;
  1113.                 } else
  1114.                 {
  1115.                     if (is_string($word) && !$this->checkEventPush($word, $pevent))
  1116.                     {
  1117.                         if ($word == ' ' && $this->p_vars['last_word'] == ' ') return;
  1118.                         $this->addText($word);
  1119.                     }
  1120.                 }
  1121.             } else
  1122.             {
  1123.                 if (is_string($word) && !$this->checkEventPush($word, $pevent))
  1124.                 {
  1125.                     if ($word == ' ' && $this->p_vars['last_word'] == ' ') return;
  1126.                     $this->addText($word);
  1127.                 }
  1128.             }
  1129.         } else
  1130.         {
  1131.             if ($this->p_vars['last_word'] == "\n")
  1132.             {
  1133.                 if ((!isset($this->parse_Ps) || !$this->parse_Ps))
  1134.                 {
  1135.                     $this->addText(' ');
  1136.                 }
  1137.             }
  1138.             if (is_string($word) && !($e = $this->checkEventPush($word, $pevent)))
  1139.             {
  1140.                 if ($word == ' ' && $this->p_vars['last_word'] == ' ') return;
  1141.                 if ($this->doSimpleList($word)) return;
  1142.                 $this->addText($word);
  1143.             }
  1144.         }
  1145.     }
  1146.     
  1147.     /**#@-*/
  1148.     /**
  1149.      * Return a simple list, if found
  1150.      *
  1151.      * This helper function extracts a simple list beginning with any of
  1152.      * 'o','-'.'#','+','0','1','0.','1.' and starts parsing it.
  1153.      * @param string line that may contain a simple list
  1154.      * @return boolean true if a list is found, false otherwise
  1155.      */
  1156.     function doSimpleList($word)
  1157.     {
  1158.         if ($this->p_flags['in_event']) return true;
  1159.         if (is_object($word)) return false;
  1160.         $ltrimword = ltrim($word);
  1161.         if ((strlen($ltrimword) != strlen($word))
  1162.              && strlen($ltrimword)
  1163.              && ((in_array($ltrimword{0},array('o','-','1','0','#','+')) && $ltrimword{1} == ' '))
  1164.                  || ((strlen($ltrimword) >= 2) && (in_array(substr($ltrimword,0,2),array('1.','0.')) && $ltrimword{2} == ' ')))
  1165.         {
  1166.             // save the whitespace for comparison
  1167.             $this->p_vars['whitespace'] = substr($word,0,strlen($word) - strlen($ltrimword));
  1168.             $this->p_vars['start_list'] = $ltrimword{0};
  1169.             if ($this->p_vars['start_list'] != '1' && $this->p_vars['start_list'] != '1.' &&
  1170.                 $this->p_vars['start_list'] != '0' && $this->p_vars['start_list'] != '0.')
  1171.             {
  1172.                 $this->p_flags['orderedlist'] = false;
  1173.             } else
  1174.             {
  1175.                 if (substr($ltrimword,0,2) == '1.')
  1176.                 {
  1177.                     $this->p_vars['start_list'] = '1.';
  1178.                 }
  1179.                 $this->p_flags['orderedlist'] = true;
  1180.             }
  1181.             $this->p_vars['event_stack']->pushEvent(PHPDOCUMENTOR_PDP_EVENT_SIMLIST);
  1182.             $this->setContext('list');
  1183.             $this->p_flags['simplelist'] = true;
  1184.             $this->p_vars['lists'][0] = new parserList($this->p_flags['orderedlist']);
  1185.             $this->p_vars['list_count'] = 0;
  1186.             $this->handleSimpleList($word, PHPDOCUMENTOR_PDP_EVENT_SIMLIST, true);
  1187.             return true;
  1188.         }
  1189.         return false;
  1190.     }
  1191.     /**
  1192.     * setup the parser tokens, and the pushEvent/popEvent arrays
  1193.     * @see $tokens, $pushEvent, $popEvent
  1194.     * @param boolean determines whether to allow paragraph parsing
  1195.     * @global boolean used to determine whether to slow things down or not by
  1196.     * eliminating whitespace from comments
  1197.     */
  1198.     
  1199.     function setupStates($sdesc)
  1200.     {
  1201.         $this->p_flags['in_item'] = false;
  1202.         $this->p_flags['in_event'] = false;
  1203.         $this->p_flags['simplelist'] = false;
  1204.         $this->_context = array('normal');
  1205.         $this->tokens[STATE_NOEVENTS]            = array("\n", "<code>", "<pre>", "<ol>", "<ul>", 
  1206.                                                          "<b>", "<i>", '<var>', '<kbd>', '<samp>', "<br", '<<');
  1207.         if (!$sdesc)
  1208.         {
  1209.             $this->tokens[STATE_NOEVENTS][] = "<p>";
  1210.             $this->tokens[STATE_NOEVENTS][] = "</p>";
  1211.         }
  1212.         if (PHPDOCUMENTOR_KILL_WHITESPACE) $this->tokens[STATE_NOEVENTS][] = ' ';
  1213.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_P]        = array("</p>","<code>","<pre>","\n","<ol>","<ul>","<b>","<i>","<br","<p>", '<<',
  1214.                                                                 '<var>', '<kbd>', '<samp>');
  1215.         if (PHPDOCUMENTOR_KILL_WHITESPACE) $this->tokens[PHPDOCUMENTOR_PDP_STATE_P][] = ' ';
  1216.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_CODE]        = array("</code>", '<</code>>');
  1217.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_PRE]        = array("</pre>", '<</pre>>');
  1218.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_LIST]        = array("<ul>","<ol>","</ul>","</ol>","<li>","</li>","<b>","<i>","<br", '<<',
  1219.                                                                    '<var>', '<kbd>', '<samp>');
  1220.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_DOUBLECR]        = array("\n","<ol>","<ul>","<code>","<pre>","<b>","<i>","<br","<p>","</p>",
  1221.                                                                        '<var>', '<kbd>', '<samp>', '<<');
  1222.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_SIMLIST]      = array("\n",'<var>', '<kbd>', '<samp>','<b>','<i>', '<pre>', '<code>',
  1223.                                                                     '<br', '<<');
  1224.  
  1225.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_B]    = array("<code>","\n","<pre>","<ol>","<ul>","</b>","<i>","<br", '<<',
  1226.                                                             '<var>', '<kbd>', '<samp>');
  1227.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_KBD]    = array("<code>","\n","<pre>","<ol>","<ul>","<b>","<i>","<br", '<<',
  1228.                                                             '<var>', '</kbd>', '<samp>');
  1229.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_VAR]    = array("<code>","\n","<pre>","<ol>","<ul>","<b>","<i>","<br", '<<',
  1230.                                                             '</var>', '<kbd>', '<samp>');
  1231.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_SAMP]    = array("<code>","\n","<pre>","<ol>","<ul>","<b>","<i>","<br", '<<',
  1232.                                                             '<var>', '<kbd>', '</samp>');
  1233.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_I]    = array("<code>","\n","<pre>","<ol>","<ul>","<b>","</i>","<br", '<<',
  1234.                                                             '<var>', '<kbd>', '<samp>');
  1235.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_BR]    = array(">","/>");
  1236.         $this->tokens[PHPDOCUMENTOR_PDP_STATE_ESCAPE]    = array('code>>', '/code>>', 'pre>>', '/pre>>', 'b>>', '/b>>', 
  1237.                                                                  'i>>', '/i>>', 'ol>>', '/ol>>', 'ul>>', '/ul>>', 
  1238.                                                                  'br>>', 'br />>', 'p>>', '/p>>', 'samp>>', '/samp>>', 
  1239.                                                                  'kbd>>', '/kbd>>', 'var>>', '/var>>'); 
  1240.         if (PHPDOCUMENTOR_KILL_WHITESPACE) $this->tokens[PHPDOCUMENTOR_PDP_STATE_DOUBLECR][] = ' ';
  1241.  
  1242.         // For each event word to event mapings
  1243.         $this->pushEvent[PARSER_EVENT_NOEVENTS] = 
  1244.             array(
  1245.                 "<code>"    => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1246.                 "<pre>"    => PHPDOCUMENTOR_PDP_EVENT_PRE,
  1247.                 "<p>" => PHPDOCUMENTOR_PDP_EVENT_P,
  1248.                 "<var>" => PHPDOCUMENTOR_PDP_EVENT_VAR,
  1249.                 "<samp>" => PHPDOCUMENTOR_PDP_EVENT_SAMP,
  1250.                 "<kbd>" => PHPDOCUMENTOR_PDP_EVENT_KBD,
  1251.                 "<ol>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1252.                 "<ul>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1253.                 "<b>" => PHPDOCUMENTOR_PDP_EVENT_B,
  1254.                 "<i>" => PHPDOCUMENTOR_PDP_EVENT_I,
  1255.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1256.                 "\n" => PHPDOCUMENTOR_PDP_EVENT_DOUBLECR,
  1257.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1258.             );
  1259. ##########################
  1260.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_CODE] =
  1261.             array(
  1262.                 '<</code>>' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE_CODE,
  1263.             );
  1264.          
  1265.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_CODE] = array("</code>");
  1266. ##########################
  1267.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_PRE] =
  1268.             array(
  1269.                 '<</pre>>' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE_PRE,
  1270.             );
  1271.          
  1272.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_PRE] = array("</pre>");
  1273. ##########################
  1274.          
  1275.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_BR] = array(">","/>");
  1276. ##########################
  1277.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_P] =
  1278.             array(
  1279.                 "<code>" => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1280.                 "<ol>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1281.                 "<ul>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1282.                 "<var>" => PHPDOCUMENTOR_PDP_EVENT_VAR,
  1283.                 "<samp>" => PHPDOCUMENTOR_PDP_EVENT_SAMP,
  1284.                 "<kbd>" => PHPDOCUMENTOR_PDP_EVENT_KBD,
  1285.                 "<pre>" => PHPDOCUMENTOR_PDP_EVENT_PRE,
  1286.                 "<b>" => PHPDOCUMENTOR_PDP_EVENT_B,
  1287.                 "<i>" => PHPDOCUMENTOR_PDP_EVENT_I,
  1288.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1289.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1290.             );
  1291.          
  1292.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_P] = array("</p>");
  1293. ##########################
  1294.         
  1295.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_LIST] =
  1296.             array(
  1297.                 "<ul>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1298.                 "<ol>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1299.                 "<code>" => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1300.                 "<var>" => PHPDOCUMENTOR_PDP_EVENT_VAR,
  1301.                 "<samp>" => PHPDOCUMENTOR_PDP_EVENT_SAMP,
  1302.                 "<kbd>" => PHPDOCUMENTOR_PDP_EVENT_KBD,
  1303.                 "<b>" => PHPDOCUMENTOR_PDP_EVENT_B,
  1304.                 "<i>" => PHPDOCUMENTOR_PDP_EVENT_I,
  1305.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1306.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1307.             );
  1308.         
  1309.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_LIST] = array("</ul>","</ol>");
  1310. ##########################
  1311.  
  1312.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_SIMLIST] = 
  1313.             array(
  1314.                 "<code>"    => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1315.                 "<pre>"    => PHPDOCUMENTOR_PDP_EVENT_PRE,
  1316.                 "<p>" => PHPDOCUMENTOR_PDP_EVENT_P,
  1317.                 "<var>" => PHPDOCUMENTOR_PDP_EVENT_VAR,
  1318.                 "<samp>" => PHPDOCUMENTOR_PDP_EVENT_SAMP,
  1319.                 "<kbd>" => PHPDOCUMENTOR_PDP_EVENT_KBD,
  1320.                 "<b>" => PHPDOCUMENTOR_PDP_EVENT_B,
  1321.                 "<i>" => PHPDOCUMENTOR_PDP_EVENT_I,
  1322.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1323.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1324.             );
  1325. ##########################
  1326.         
  1327.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_DOUBLECR] =
  1328.             array(
  1329.                 "<code>" => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1330.                 "<ol>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1331.                 "<ul>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1332.                 "<pre>" => PHPDOCUMENTOR_PDP_EVENT_PRE,
  1333.                 "<b>" => PHPDOCUMENTOR_PDP_EVENT_B,
  1334.                 "<i>" => PHPDOCUMENTOR_PDP_EVENT_I,
  1335.                 "<var>" => PHPDOCUMENTOR_PDP_EVENT_VAR,
  1336.                 "<samp>" => PHPDOCUMENTOR_PDP_EVENT_SAMP,
  1337.                 "<kbd>" => PHPDOCUMENTOR_PDP_EVENT_KBD,
  1338.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1339.                 "<p>" => PHPDOCUMENTOR_PDP_EVENT_P,
  1340.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1341.             );
  1342.         
  1343. ##########################
  1344.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_B] =
  1345.             array(
  1346.                 "<code>" => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1347.                 "<ol>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1348.                 "<ul>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1349.                 "<pre>" => PHPDOCUMENTOR_PDP_EVENT_PRE,
  1350.                 "<var>" => PHPDOCUMENTOR_PDP_EVENT_VAR,
  1351.                 "<samp>" => PHPDOCUMENTOR_PDP_EVENT_SAMP,
  1352.                 "<kbd>" => PHPDOCUMENTOR_PDP_EVENT_KBD,
  1353.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1354.                 '<i>' => PHPDOCUMENTOR_PDP_EVENT_I,
  1355.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1356.             );
  1357.          
  1358.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_B] = array("</b>");
  1359.  
  1360. ##########################
  1361.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_I] =
  1362.             array(
  1363.                 "<code>" => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1364.                 "<ol>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1365.                 "<ul>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1366.                 "<pre>" => PHPDOCUMENTOR_PDP_EVENT_PRE,
  1367.                 "<var>" => PHPDOCUMENTOR_PDP_EVENT_VAR,
  1368.                 "<samp>" => PHPDOCUMENTOR_PDP_EVENT_SAMP,
  1369.                 "<kbd>" => PHPDOCUMENTOR_PDP_EVENT_KBD,
  1370.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1371.                 '<b>' => PHPDOCUMENTOR_PDP_EVENT_B,
  1372.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1373.             );
  1374.          
  1375.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_I] = array("</i>");
  1376.  
  1377. ##########################
  1378.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_VAR] =
  1379.             array(
  1380.                 "<code>" => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1381.                 "<ol>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1382.                 "<ul>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1383.                 "<pre>" => PHPDOCUMENTOR_PDP_EVENT_PRE,
  1384.                 "<i>" => PHPDOCUMENTOR_PDP_EVENT_I,
  1385.                 "<samp>" => PHPDOCUMENTOR_PDP_EVENT_SAMP,
  1386.                 "<kbd>" => PHPDOCUMENTOR_PDP_EVENT_KBD,
  1387.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1388.                 '<b>' => PHPDOCUMENTOR_PDP_EVENT_B,
  1389.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1390.             );
  1391.          
  1392.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_VAR] = array("</var>");
  1393.  
  1394. ##########################
  1395.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_SAMP] =
  1396.             array(
  1397.                 "<code>" => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1398.                 "<ol>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1399.                 "<ul>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1400.                 "<pre>" => PHPDOCUMENTOR_PDP_EVENT_PRE,
  1401.                 "<var>" => PHPDOCUMENTOR_PDP_EVENT_VAR,
  1402.                 "<i>" => PHPDOCUMENTOR_PDP_EVENT_I,
  1403.                 "<kbd>" => PHPDOCUMENTOR_PDP_EVENT_KBD,
  1404.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1405.                 '<b>' => PHPDOCUMENTOR_PDP_EVENT_B,
  1406.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1407.             );
  1408.          
  1409.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_SAMP] = array("</samp>");
  1410.  
  1411. ##########################
  1412.         $this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_KBD] =
  1413.             array(
  1414.                 "<code" => PHPDOCUMENTOR_PDP_EVENT_CODE,
  1415.                 "<ol>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1416.                 "<ul>" => PHPDOCUMENTOR_PDP_EVENT_LIST,
  1417.                 "<pre" => PHPDOCUMENTOR_PDP_EVENT_PRE,
  1418.                 "<var>" => PHPDOCUMENTOR_PDP_EVENT_VAR,
  1419.                 "<samp>" => PHPDOCUMENTOR_PDP_EVENT_SAMP,
  1420.                 "<i>" => PHPDOCUMENTOR_PDP_EVENT_I,
  1421.                 "<br" => PHPDOCUMENTOR_PDP_EVENT_BR,
  1422.                 '<b>' => PHPDOCUMENTOR_PDP_EVENT_B,
  1423.                 '<<' => PHPDOCUMENTOR_PDP_EVENT_ESCAPE,
  1424.             );
  1425.          
  1426.         $this->popEvent[PHPDOCUMENTOR_PDP_EVENT_KBD] = array("</kbd>");
  1427.     }
  1428.     
  1429.     function getParserEventName ($value)
  1430.     {    
  1431.         $lookup = array(
  1432.             PARSER_EVENT_NOEVENTS         => "PARSER_EVENT_NOEVENTS",
  1433.             PHPDOCUMENTOR_PDP_EVENT_CODE        => "PHPDOCUMENTOR_PDP_EVENT_CODE",
  1434.             PHPDOCUMENTOR_PDP_EVENT_P        => "PHPDOCUMENTOR_PDP_EVENT_P",
  1435.             PHPDOCUMENTOR_PDP_EVENT_B        => "PHPDOCUMENTOR_PDP_EVENT_B",
  1436.             PHPDOCUMENTOR_PDP_EVENT_I        => "PHPDOCUMENTOR_PDP_EVENT_I",
  1437.             PHPDOCUMENTOR_PDP_EVENT_BR        => "PHPDOCUMENTOR_PDP_EVENT_BR",
  1438.             PHPDOCUMENTOR_PDP_EVENT_VAR        => "PHPDOCUMENTOR_PDP_EVENT_VAR",
  1439.             PHPDOCUMENTOR_PDP_EVENT_SAMP        => "PHPDOCUMENTOR_PDP_EVENT_SAMP",
  1440.             PHPDOCUMENTOR_PDP_EVENT_KBD        => "PHPDOCUMENTOR_PDP_EVENT_KBD",
  1441.             PHPDOCUMENTOR_PDP_EVENT_ESCAPE        => "PHPDOCUMENTOR_PDP_EVENT_ESCAPE",
  1442.             PHPDOCUMENTOR_PDP_EVENT_ESCAPE_CODE        => "PHPDOCUMENTOR_PDP_EVENT_ESCAPE_CODE",
  1443.             PHPDOCUMENTOR_PDP_EVENT_ESCAPE_PRE        => "PHPDOCUMENTOR_PDP_EVENT_ESCAPE_PRE",
  1444.             PHPDOCUMENTOR_PDP_EVENT_DOUBLECR        => "PHPDOCUMENTOR_PDP_EVENT_DOUBLECR",
  1445.             PHPDOCUMENTOR_PDP_EVENT_LIST    => "PHPDOCUMENTOR_PDP_EVENT_LIST",
  1446.             PHPDOCUMENTOR_PDP_EVENT_PRE => "PHPDOCUMENTOR_PDP_EVENT_PRE",
  1447.             PHPDOCUMENTOR_PDP_EVENT_SIMLIST => "PHPDOCUMENTOR_PDP_EVENT_SIMLIST",
  1448.         );
  1449.         if (isset($lookup[$value]))
  1450.         return $lookup[$value];
  1451.         else return $value;
  1452.     }
  1453. }
  1454.  
  1455. ?>
  1456.