summaryrefslogtreecommitdiff
path: root/buildscripts/PhpDocumentor/phpDocumentor/ParserDocBlock.inc
blob: 96ea1b20ffaf80eeefad50ce49d55335de1a1dbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
<?php
//
// +------------------------------------------------------------------------+
// | phpDocumentor                                                          |
// +------------------------------------------------------------------------+
// | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |
// | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |
// | Web           http://www.phpdoc.org                                    |
// | Mirror        http://phpdocu.sourceforge.net/                          |
// | PEAR          http://pear.php.net/package-info.php?pacid=137           |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License,        |
// | that is available at http://www.php.net/license/3_0.txt.               |
// | If you did not receive a copy of the PHP license and are unable to     |
// | obtain it through the world-wide-web, please send a note to            |
// | license@php.net so we can mail you a copy immediately.                 |
// +------------------------------------------------------------------------+
//

/**
 * DocBlock Parser Classes
 * @package phpDocumentor
 * @subpackage ParserDocBlock
 */
/**
 * represents a short or long description in a DocBlock ({@link parserDocBlock})
 * @package phpDocumentor
 * @subpackage ParserDocBlock
 * @author Greg Beaver <cellog@users.sourceforge.net>
 * @since 1.0rc1
 * @version $Id: ParserDocBlock.inc,v 1.1 2005/10/17 18:36:57 jeichorn Exp $
 */
class parserDesc extends parserStringWithInlineTags
{
    /**
     * Type is used by many functions to skip the hassle of if phpDocumentor_get_class($blah) == 'parserBlah'
     * always '_desc'
     * @var string
     */
    var $type = '_desc';
    
    /**
     * @param mixed like {@link parserStringWithInlineTags::add()}, this can be a string or parserInlineTag, but it can also be a
     *              parserStringWithInlineTags, and the contents will be merged
     */
    function add($stringOrClass)
    {
        if (is_object($stringOrClass))
        {
            if (phpDocumentor_get_class($stringOrClass) == 'parserstringwithinlinetags' ||
                phpDocumentor_get_class($stringOrClass) == 'parserdesc')
            {
                for($i=0;$i<count($stringOrClass->value);$i++)
                {
                    parserStringWithInlineTags::add($stringOrClass->value[$i]);
                }
            } else
            {
                parserStringWithInlineTags::add($stringOrClass);
            }
        } else return parserStringWithInlineTags::add($stringOrClass);
    }
    
    /**
     * @return boolean whether this desc has an {@}inheritdoc} inline tag
     */
    function hasInheritDoc()
    {
        for($i=0;$i<count($this->value);$i++)
        {
            if (phpDocumentor_get_class($this->value[$i])=='parserinheritdocinlinetag') return true;
        }
    }
    
    /**
     * @return boolean whether this desc has an {@}source} inline tag
     */
    function hasSource()
    {
        for($i=0;$i<count($this->value);$i++)
        {
            if (phpDocumentor_get_class($this->value[$i])=='parsersourceinlinetag') return true;
        }
    }
    
    /**
     * replaces {@}inheritdoc} with the contents of the parent DocBlock
     * @param parserDesc parent parserDesc, used to retrieve the description
     */
    function replaceInheritDoc($desc)
    {
        $value = $this->value;
        $this->value = array();
        for($i=0;$i<count($value);$i++)
        {
            if (phpDocumentor_get_class($value[$i])=='parserinheritdocinlinetag')
            {
                for($j=0;$j<count($desc->value);$j++)
                {
                    $this->add($desc->value[$j]);
                }
            } else $this->add($value[$i]);
        }
    }
}

/**
 * Represents a docblock and its components, {@link $desc}, {@link $sdesc}, {@link $tags}, and also {@link $params} for functions
 * @package phpDocumentor
 * @subpackage ParserDocBlock
 * @author Greg Beaver <cellog@users.sourceforge.net>
 * @since 1.0rc1
 * @version $Id: ParserDocBlock.inc,v 1.1 2005/10/17 18:36:57 jeichorn Exp $
 */
