Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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