7 method parser - implements all the routines related to parsing a method
8 and returning a Method Data Object.
11 NOTE: these methods are called statically from the main parser, and hence
12 inherit $this from the parser!!!!!!!
20 class PHP_CodeDoc_Parser_Method {
23 function read($inclass) {
25 if ($c = PHP_CodeDoc_Parser_Method::parse()) {
26 $this->debug(__METHOD__,$c->name);
29 $c->rfilename = $this->rfilename;
30 $c->activeFile = $this->activeFile;
32 $this->classes[$this->_active_class]->Operations[$c->name] = $c;
33 $this->classes[$this->_active_class]->Operations[$c->name]->class = $this->classes[$this->_active_class]->name;
37 // merge method's author with class.
38 // hey this is a cool use of all those array functions!
41 if (@$a = $this->classes[$this->_active_class]->Operations[$c->name]->description->author)
42 $this->classes[$this->_active_class]->description->author
43 = array_reverse(array_values( array_unique (array_reverse(array_merge(
44 $this->classes[$this->_active_class]->description->author, $a)))));
46 // echo $this->methods++;
48 $c->active_package = &$this->packages[$this->active_package->name];
49 $c->rfilename = $this->rfilename;
50 $c->activeFile = $this->activeFile;
52 $this->active_directory->functions[] = $c;
53 //$c->active_package->functions[$c->name] = $c;
55 $this->pos = $c->endpos;
60 var $_active_method; // return object (PHP_CodeDoc_MethodParser)
62 function parse() { // really parse
64 // before pos... 2 points...
65 /// probably need to look back for 'string'?
66 $flags= array($this->look_nws(-1), $this->look_nws(-2), $this->look_nws(-3), $this->look_nws(-4));
69 $startpos = $this->pos;
70 if ($npos = $this->find_token_pos($startpos,array(T_STRING),'(')) {
71 $n = @$this->tokens[$npos][1];
76 $this->pos = $this->pos + 4;
77 $method = new PHP_CodeDoc_Data_Method;
79 $method->type = "Public";
80 $method->isPublic = 1;
81 $method->isStatic = in_array(T_STATIC, $flags) ? 1 : 0;
82 $method->isFinal = in_array(T_FINAL, $flags) ? 1 : 0;
83 $method->visibility = 1;
84 if (in_array(T_PRIVATE, $flags)) {
85 $method->type = "Private";
86 $method ->isPublic = 0;
87 $method->visibility = 0;
89 if (in_array(T_PROTECTED, $flags)) {
90 $method->type = "Protected";
91 $method ->isPublic = 0;
92 $method->visibility = 0;
96 $method->Param = PHP_CodeDoc_Parser_Method::_get_args($method);
98 if ($v = PHP_CodeDoc_Parser_Comment::parse()) {
99 $method->description = $v;
102 $this->pos = $startpos;
103 PHP_CodeDoc_Parser_Method::_store_method_tokens($method);
104 // store the array of objects so It can be printed out!
105 $this->pos = $startpos;
107 $method->endpos = $this->endpos;
115 function _store_method_tokens(&$method) { //remember the tokens for a method.. (for printing later)
123 $method->tokenStart = $this->pos;
124 $startpos = $this->pos;
125 while ($pos < $this->total) {
126 $v = $this->tokens[$pos];
128 if (!$inbrak && $v[0] == T_CURLY_OPEN) {
133 //if ($v[1] && $v[1]{0} == "(")
135 //$v[0] = token_name($v[0]);
136 $v[2]= "{$level}:{$inbrak}";
138 if (!$inbrak && trim($v) == "}")
140 if (!$inbrak && trim($v) == "{") {
145 if (trim($v) == "(") $inbrak++;
146 if (trim($v) == ")") $inbrak--;
151 if ($in_method && !$level) {
152 $this->endpos = $pos;
153 $method->tokenEnd = $pos;
160 $this->endpos = $this->pos+1;
161 $method->tokenEnd = $this->pos+1;
166 function _get_args (&$method) {// read arguments of a method call
170 while ($this->pos < $this->total) {
171 $v = $this->tokens[$this->pos];
173 if ($v[0] == T_WHITESPACE) {
180 $Param[$p] = new StdClass;
181 $Param[$p]->name = $v[1];
187 case T_CONSTANT_ENCAPSED_STRING:
188 if (!@$Param[$p]->Value)
189 $Param[$p]->Value = $v[1];
192 $Param[$p]->Value = "array()";
195 //echo "XXX:{$this->pos}:" .token_name($v[0]) . ":{$this->level}:". $v[1] .":\n";
197 //if ($v == "(") $level++;
198 if ($v == "{") return $Param;
200 //if ($v == ",") $current_var = "";
201 //echo "XXX:{$this->pos}:RAW:{$v}\n";
205 return $Param; // shouldnt really get here