class parserDocBlock
{
    /**
     * @var parserDesc
     */
    var $desc = false;
    /**
     * @var array array of {@link parserDesc}s
     */
    var $processed_desc = false;
    /**
     * @var array array of {@link parserDesc}s
     */
    var $processed_sdesc = false;
    /**
     * @var parserDesc
     */
    var $sdesc = false;
    /**
     * Line number in the source on which this docblock begins
     * @since 1.2
     * @var false|integer
     */
    var $linenumber = false;
    /**
     * Line number in the source on which this docblock ends
     * @since 1.2
     * @var false|integer
     */
    var $endlinenumber = false;
    /**
     * array of {@link parserTag}s
     * @var array
     */
    var $tags = array();
    /**
     * array of unrecognized {@link parserTag}s
     * @var array
     */
    var $unknown_tags = array();
    /**
     * array of param data.
     * Format:
     * array(index of param in function parameter list -OR- parameter name =>
     *         parserStringWithInlineTags,...)
     * @var array
     */
    var $params = array();
    /**
     * array of global variable data.
     * Format:
     * array(index of global variable in @global tag list -OR- global variable name =>
     *         array(datatype,parserStringWithInlineTags),...)
     * @var array
     */
    var $funcglobals = array();
    
    /**
     * array of static variable data.
     * Format:
     * array(index of static variable in @global tag list -OR- static variable name =>
     *         {@link parserStaticvarTag},...)
     * @var array
     */
    var $statics = array();
    /**
     * This is either a {@link parserReturnTag} or false if no return tag is present
     * @var mixed
     */
    var $return = false;
    /**
     * This is either a {@link parserVarTag} or false if no var tag is present
     * @var mixed
     */
    var $var = false;
    /**
     * fix for bug 591396
     * @var boolean
     */
    var $explicitpackage = false;
    /**
     * fix for bug 708559
     * @var boolean
     */
    var $explicitcategory = false;
    /** @var string */
    var $category;
    /** @var string */
    var $package = 'default';
    /** @var string */
    var $subpackage = '';
    /**
     * whether this DocBlock has an @access tag
     * @var boolean */
    var $hasaccess = false;
    /**
     * whether this DocBlock has a @name tag
     * @var boolean */
    var $hasname = false;
    /**
     * description of package parsed from @package tag
     * Unused in this version
     * @var string
     */
    var $packagedescrip = '';
    /**
     * description of subpackage parsed from @package tag
     * Unused in this version
     * @var string
     */
    var $subpackagedescrip = '';
    /**
     * Determines whether a DocBlock can legally have a {@}source} tag
     * @tutorial tags.inlinesource.pkg
     * @var boolean
     * @access private
     */
    var $_canSource = false;
    
    /**
     * sets package to default
     * @global string default package name
     */
    function parserDocBlock()
    {
        global $phpDocumentor_DefaultPackageName;
        $this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
        $this->category = $GLOBALS['phpDocumentor_DefaultCategoryName'];
    }
    
    /**
     * Sets the starting line number for the DocBlock
     * @param integer
     */
    function setLineNumber($number)
    {
        $this->linenumber = $number;
    }
    
    /**
     * Retrieve starting line number
     * @return integer
     */
    function getLineNumber()
    {
        return $this->linenumber;
    }
    
    /**
     * Sets the ending line number for the DocBlock
     * @param integer
     */
    function setEndLineNumber($number)
    {
        $this->endlinenumber = $number;
    }
    
    /**
     * Retrieve ending line number
     * @return integer
     */
    function getEndLineNumber()
    {
        return $this->endlinenumber;
    }
    
    /**
     * Parse out any html tags from doc comments, and make them into
     * abstract structures
     * @uses parserDescParser::parse()
     */
    function postProcess()
    {
        if ($this->sdesc)
        {
            $parser = new parserDescParser;
            $parser->subscribe('*',$this);
            if ($this->desc) $parser->parse($this->desc->value);
            $parser->parse($this->sdesc->value,true);
        }
    }
    
