e5a025d5fd5e2e68791a1ea2748955e184f4dd3e
[PHP_CodeDoc] / CodeDoc / Parser / Var.php
1 <?php
2 /*
3 *@package PHP_CodeDoc
4 */
5 /*
6
7 var parser -  very simple!
8 uses parent (master codedoc object) which contains the active tokens
9
10 */
11
12  
13 class PHP_CodeDoc_Parser_Var {
14
15     
16     var $var; // current return value;
17     function read ($inclass) {
18         if (!$inclass) {
19             return;
20         }
21         if ($c = PHP_CodeDoc_Parser_Var::parse()) {
22              
23             $c->activeFile = $this->activeFile;
24             $this->classes[$this->_active_class]->Attributes[$c->name] = $c;
25             $this->classes[$this->_active_class]->Attributes[$c->name]->class =
26                     $this->classes[$this->_active_class]->name;
27         }
28     }
29     
30     
31     function parse()
32     { //  read var declares in a class
33         $flags= array($this->look_nws(-1), $this->look_nws(-2), $this->look_nws(-3), $this->look_nws(-4));
34        
35         
36         $startpos = $this->pos;
37         
38         $var = new PHP_CodeDoc_Data_Var;
39         $var->name  = $this->tokens[$this->pos+2][1];
40         $var->type = "Public";
41         $var->isPublic = 1;
42         $var->isStatic = 0;
43         $var->visibility = 1;
44         $var->isConstant = $this->tokens[$this->pos][0] == T_CONST;
45         
46         if (in_array(T_PRIVATE, $flags)) {
47             $var->type = "Private";
48             $var->isPublic = 0;
49             $var->visibility = 0;
50         }
51         if (in_array(T_PROTECTED, $flags)) {
52             $var->type = "Protected";
53             $var->isPublic = 0;
54             $var->visibility = 0;
55         }
56         if (in_array(T_STATIC, $flags)) {
57             $var->isStatic = 1;
58         }
59         
60         $var->visibility = 1;
61         
62         PHP_CodeDoc_Parser_Var::_store_tokens($var);
63         
64         if ($v = PHP_CodeDoc_Parser_Comment::parse()) {
65             $var->description = $v;
66         }
67         $this->pos = $startpos;
68            
69         return $var;
70     
71     }
72     
73     /* 
74     remember the tokens for a var.. (for printing later)
75     */
76     function _store_tokens(&$var) { 
77         //return;
78         $var->tokenStart=$this->pos;
79         $n=0;
80         $in_method =0;
81         $inbrak =0;
82         $level=0;
83         $pos = $this->pos;
84         while ($pos < $this->total) {
85             $v = $this->tokens[$pos];
86             if (!is_array($v)) {
87                 if (trim($v) == ";") {
88                     $var->tokenEnd = $pos;
89                     return;
90                 }
91             }
92              
93             $var->tokens[$n] = $v;
94             $pos++;
95             $n++;
96         }
97         $var->tokenEnd = $pos;
98     }
99     
100     
101 }
102 ?>
103    
104