changed git call from https to git readonly
[atutor.git] / mods / phpdoc / PHPDoc / parser / PhpdocParserTags.php
1 <?php\r
2 /**\r
3 * Functions used to parse PHPDoc Tags.\r
4\r
5 * @version $Id: PhpdocParserTags.php,v 1.4 2000/12/03 22:37:37 uw Exp $\r
6 */\r
7 class PhpdocParserTags extends PhpdocParserRegExp {\r
8         \r
9         /**\r
10         * Extract the value from the given tags and copy the data to the $data array if its an allowed tag\r
11         *\r
12         * @param        array   $tags                   array of tags returned by getTags\r
13         * @param        array   $data                   array where the allowed tags and their values are copied to\r
14         * @param        array   $allowed        array of allowed (recognized) tags\r
15         * @return       array   $data\r
16         * @throws       PhpdocError\r
17         * @see  getTags(), analyseVariableParagraphs(), analyseFunctionParagraphs(), analyseClassParagraphs(), analyseSeeTags()\r
18         */\r
19         function analyseTags($tags, $data, $allowed) {\r
20         \r
21                 if (!is_array($tags) || !is_array($data) || !is_array($allowed)) {\r
22                         $this->err[] = new PhpdocError("Illegal function call", __FILE__, __LINE__);\r
23                         return $data;\r
24                 }\r
25 \r
26                 reset($tags);\r
27                 while (list($k, $tag) = each($tags)) {  \r
28                 \r
29                         $tagname = substr( strtolower($tag["tag"]), 1 );\r
30                         if (!isset($allowed[$tagname])) {\r
31                                 $data["notallowed"][$tagname] = true;\r
32                                 continue;\r
33                         }\r
34                         \r
35                         switch ($tagname) {\r
36                                 \r
37                                 # @tagname description\r
38                                 case "exclude":\r
39                                 case "package":\r
40                                 case "magic":\r
41                                 case "todo":\r
42                                 case "version":\r
43                                 case "since":\r
44                                 case "include":\r
45                                 case "copyright":\r
46                                 \r
47                                         if (isset($data[$tagname])) {   \r
48                                         \r
49                                                 $tag["msg"] = "This tag must be used only once within a doc comment. First declaration gets used.";\r
50                                                 $data["syntaxerror"][] = $tag;\r
51                                                 break;\r
52                                                 \r
53                                         }\r
54                                                 \r
55                                         if ("" == $tag["value"]) {\r
56                                         \r
57                                                 $tag["msg"] = "Description is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
58                                                 $data["syntaxerror"][] = $tag;\r
59                                                 $data[$tagname] = $tag["value"];\r
60                                                 \r
61                                         } else \r
62                                                 $data[$tagname] = $tag["value"];\r
63                                                 \r
64                                         break;\r
65                                 \r
66                                 # @tagname [void]       \r
67                                 case "abstract":                \r
68                                 case "static":                  \r
69                                 case "final":\r
70                                 \r
71                                         if (isset($data[$tagname])) {\r
72                                         \r
73                                                 $tag["msg"] = "This tag must be used only once within a doc comment. First declaration gets used.";\r
74                                                 $data["syntaxerror"][] = $tag;\r
75                                                 break;\r
76                                                 \r
77                                         }\r
78                                         \r
79                                         if ("" != $tag["value"]) {\r
80                                                 \r
81                                                 $tag["msg"] = "Description gets ignored, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'.";\r
82                                                 $data["syntaxerror"][] = $tag;\r
83                                                 \r
84                                         }\r
85                                         $data[$tagname] = true;\r
86                                         break;\r
87                                 \r
88                                 case "var":\r
89                                 case "return":\r
90 \r
91                                         if (isset($data[$tagname])) {\r
92                                         \r
93                                                 $tag["msg"] = "This tag must be used only once within a doc comment. First declaration gets used.";\r
94                                                 $data["syntaxerror"][] = $tag;\r
95                                                 break;\r
96                                                 \r
97                                         }\r
98                                         \r
99                                         if (preg_match($this->TAGS[$tagname], $tag["value"], $regs)) {\r
100 \r
101                                                 $desc = "";\r
102                                                 \r
103                                                 if ("object" == $regs[1]) {\r
104                                                 \r
105                                                         $type = "object ";\r
106                                                         if ( "" == $regs[2] ) {\r
107                                                                 \r
108                                                                 $type .= "[unknown]";\r
109                                                                 $tag["msg"] = "Objectname is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
110                                                                 $data["syntaxerror"][] = $tag;          \r
111                                                                 \r
112                                                         } else {\r
113                                                         \r
114                                                                 $type .= $regs[2];\r
115                                                                 \r
116                                                         }\r
117                                                         \r
118                                                         $desc = $regs[4];\r
119                                                         \r
120                                                 } else {\r
121                                                 \r
122                                                         $type = $regs[1];\r
123                                                         $desc = $regs[2] . " " . $regs[4];\r
124                                                         \r
125                                                 }\r
126                                                         \r
127                                                 $data[$tagname] = array (\r
128                                                                                                                                                 "type"          => $type,\r
129                                                                                                                                                 "name"          => $regs[3],\r
130                                                                                                                                 );\r
131                                                                                                                                 \r
132                                                 if ("" != trim($desc)) \r
133                                                         $data[$tagname]["desc"] = $desc;\r
134 \r
135                                         } else {\r
136                                         \r
137                                                 $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
138                                                 $tag["msg"] .= $this->TAGS[$tagname];\r
139                                                 $data["syntaxerror"][] = $tag;\r
140                                                 \r
141                                         }\r
142                                         break;\r
143         \r
144                                 case "global":\r
145 \r
146                                         if (preg_match($this->TAGS["global"], $tag["value"], $regs)) {\r
147                                                 \r
148                                                 if ("" == $regs[3]) {\r
149                                                 \r
150                                                         $tag["msg"] = "Variablename ist missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
151                                                         $data["syntaxerror"][] = $tag;\r
152                                                         \r
153                                                 }\r
154                                                 \r
155                                                 if ("object" == $regs[1]) {\r
156                                                 \r
157                                                         $type = "object ";\r
158                                                         if ( "" == $regs[2] ) {\r
159                                                         \r
160                                                                 $type .= "[unknown]";\r
161                                                                 $tag["msg"] = "Objectname is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
162                                                                 $data["syntaxerror"][] = $tag;          \r
163                                                                 \r
164                                                         } else {\r
165                                                         \r
166                                                                 $type .= $regs[2];\r
167                                                                 \r
168                                                         }\r
169                                                         \r
170                                                 } else {\r
171                                                 \r
172                                                         $type = $regs[1];\r
173                                                         \r
174                                                 }\r
175                                                 \r
176                                                 if ("" == $regs[4]) {\r
177                                                         $data["global"][] = array (\r
178                                                                                                                                                                 "type"  => $type,\r
179                                                                                                                                                                 "name"  => $regs[3]\r
180                                                                                                                                                 );\r
181                                                 } else {\r
182                                                         $data["global"][] = array (\r
183                                                                                                                                                                 "type"  => $type,\r
184                                                                                                                                                                 "name"  => $regs[3],\r
185                                                                                                                                                                 "desc"  => $regs[4]\r
186                                                                                                                                                 );\r
187                                                 }\r
188                                                 \r
189                                         } else {\r
190                                         \r
191                                                 $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
192                                                 $data["syntaxerror"][] = $tag;\r
193                                                 \r
194                                         }\r
195                                                 \r
196                                         break;\r
197                                         \r
198                                 case "param":\r
199                                 case "parameter":\r
200 \r
201                                         if (preg_match($this->TAGS["var"], $tag["value"], $regs)) {\r
202 \r
203                                                 if ("object" == $regs[1]) {\r
204                                                 \r
205                                                         $type = "object ";\r
206                                                         if ("" == $regs[2]) {\r
207                                                         \r
208                                                                 $type .= "[unknown]";\r
209                                                                 $tag["msg"] = "Objectname is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
210                                                                 $data["syntaxerror"][] = $tag;          \r
211                                                                 \r
212                                                         } else {\r
213                                                         \r
214                                                                 $type .= $regs[2];\r
215                                                                 \r
216                                                         }\r
217                                                         \r
218                                                 } else {\r
219                                                 \r
220                                                         $type = $regs[1];\r
221                                                         \r
222                                                 }                                                                                       \r
223                                                 \r
224                                                 if ("" == $regs[4]) {\r
225                                                         $data["params"][] = array (\r
226                                                                                                                                                                         "type"          => $type,\r
227                                                                                                                                                                         "name"          => $regs[3]\r
228                                                                                                                                                                 );\r
229                                                 } else {\r
230                                                         $data["params"][] = array (\r
231                                                                                                                                                                         "type"          => $type,\r
232                                                                                                                                                                         "name"          => $regs[3],\r
233                                                                                                                                                                         "desc"          => $regs[4]\r
234                                                                                                                                                                 );\r
235                                                 }\r
236                                                                                         \r
237                                         }  else {\r
238                                         \r
239                                                 $tag["msg"] = "General syntax error, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'.";\r
240                                                 $data["syntaxerror"][] =        $tag;\r
241                                                 \r
242                                         }\r
243                                         \r
244                                         break;\r
245                                 \r
246                                 case "see":\r
247 \r
248                                         if ("" != $tag["value"]) {\r
249         \r
250                                                 $error = "";\r
251                                                 $references = explode(",", $tag["value"] );\r
252                                                 reset($references);\r
253                                                 while (list($k, $reference) = each($references)) {\r
254                                                 \r
255                                                         if (preg_match($this->TAGS["see_var"], $reference, $regs)) {\r
256                                                         \r
257                                                                 list($msg, $entry) = $this->analyseSeeTagRegs($regs);\r
258                                                                 $error .= $msg;\r
259                                                                 if (count($entry) > 0)\r
260                                                                         $data["see"]["var"][] = $entry; \r
261                                                                 \r
262                                                         } else if (preg_match($this->TAGS["see_function"], $reference, $regs)) {\r
263                                                                 \r
264                                                                 list($msg, $entry) = $this->analyseSeeTagRegs($regs);\r
265                                                                 $error .= $msg;\r
266                                                                 if (count($entry) > 0)\r
267                                                                         $data["see"]["function"][] = $entry;\r
268                                                                 \r
269                                                         } else if (preg_match($this->TAGS["see_moduleclass"], $reference, $regs)) {\r
270 \r
271                                                                 $name = $regs[1];\r
272 \r
273                                                                 if (substr($name, 0, $this->C_COMPLEX["module_separator_len"]) == $this->C_BASE["module_separator"]) {\r
274                                                                 \r
275                                                                         $name = substr($name, $this->C_COMPLEX["module_separator_len"]);\r
276                                                                         if ("" == $name) {\r
277                                                                         \r
278                                                                                 $error .= "Element name is missing: '$regs[0]'. Reference gets ignored";\r
279                                                                                 continue;\r
280                                                                                 \r
281                                                                         } else {\r
282                                                                         \r
283                                                                                 $error .= "Element name starts with moduleseparator, module name forgotten '$regs[0]'?";\r
284                                                                                 continue;\r
285                                                                         \r
286                                                                         }\r
287                                                                                 \r
288                                                                 } else if (!strstr($name, $this->C_BASE["module_separator"])) {\r
289                                                                 \r
290                                                                         $error .= "Use function() to referr to functions and $var to referr to variables - don't know what '$name' referrs to.";\r
291                                                                         continue;\r
292                                                                         \r
293                                                                 }\r
294                                                                 \r
295                                                                 $data["see"]["moduleclass"][] = $name;\r
296                                                                 \r
297                                                         } else {\r
298                                                         \r
299                                                                 $error .= "Unknown syntax '$reference'";\r
300                                                                 \r
301                                                         }\r
302                                                 \r
303                                                 }\r
304                                                 \r
305                                                 if ( "" != $error) {\r
306                                                         \r
307                                                         $tag["msg"] = sprintf("Could not understand all references. %s. Syntax: '%s' (function), '%s' (variable), '%s' (module or class).",\r
308                                                                                                                                                         $error,\r
309                                                                                                                                                         $this->C_COMPLEX["see_function"],\r
310                                                                                                                                                         $this->C_COMPLEX["see_var"],\r
311                                                                                                                                                         $this->C_COMPLEX["see_moduleclass"]\r
312                                                                                                                                                 );\r
313                                                         $data["syntaxerror"][] = $tag;\r
314 \r
315                                                 }\r
316                                                 \r
317                                         } else {\r
318                                         \r
319                                                 $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
320                                                 $data["syntaxerror"][] = $tag;\r
321                                                 \r
322                                         }\r
323                                         break;\r
324                                         \r
325                                 case "link":\r
326                                 \r
327                                         if (preg_match($this->TAGS["link"], $tag["value"], $regs)) {\r
328 \r
329                                                 $desc = trim($regs[2]);\r
330                                                 if ("" == $desc) {\r
331                                                 \r
332                                                         $data["link"][] = array(\r
333                                                                                                                                                 "url"           => $regs[1]\r
334                                                                                                                                 );\r
335                                                                                                                                 \r
336                                                 } else {                                        \r
337                                                 \r
338                                                         $data["link"][] = array(\r
339                                                                                                                                                 "url"           => $regs[1],\r
340                                                                                                                                                 "desc"  => trim($regs[2])\r
341                                                                                                                                 );\r
342                                                                                                                                 \r
343                                                 }\r
344                                                 \r
345                                         } else {\r
346                                         \r
347                                                 $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
348                                                 $data["syntaxerror"][] = $tag;\r
349                                                 \r
350                                         }\r
351                                         break;\r
352                                         \r
353                                 case "throws":\r
354                                 \r
355                                         if ("" != $tag["value"]) {\r
356                                 \r
357                                                 $exceptions = explode(",", $tag["value"]);\r
358                                                 reset($exceptions);\r
359                                                 while (list($k, $exception) = each($exceptions)) \r
360                                                         $data["throws"][] = trim($exception);\r
361                                         \r
362                                         } else {\r
363                                         \r
364                                                 $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
365                                                 $data["syntaxerror"][] = $tag;\r
366                                                 \r
367                                         }\r
368                                         break;\r
369                                         \r
370                                 case "access":\r
371                                 \r
372                                         if (preg_match($this->TAGS["access"], $tag["value"], $regs)) {\r
373                                         \r
374                                                 $data["access"] = $regs[1];\r
375                                                 \r
376                                         } else {\r
377 \r
378                                                 $tag["msg"] = ("" == $tag["value"]) ? "General syntax error," : "Access modifier unknown,";\r
379                                                 $tag["msg"].= " '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
380                                                 $data["syntaxerror"][] = $tag;                                                                                  \r
381                                                 \r
382                                         }\r
383                                                 \r
384                                         break;\r
385                                         \r
386                                 case "deprec":\r
387                                 case "deprecated":\r
388                                 \r
389                                         if (isset($data["deprec"])) {\r
390                                         \r
391                                                 $tag["msg"] = "This tag must be used only once within a doc comment. First declaration gets used.";\r
392                                                 $data["syntaxerror"][] = $tag;\r
393                                                 break;\r
394                                         \r
395                                         }                               \r
396                                         \r
397                                         if ("" != $tag["value"]) {\r
398                                         \r
399                                                 $data["deprec"] = $tag["value"];\r
400                                         \r
401                                         } else {\r
402                                                 \r
403                                                 $tag["msg"] = "Description is missing, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
404                                                 $data["syntaxerror"][] = $tag;\r
405                                                 \r
406                                         }\r
407                                         break;\r
408                                         \r
409                                 case "brother":\r
410                                 case "sister":\r
411                                 \r
412                                         if (isset($data["brother"])) {\r
413                                                 \r
414                                                 $tag["msg"] = "This tag must be used only once within a doc comment. First declaration gets used.";\r
415                                                 $data["syntaxerror"][] = $tag;\r
416                                                 break;\r
417                                                 \r
418                                         }\r
419                                         \r
420                                         if ("" != $tag["value"]) {\r
421                                         \r
422                                                 if (preg_match($this->TAGS["brother"], $tag["value"], $regs)) {\r
423                                                         \r
424                                                         $data["brother"] = $regs[1];\r
425                                                         \r
426                                                 } else {\r
427                                                 \r
428                                                         $tag["msg"] = "Can't find a function name nor a variable name, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
429                                                         $data["syntaxerror"][] = $tag;\r
430                                                         \r
431                                                 }\r
432                                         \r
433                                         } else {\r
434                                                 \r
435                                                 $data["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
436                                                 $data["syntaxerror"][] = $tag;\r
437                                                 \r
438                                         }\r
439                                         break;\r
440 \r
441                                 case "module":\r
442                                 case "modulegroup":\r
443                                 \r
444                                         if (isset($data[$tagname])) {\r
445                                         \r
446                                                 $tag["msg"] = "This tag must be used only once within a doc comment. First declaration gets used.";\r
447                                                 $data["syntaxerror"][] = $tag;\r
448                                                 break;\r
449                                         \r
450                                         }\r
451                                         \r
452                                         if ("" != $tag["value"]) {\r
453                                                 \r
454                                                 if (preg_match($this->TAGS["module"], $tag["value"], $regs)) {\r
455                                                         \r
456                                                         $data[$tagname] = $regs[0];\r
457                                                         \r
458                                                 } else {\r
459 \r
460                                                         $tag["msg"] = "Illegal label used, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";                                         \r
461                                                         $data["syntaxerror"][] = $tag;\r
462                                                         \r
463                                                 }\r
464                                                 \r
465                                         } else {\r
466                                         \r
467                                                 $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
468                                                 $data["syntaxerror"][] = $tag;\r
469                                                 \r
470                                         }\r
471                                         break;          \r
472                                         \r
473                                 case "const":\r
474                                 case "constant":        \r
475                                 \r
476                                         if (isset($data["const"])) {\r
477                                         \r
478                                                 $tag["msg"] = "This tag must be used only once within a doc comment. First declaration gets used.";\r
479                                                 $data["syntaxerror"][] = $tag;\r
480                                                 break;\r
481                                                 \r
482                                         }       \r
483                                         \r
484                                         if ("" != $tag["value"]) {\r
485                                         \r
486                                                 if (preg_match($this->TAGS["const"], $tag["value"], $regs)) {\r
487                                                         \r
488                                                         $data["const"] = array(\r
489                                                                                                                                                         "name"  => $regs[1],\r
490                                                                                                                                                         "desc"  => trim($regs[2])\r
491                                                                                                                                                 );\r
492                                                                                                                                                 \r
493                                                 } else {\r
494                                                 \r
495                                                         $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
496                                                         $data["syntaxerror"][] = $tag;\r
497                                                         \r
498                                                 }\r
499                                                 \r
500                                         } else {\r
501                                                 \r
502                                                 $tag["msg"] = "General syntax error, syntax: '" . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
503                                                 $data["syntaxerror"][] = $tag;\r
504 \r
505                                         }\r
506                                         break;\r
507                                 \r
508                                 case "author":\r
509                                 \r
510                                         if ("" != $tag["value"]) {\r
511                                         \r
512                                                 $authors = explode(",", $tag["value"]);\r
513                                                 reset($authors);\r
514                                                 while (list($k, $author) = each($authors)) {\r
515 \r
516                                                         if (preg_match($this->TAGS["author"], $author, $regs)) {\r
517                                                                                                 \r
518                                                                 $data["author"][] = array(\r
519                                                                                                                                                                         "name"  => trim(substr($author, 0, strpos($author, $regs[0]))),\r
520                                                                                                                                                                         "mail"  => trim($regs[1])\r
521                                                                                                                                                                 );\r
522                                                         } else if (""!=trim($author)) {\r
523                                                                 \r
524                                                                 $data["author"][] = array(\r
525                                                                                                                                                                         "name"  => trim($author)\r
526                                                                                                                                                                 );\r
527                                                                                                                                                                 \r
528                                                         } else {\r
529                                                         \r
530                                                                 $tag["msg"] = "Name is missing in enumeration, syntax: '".$this->PHPDOC_TAGS["@$tagname"]."'.";\r
531                                                                 $data["syntaxerror"][] = $tag;\r
532                                                                 \r
533                                                         }\r
534                                                         \r
535                                                 }\r
536                                         \r
537                                         } else {\r
538                                         \r
539                                                 $tag["msg"] = "General syntax error, syntax: " . $this->PHPDOC_TAGS["@$tagname"] . "'.";\r
540                                                 $data["syntaxerror"][] = $tag;\r
541                                         \r
542                                         }\r
543 \r
544                                         break;\r
545                                                                                 \r
546                                 default:\r
547                                         // I'm quite sure this default is obsolete, but I don't feel like checking it.\r
548                                         // Anyway this array index should get used one fine day.\r
549                                         $data["unknown"][] = $tag;\r
550                                         break;\r
551                         }       \r
552                         \r
553                 }               \r
554 \r
555                 return $data;           \r
556         } // end func analyseTags\r
557         \r
558         /**\r
559         * Helperfunction to analyse see tags\r
560         *\r
561         * @param        array   Array return by preg_match()\r
562         * @return       array $see[0] = error, $see[1] = data\r
563         * @see  analyseTags()\r
564         */\r
565         function analyseSeeTagRegs($regs) {\r
566         \r
567                 $error  = "";\r
568                 $group  = trim($regs[1]);\r
569                 $name   = trim($regs[2]);\r
570                 \r
571                 if (substr($name, 0, $this->C_COMPLEX["module_separator_len"]) == $this->C_BASE["module_separator"]) {\r
572                 \r
573                         $name = substr($name, $this->C_COMPLEX["module_separator_len"]);\r
574                         if ("" == $name) {\r
575                         \r
576                                 $error = "Element name is missing '$regs[0]'. Reference gets ignored";\r
577                                 return array($error, array());\r
578                                 \r
579                         } else {\r
580                         \r
581                                 $error = "Element name starts with moduleseparator, module name forgotten '$regs[0]'?";\r
582                         \r
583                         }\r
584                         \r
585                 }\r
586                 \r
587                 if ("" != $group && $this->C_BASE["module_separator"] != $group) {\r
588                 \r
589                         $group = substr($group, 0, $this->C_COMPLEX["module_separator_len_neg"]);\r
590                         if ("" == $group) {\r
591 \r
592                                 $error = "Groupname missing '$regs[0]'.";\r
593                                 $data = array( "name" => $name );\r
594                                 \r
595                         } else {\r
596                         \r
597                                 $data = array ( \r
598                                                                                                 "group" => $group,\r
599                                                                                                 "name"  => $name\r
600                                                                                         );\r
601                                                                                         \r
602                         }\r
603         \r
604                 } else {\r
605                 \r
606                         $data = array ( "name" => $name );\r
607                         \r
608                 }\r
609                 \r
610                 return array($error, $data);\r
611         } // end func analyseSeeTagRegs\r
612         \r
613         /**\r
614         * Extracts PHPDoc tags from a PHPDoc doc comment.\r
615         *\r
616         * @param        string  Doc comment.\r
617         * @return array         List of tags ordered by their appearance containing the \r
618         *                                                               tag name and it's (unparsed) value.\r
619         * @see          getTagPos()\r
620         */\r
621         function getTags($phpdoc) {\r
622 \r
623                 $positions = $this->getTagPos($phpdoc);\r
624                 \r
625                 if (0 == count($positions))\r
626                         return array();\r
627                 \r
628                 reset($positions);\r
629                 list($k, $data) = each($positions);\r
630                 $lastpos = $data["pos"];\r
631                 $lasttag = $data["tag"];\r
632                 \r
633                 while (list($k, $data) = each($positions)) {\r
634                 \r
635                         $line           = substr($phpdoc, $lastpos, ($data["pos"] - $lastpos));\r
636                         $value          = trim(substr($line, strlen($lasttag)));\r
637                         $tags[]         = array ("tag"  => $lasttag, "value"    => $value );\r
638                         \r
639                         $lastpos        = $data["pos"];\r
640                         $lasttag        = $data["tag"];\r
641                         \r
642                 }\r
643                 \r
644                 $line   = substr($phpdoc, $lastpos);\r
645                 $value  = trim(substr($line, strlen($lasttag)));\r
646                 $tags[] = array ("tag"  => $lasttag, "value"    => $value );\r
647 \r
648                 return $tags;\r
649         } // end func getTags\r
650         \r
651         /**\r
652         * Find the position of the next phpdoc tag.\r
653         *\r
654         * @param        string  $phpdoc \r
655         * @param        integer $offset\r
656         * @return array         $tag    0 => tag, 1 => offset\r
657         * @access       private\r
658         * @see          findTags()\r
659         */\r
660         function getTagPos($phpdoc, $offset = 0) {\r
661                 \r
662                 $positions      = array();\r
663                 \r
664                 preg_match_all($this->TAGS["all"], $phpdoc, $regs, PREG_SET_ORDER);\r
665                 \r
666                 reset($regs);\r
667                 while (list($k, $data) = each($regs)) {\r
668                 \r
669                         $pos = strpos($phpdoc, $data[0], $offset);\r
670                         \r
671                         if ($pos > 0 || $data[0] == substr($phpdoc, 0, strlen($data[0])) ) {\r
672                                 $positions[] = array ("pos" => $pos, "tag" => $data[0]);\r
673                                 $offset = $pos+1;\r
674                         }\r
675                         \r
676                 }\r
677 \r
678                 return $positions;\r
679         } // end func getTagPos \r
680         \r
681         /**\r
682         * Takes an array filled by analyseTags() and converts the parse errors into a single error message.\r
683         * \r
684         * Checks for [syntaxerror], [notallowed] and [unknown] entries in the data hash,\r
685         * converts them into an error message and unsets the indizes. The function\r
686         * returns a hash containing the aggregates error message and the modified \r
687         * data hash.\r
688         *\r
689         * @param        array           $data\r
690         * @param        string  $mode   Keyword where the data hash comes from eg. function/class...\r
691         * @return       array   array( $error_msg, $data )\r
692         */\r
693         function checkParserErrors($data, $mode) {\r
694                 \r
695                 $msg = "";\r
696                 // tags with an incorrect syntax\r
697                 if (isset($data["syntaxerror"])) {\r
698 \r
699                         $msg.= "PHPDoc found " . count($data["syntaxerror"]) . " syntax error(s) in the tag list. ";\r
700                         \r
701                         reset($data["syntaxerror"]);\r
702                         while (list($k, $error) = each($data["syntaxerror"])) \r
703                                 $msg.= sprintf("Tag: '%s %s' - %s.", $error["tag"], $error["value"], $error["msg"]);\r
704                                 \r
705                         unset($data["syntaxerror"]);                    \r
706                         \r
707                 }\r
708                 \r
709                 // tags that are not allowed in this context\r
710                 if (isset($data["notallowed"])) {\r
711                         \r
712                         $msg .= count($data["notallowed"]) . " tag[s] were used that are not allowed in $mode doc comments: ";\r
713                         \r
714                         reset($data["notallowed"]);\r
715                         while (list($tagname, $v) = each($data["notallowed"]))\r
716                                 $msg .= "$tagname, ";\r
717                                 \r
718                         $msg = substr($msg, 0, -2) . ".";\r
719                         unset($data["notallowed"]);\r
720                 }\r
721                 \r
722                 // unknown tags\r
723                 if (isset($data["unknown"])) {\r
724                 \r
725                         $msg .= "PHPDoc found " . count($data["unknown"]) . " tag[s] that are unknown: ";\r
726                         \r
727                         reset($data["unknown"]);\r
728                         while (list($k, $error) = each($data["unknown"]))\r
729                                 $msg.= sprintf("%s, ", $error["tag"]);\r
730                         \r
731                         $msg = substr($msg, 0, -2) . ".";\r
732                         unset($data["unknown"]);\r
733                 }\r
734                 \r
735                 return array($msg, $data);\r
736         } // end func checkParserErrors\r
737                 \r
738 } // end class PhpdocParserTags\r
739 ?>