    /**
     * Tells the DocBlock it can have a @filesource tag
     *
     * Only page-level DocBlocks may have a @filesource tag
     */
    function canSource()
    {
        $this->_canSource = true;
    }
    
    /**
     * Tells the DocBlock it can't have a @filesource tag
     *
     * Only page-level DocBlocks may have a @filesource tag
     */
    function cantSource()
    {
        $this->_canSource = false;
    }
    
    /**
     * Indirectly called after parsing by {@link postProcess}
     *
     * @param integer either 1 for long desc or 2 for short desc
     * @param array data organized into paragraphs.  Each entry is a {@link parserStringWithInlineTags}
     * @uses $processed_desc sets to the array passed from {@link parserDescParser::parse()}
     * @uses $processed_sdesc sets to the array passed from {@link parserDescParser::parse()}
     * @access private
     */
    function HandleEvent($event,$data)
    {
        if ($event == 1)
        $this->processed_desc = $data;
        else
        $this->processed_sdesc = $data;
    }
    
    /**
     * @param array
     */
    function updateModifiers($modifiers)
    {
        if (is_array($modifiers) && count($modifiers))
        {
            foreach ($modifiers as $modifier)
            {
                switch ($modifier)
                {
                    case 'private' :
                    case 'public' :
                    case 'protected' :
                        unset($this->tags['access']);
                        $x = new parserAccessTag($modifier);
                        if ($x->isvalid)
                        {
                            $this->hasaccess = true;
                            $this->tags['access'][] = $x;
                        }
                    break;
                    case 'static' :
                    case 'abstract' :
                        unset($this->tags[$modifier]);
                        $this->addKeyword($modifier, '');
                    break;
                }
            }
        }
    }
    
    /**
     * Set the short description of the DocBlock
     *
     * Setting the short description is possible by passing in one of three
     * possible parameters:
     * <ul>
     *  <li>another DocBlock's short description</li>
     *  <li>another DocBlock, the short description will be extracted</li>
     *  <li>a Zend Studio-compatible @desc tag</li>
     * </ul>
     * @param parserDesc|parserDocBlock|parserTag sets {@link $sdesc}
     */
    function setShortDesc($desc)
    {
        if (phpDocumentor_get_class($desc) == 'parsertag')
        {
            $this->sdesc = new parserDesc;
            $this->processed_sdesc = $desc->value;
            return;
        }
        if (phpDocumentor_get_class($desc) == 'parserdesc') {
            $this->sdesc = $desc;
        } else
        {
            $this->sdesc = $desc->sdesc;
            $this->processed_sdesc = $desc->processed_sdesc;
        }
        
        if ($this->sdesc && $this->sdesc->hasSource())
        {
            addWarning(PDERROR_SOURCE_TAG_IGNORED,$this->sdesc->getString());
        }
    }
    
    /**
     * Passes to {@link parserStringWithInlineTags::setSource()}
     *
     * After passing, it calls {@link postProcess()} to set up the new
     * source
     * @param string|array tokenized highlight-ready source code
     * @param false|string name of class if this is a method source
     */
    function setSource($source, $class = false)
    {
        if ($this->desc)
        {
            $this->desc->setSource($source, $class);
            $this->postProcess();
        }
    }
    
    /**
     * @param parserDesc|parserDocBlock sets {@link $desc}
     */
    function setDesc($desc)
    {
        if (phpDocumentor_get_class($desc) == 'parserdesc')
        $this->desc = $desc;
        else
        {
            $this->desc = $desc->desc;
            $this->processed_desc = $desc->processed_desc;
        }
    }
    
    /**
     * Wrapper for {@link parserDesc::hasInheritDoc()}
     * @return boolean
     */
    function hasInheritDoc()
    {
        if (!$this->desc) return false;
        return $this->desc->hasInheritDoc();
    }
    
    /**
     * Wrapper for {@link parserDesc::replaceInheritDoc()}
     *
     * Also replaces {@}inheritdoc} in the {@link $processed_desc}
     * @param parserDesc
     */
    function replaceInheritDoc($desc)
    {
        if (!$this->desc) return false;
        $this->desc->replaceInheritDoc($desc->desc);
        $this->postProcess();
    }
    
    /**
     * @param Converter takes {@link $sdesc} and converts it to a string and returns it if present, otherwise returns ''
     * @return string
     */
    function getSDesc(&$converter)
    {
        if ($this->sdesc && $this->processed_sdesc)
        {
            $result = '';
            foreach($this->processed_sdesc as $desc)
            {
                if (count($desc->value))
                $result .= $desc->Convert($converter);
            }
            return $result;
        } else
        {
//            var_dump($this->desc,$this->processed_desc);
        }
        return '';
    }
    
    /**
     * @param Converter takes {@link $desc} and converts it to a string and returns it if present, otherwise returns ''
     * @return string
     */
    function getDesc(&$converter)
    {
        if ($this->desc && $this->processed_desc)
        {
            $result = '';
            foreach($this->processed_desc as $desc)
            {
                if (count($desc->value))
                $result .= $converter->EncloseParagraph($desc->Convert($converter));
            }
            return $result;
        } else
        {
//            var_dump($this->desc,$this->processed_desc);
        }
        return '';
    }
    
    /**
     * @param string $paramVar if empty, param is indexed in the order received and set using {@link changeParam()}
     * @param parserStringWithInlineTags $value
     */
    function addParam($paramVar, $paramType, $value)
    {
        if (empty($paramVar))
        $this->params[count($this->params)] = new parserParamTag($paramType,$value);
        else
        $this->params[$paramVar] = new parserParamTag($paramType,$value);
    }
    
    /**
     * @param integer $index index of parameter in the {@link $params} array
     * @param string $name name of the parameter to set in the $params array
     */
    function changeParam($index,$name)
    {
        $this->params[$name] = $this->params[$index];
        unset($this->params[$index]);
    }
    
    /**
     * replaces nameless parameters in the {@link $params} array with their names
     * @param array $params Format: array(parameter index => parameter name,...)
     */
    function updateParams($params)
    {
        for($i=0;$i<count($params);$i++)
        {
            if (isset($this->params[$i]))
            {
                $this->changeParam($i,$params[$i]);
            }
        }
        if (isset($this->tags))
        unset($this->tags['param']);
    }
    
    /**
     * Used to insert DocBlock Template tags into a docblock
     * @param parserTag tag
     * @global array used to determine whether to add ignored tags, or not
     */
    function addTag($tag)
    {
        global $_phpDocumentor_setting;
        if (phpDocumentor_setup::checkIgnoreTag($tag->keyword)) return;
        $value = $tag->value;
        if (is_array($value)) $value = $value[0];
        if ($tag->keyword == 'uses')
        {
            $this->addUses($value, $tag->_description);
        } else
        {
            $this->addKeyword($tag->keyword, $value);
        }
    }

    /**
     * @param string $keyword tag name
     * @param parserStringWithInlineTags $value the contents of the tag
     * @global array used to determine whether to add the @internal tag or not
     */
    function addKeyword($keyword, $value)
    {
        global $_phpDocumentor_setting;
        if (phpDocumentor_setup::checkIgnoreTag($keyword)) return;
        // don't add the tag at all if it was specified to ignore it with --ignore-tags
        if ($keyword == 'package' || $keyword == 'subpackage' || $keyword == 'category') return $this->addPackage($keyword, $value);
        if ($keyword == 'access') return $this->addAccess($value);
        if ($keyword == 'link') return $this->addLink($value);
        if ($keyword == 'see' || $keyword == 'tutorial') return $this->addSee($keyword,$value);
        if ($keyword == 'uses') return $this->addUses($keyword, $value);
        if ($keyword == 'name') return $this->addName($value);
        if (!in_array($keyword,$GLOBALS['_phpDocumentor_tags_allowed']))
        $this->addUnknownTag($keyword,$value);
        else
        {
        if ($keyword == 'internal' && (!isset($_phpDocumentor_setting['parseprivate']) || $_phpDocumentor_setting['parseprivate'] == 'off')) return;
            if (!isset($this->tags[$keyword])) {
                $this->tags[$keyword] = array();
            }
            $ptag = 'parserTag';
            if (class_exists('parser'.$keyword.'tag'))
                $ptag = 'parser'.ucfirst($keyword).'Tag';
            array_unshift($this->tags[$keyword], new $ptag($keyword, $value));
        }
    }
    
    /**
     * adds an @example tag
     * @param string contents of the tag
     * @param string path to the file containing this tag
     */
    function addExample($value, $path)
    {
        $this->tags['example'][] = new parserExampleTag($value, $path);
    }
    
    /**
     * adds an unknown tag to the {@link $unknown_tags} array for use by custom converters
     * @param string tag name
     * @param string tag value
     */
    function addUnknownTag($keyword, $value)
    {
        addWarning(PDERROR_UNKNOWN_TAG,$keyword);
        $this->unknown_tags[$keyword][] = new parserTag($keyword, $value);
    }
    
    /**
     * set the element's package to the passed values.  Used in {@link phpDocumentor_IntermediateParser} to align package of
     * elements inside a class or procedural page to the package of the class/procedural page
     * @param string
     * @param string
     * @param string
     * @param string element name
     * @param string element type (include, define, var, method, global, function, const)
     */
    function overridePackage($category, $package,$subpackage,$elname,$type)
    {
        if ($this->package != $GLOBALS['phpDocumentor_DefaultPackageName'])
        {
            addError(PDERROR_OVERRIDDEN_PACKAGE_TAGS,$elname,$type,$this->package);
            $this->explicitpackage = false;
        }
        if (!empty($this->subpackage))
        addError(PDERROR_OVERRIDDEN_SUBPACKAGE_TAGS,$type,$elname,$this->subpackage);
        $this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
        $this->subpackage = '';
        $this->category = $category;
        $this->addPackage('package',$package);
        $this->addPackage('subpackage',$subpackage);
    }
    
    /**
     * Used if this docblock has a @package tag.
     *
     * phpDocumentor will guess package for DocBlocks that don't have
     * a @package tag
     * @uses $explicitpackage
     */
    function setExplicitPackage()
    {
        $this->explicitpackage = true;
    }
    
    /**
     * If the DocBlock has a @package tag, then this returns true
     * @return boolean
     */
    function getExplicitPackage()
    {
        return $this->explicitpackage;
    }
    
    /**
     * Used if this docblock has a @category tag.
     *
     * phpDocumentor will guess category for DocBlocks that don't have
     * a @category tag
     * @uses $explicitcategory
     */
    function setExplicitCategory()
    {
        $this->explicitcategory = true;
    }
    
    /**
     * If the DocBlock has a @category tag, then this returns true
     * @return boolean
     */
    function getExplicitCategory()
    {
        return $this->explicitcategory;
    }
    
    /**
     * @param string $keyword tag name (either package or subpackage)
     * @param mixed $value either a string or a parserStringWithInlineTags.  Strips all inline tags and use the text as the package
     */
    function addPackage($keyword, $value)
    {
        if ($keyword == 'package')
        {
            if (!$this->explicitpackage)
            {
                if (!is_string($value))
                $value = $value->getString();
                $rest = '';
                $value = explode(' ',$value);
                if (count($value) - 1)
                {
                    $rest = $value;
                    $value = $value[0];
                    unset($rest[0]);
                    $rest = implode($rest,' ');
                } else
                {
                    $value = explode("\t",$value[0]);
                    if (count($value) - 1)
                    {
                        $rest = $value;
                        $value = $value[0];
                        unset($rest[0]);
                        $rest = implode($rest,"\t");
                    } else $value = $value[0];
                }
                preg_match("/^([^`~!@#$%^&*(){}|<>,;]+)$/",$value,$match);
                if (!isset($match[0]))
                {
                    // if were a single line and the only bad character is a space then will fix things for them
                    preg_match("/^([^`~!@#$%^&*(){}|<>,;]+)$/",$value,$match);
                    if (!isset($match[0]))
                    {
                        addError(PDERROR_ILLEGAL_PACKAGENAME,'package','package',$value);
                        $value = $GLOBALS['phpDocumentor_DefaultPackageName'];
                    }
                    else
                    {
                        $value = 
                            str_replace(array(" ","/","\\",":"),"_",
                                trim($value));
                    }
                }
                $this->packagedescrip = $this->package = trim($value);
                if (!empty($rest)) $this->packagedescrip = $rest;
            } else
            {
                if (is_string($value))
                addError(PDERROR_MULTIPLE_PACKAGE_TAGS,$value);
                else
                addError(PDERROR_MULTIPLE_PACKAGE_TAGS,$value->getString());
            }
        } elseif ($keyword == 'subpackage')
        {
            if (empty($this->subpackage))
            {
                if (!is_string($value))
                $value = $value->getString();
                $rest = '';
                $value = explode(' ',$value);
                if (count($value) - 1)
                {
                    $rest = $value;
                    $value = $value[0];
                    unset($rest[0]);
                    $rest = implode($rest,' ');
                } else
                {
                    $value = explode("\t",$value[0]);
                    if (count($value) - 1)
                    {
                        $rest = $value;
                        $value = $value[0];
                        unset($rest[0]);
                        $rest = implode($rest,"\t");
                    } else $value = $value[0];
                }
                if (!empty($value))
                {
                    preg_match("/^([^`~!@#$%^&*(){}|<>,;]+)$/",$value,$match);
                    if (!isset($match[0]))
                    {
                        // if were a single line and the only bad character is a space then will fix things for them
                        preg_match("/^([^`~!@#$%^&*(){}|<>,;]+)$/",$value,$match);
                        if (!isset($match[0]))
                        {
                            addError(PDERROR_ILLEGAL_PACKAGENAME,'subpackage','subpackage',$value);
                            $value = '';
                        }
                        else
                        {
                            $value = 
                                str_replace(array(" ","/","\\",":"),"_",
                                    trim($value));
                        }
                    }
                }
                $this->subpackage = trim($value);
                if (!empty($rest)) $this->subpackagedescrip = $rest;
            } else
            {
                if (is_string($value))
                addError(PDERROR_MULTIPLE_SUBPACKAGE_TAGS,$value);
                else
                addError(PDERROR_MULTIPLE_SUBPACKAGE_TAGS,$value->getString());
            }
        } elseif ($keyword == 'category')
        {
            if (!$this->explicitcategory)
            {
                if (!is_string($value))
                $value = $value->getString();
                $this->category = $value;
            } else
            {
                if (is_string($value))
                addError(PDERROR_MULTIPLE_CATEGORY_TAGS,$value);
                else
                addError(PDERROR_MULTIPLE_CATEGORY_TAGS,$value->getString());
            }
        }
    }
    
    /**
     * Adds a @name tag to the tag list
     * @param string new name of element
     */
    function addName($value)
    {
        if (is_object($value)) $value = $value->getString();
        if (!$this->hasname)
        {
            $x = new parserNameTag('name',$value);
            $this->hasname = true;
            $this->tags['name'][] = $x;
        } else
        {
            addError(PDERROR_MULTIPLE_NAME_TAGS,$value);
        }
    }
    
    /**
     * @param string if empty, staticvar is indexed in the order received and set using {@link changeStatic()}
     * @param string data type
     * @param parserStringWithInlineTags
     */
    function addStaticVar($staticvar, $type, $descrip)
    {
        if (empty($staticvar))
        $this->statics[] = new parserStaticvarTag($type,$descrip);
        else
        $this->statics[$staticvar] = new parserStaticvarTag($type,$descrip);
    }
    
    /**
     * adds a function declaration of @global to the {@link $funcglobals} array
     * @param string global type
     * @param string description of how the global is used in the function
     */
    function addFuncGlobal($type,$value)
    {
        $this->funcglobals[] = array($type,$value);
    }
    
    /**
     * @param integer $index index of parameter in the {@link $funcglobals} array
     * @param string $name name of the parameter to set in the $funcglobals array
     */
    function changeGlobal($index,$name)
    {
        $this->funcglobals[$name] = $this->funcglobals[$index];
        unset($this->funcglobals[$index]);
    }

    /**
     * @param integer $index index of parameter in the {@link $statics} array
     * @param string $name name of the parameter to set in the $statics array
     */
    function changeStatic($index,$name)
    {
        $this->statics[$name] = $this->statics[$index];
        unset($this->statics[$index]);
    }

    /**
     * replaces nameless global variables in the {@link $funcglobals} array with their names
     * @param array
     */
    function updateGlobals($funcs)
    {
        for($i=0;$i<count($funcs);$i++)
        {
            if (isset($this->funcglobals[$i]))
            {
                $this->changeGlobal($i,$funcs[$i]);
            }
        }
    }

    /**
     * replaces nameless static variables in the {@link $statics} array with their names
     * @param array
     */
    function updateStatics($funcs)
    {
        for($i=0;$i<count($funcs);$i++)
        {
            if (isset($this->statics[$i]))
            {
                $this->changeStatic($i,$funcs[$i]);
            }
        }
    }

    /**
     * add an @access tag to the {@link tags} array
     * @param string should be either public or private
     */
    function addAccess($value)
    {
        if (is_object($value)) $value = $value->getString();
        $value = strtolower($value);
        if (!$this->hasaccess)
        {
            $x = new parserAccessTag($value);
            if ($x->isvalid)
            {
                $this->hasaccess = true;
                $this->tags['access'][] = $x;
            }
        } else
        {
            if (is_string($value))
            addError(PDERROR_MULTIPLE_ACCESS_TAGS,$value);
            else
            addError(PDERROR_MULTIPLE_ACCESS_TAGS,$value->getString());
        }
    }
    
    /**
     * Adds a new @filesource tag to the DocBlock
     * @tutorial tags.filesource.pkg
     * @param string full path to the file
     * @param array tokenized source code, ordered by line number
     */
    function addFileSource($path, $source)
    {
        if (isset($this->tags['filesource'])) return;
        $this->tags['filesource'][] = new parserFileSourceTag($path, $source);
    }
    
    /**
     * creates a {@link parserLinkTag} and adds it to the {@link $tags} array
     * @param string $link
     */
    function addLink($link)
    {
        if (phpDocumentor_setup::checkIgnoreTag('@link')) return;
        $this->tags['link'][] = new parserLinkTag($link);
    }
    
    /**
     * creates a {@link parserLinkTag} and adds it to the {@link $tags} array
     * @param string either see or uses
     * @param string $value
     */
    function addSee($keyword,$value)
    {
        if (phpDocumentor_setup::checkIgnoreTag($keyword)) return;
        $tag = 'parser'.ucfirst($keyword).'Tag';
        $this->tags[$keyword][] = new $tag($value);
    }
    
    /**
     * creates a {@link parserReturnTag} and adds it to the {@link $tags} array
     * @param string $returnType the one-word name of the return type (mixed should be used if more than one type)
     * @param parserStringWithInlineTags $value
     */
    function addReturn($returnType, $value)
    {
        // only take the first one
        if (!$this->return)
        {
            $this->return = new parserReturnTag($returnType, $value);
        } else
        {
            addError(PDERROR_MULTIPLE_RETURN_TAGS,$returnType,$value->getString());
        }
    }
    
    /**
     * creates a {@link parserVarTag} and adds it to the {@link $tags} array
     * @param string $varType the one-word name of the variable type (mixed should be used if more than one type)
     * @param parserStringWithInlineTags $value
     */
    function addVar($varType, $value)
    {
        // only take the first one
        if (!$this->var)
        {
            $this->var = new parserVarTag($varType, $value);
        } else
        {
            addError(PDERROR_MULTIPLE_VAR_TAGS,$varType,$value->getString());
        }
    }
    
    /**
     * Adds a virtual @usedby tag to output
     * @param abstractLink link to the element that has a @uses tag
     * @param parserStringWithInlinetags description of how the elements uses
     *                                   this one
     * @access private
     */
    function addUsedBy($link, $descrip)
    {
        $this->tags['usedby'][] = new parserUsedByTag($link, $descrip);
    }
    
    /**
     * Add a @uses tag to the DocBlock
     * @param string @see-style text, used for {@link Converter::getLink()}
     * @param parserStringWithInlineTags description of how the used element is
     *                                   used
     * @tutorial tags.uses.pkg
     */
    function addUses($seeel, $description)
    {
        $this->tags['uses'][] = new parserUsesTag($seeel, $description);
    }
    
    /**
     * @param string
     * @return mixed false if no keyword, unconverted value if one keyword, array of unconverted values if more than one keyword
     */
    function getKeyword($keyword)
    {
        if ($keyword == 'filesource' && !$this->_canSource) return false;
        if (isset($this->tags[$keyword]))
        {
            if (count($this->tags[$keyword]) == 1)
            {
                return $this->tags[$keyword][0];
            } else return $this->tags[$keyword];
        } else return false;
    }
    
    /**
     * @return array Format: array('var' => tag name, 'data' => unconverted tag value)
     */
    function listParams()
    {
        if (isset($this->params))
        {
            $ret = array();
            foreach($this->params as $key => $val)
            {
                $ret[] = array("var" => ucfirst($key),"data" => $val);
            }
            return $ret;
        } else {
            return array();
        }
    }
    
    /**
     * @param Converter
     */
    function listTags()
    {
        $tags = array();
        foreach($this->tags as $keyword => $vals)
        {
            if ($keyword == 'filesource' && !$this->_canSource) continue;
            foreach($vals as $val)
            {
                $tags[] = $val;
            }
        }
        usort($tags,'tagsort');
        return $tags;
    }
    
    /** @return string always 'docblock' */
    function getType()
    {
        return 'docblock';
    }
}

/**
 * @access private
 */
function tagsort($a, $b)
{
    switch(phpDocumentor_get_class($a))
    {
        case 'parsertag' :
            switch ($a->keyword)
            {
                case 'author' :
                    $o = 3;
                    break;
                case 'version' :
                    $o = 4;
                    break;
                case 'deprecated' :
                case 'deprec' :
                    $o = 7;
                    break;
                case 'todo' :
                case 'TODO' :
                    $o = 8;
                    break;
                case 'abstract' :
                    $o = 9;
                    break;
            }
        case 'parseraccesstag' :
            $o = 10;
            break;
        case 'parsernametag' :
            $o = 11;
            break;
        case 'parserseetag' :
            $o = 5;
            break;
        case 'parserlinktag' :
            $o = 6;
            break;
        case 'parserreturntag' :
            $o = 0;
            break;
        case 'parservartag' :
            $o = 1;
            break;
        case 'parserstaticvartag' :
            $o = 2;
            break;
        default :
            $o = 12;
            break;
    }
    switch(phpDocumentor_get_class($b))
    {
        case 'parsertag' :
            switch ($b->keyword)
            {
                case 'author' :
                    $p = 3;
                case 'version' :
                    $p = 4;
                case 'deprecated' :
                case 'deprec' :
                    $p = 7;
                case 'todo' :
                case 'TODO' :
                    $p = 8;
                case 'abstract' :
                    $p = 9;
            }
        case 'parseraccesstag' :
            $p = 10;
        case 'parsernametag' :
            $p = 11;
        case 'parserseetag' :
            $p = 5;
        case 'parserlinktag' :
            $p = 6;
        case 'parserreturntag' :
            $p = 0;
        case 'parservartag' :
            $p = 1;
        case 'parsertutorialtag' :
            $p = 1;
        case 'parserstaticvartag' :
            $p = 2;
        default :
            $p = 12;
    }
    if ($o == $p) return 0;
    if ($o < $p) return -1;
    if ($o > $p) return 1;
}
?>