JSDOC/Walker2.js
[gnome.introspection-doc-generator] / JSDOC / Walker2.js
1 //<Script type="text/javascript">
2 XObject      = imports.XObject.XObject;
3
4 Scope        = imports.Scope.Scope;
5 DocComment   = imports.DocComment.DocComment;
6 Symbol       = imports.Symbol.Symbol;
7 Parser       = imports.Parser.Parser;
8
9 /**
10 * Scope stuff
11
12 * // FIXME - I need this to do next() without doccomments..
13 */
14
15 Walker2 = XObject.define(
16     function(ts) {
17         this.ts = ts;
18         this.warnings = [];
19         this.scopes = [];
20         this.indexedScopes = {};
21         this.symbols = {};
22         //this.timer = new Date() * 1;
23        
24     },
25     Object,
26     
27     {
28     /*
29         timer: 0,
30         timerPrint: function (str) {
31             var ntime = new Date() * 1;
32             var tdif =  ntime -this.timer;
33             this.timer = ntime;
34             var pref = '';
35             if (tdif > 100) { //slower ones..
36                 pref = '***';
37             }
38             print(pref+'['+tdif+']'+str);
39             
40         },
41         */
42         warn: function(s) {
43             //this.warnings.push(s);
44             print("WARNING:" + htmlescape(s) + "<BR>");
45         },
46         // defaults should not be initialized here =- otherwise they get duped on new, rather than initalized..
47         warnings : false,
48         ts : false,
49         scopes : false,
50         global : false,
51         mode : "", //"BUILDING_SYMBOL_TREE",
52         braceNesting : 0,
53         indexedScopes : false,
54         munge: true,
55         symbols: false, /// object store of sumbols..
56
57
58
59
60         buildSymbolTree : function()
61         {
62             //print("<PRE>");
63             
64             this.ts.rewind();
65             this.braceNesting = 0;
66             this.scopes = [];
67             this.aliases = {};
68              
69             this.globalScope = new Scope(-1, false, -1, '$global$');
70             indexedScopes = { 0 : this.globalScope };
71             
72             this.mode = 'BUILDING_SYMBOL_TREE';
73             this.parseScope(this.globalScope);
74         },
75         
76
77
78         log : function(str)
79         {
80               //print("<B>LOG:</B>" + htmlescape(str) + "<BR/>\n");
81         },
82         logR : function(str)
83         {
84                 //print("<B>LOG:</B>" + str + "<BR/>");
85         },
86
87        
88         currentDoc: false,
89
90
91         parseScope : function(scope, ealiases) // parse a token stream..
92         {
93             //this.timerPrint("parseScope EnterScope"); 
94             
95             var aliases = {};
96             var fixAlias = function(str, nomore)
97             {
98                 var ar = str.split('.');
99                 var m = ar.shift();
100                 
101                 //print(str +"?=" +aliases.toSource());
102                 if (aliases[m] == undefined) {
103                     return str;
104                 }
105                 var ret = aliases[m] + (ar.length? '.' : '' )+ ar.join('.');
106                 if (nomore !== true) {
107                     ret = fixAlias(ret, true);
108                 }
109                 
110                 
111                 
112                 return ret;
113             };
114
115             
116             
117             if (ealiases != undefined) {
118                 // copy it down..
119                 for(var i in ealiases) {
120                     aliases[i] = ealiases[i];
121                 }
122                 
123                 
124             } else {
125                 ealiases = {};
126             }
127             //print("STARTING SCOPE WITH: " + ealiases.toSource());
128             var symbol;
129             var token;
130             
131             var identifier;
132
133             var expressionBraceNesting = this.braceNesting;
134             var bracketNesting = 0;
135             var parensNesting = 0;
136            
137             
138             var l1 = '', l2 = '';
139             var scopeName ='';
140             
141             
142             var locBraceNest = 0;
143             // determines if we are in object literals...
144             
145             var isObjectLitAr = [ false ];
146             //print("SCOPE: ------------------START ----------------");
147             this.scopesIn(scope);
148             var scopeLen = this.scopes.length;
149             
150             if (this.ts.cursor < 1) {
151               // this.ts.cursor--; // hopeflly this kludge will work
152             }
153             
154             
155             //print(JSON.stringify(this.ts, null, 4)); Seed.quit();
156             
157             while (null != (token = this.ts.next())) {
158                 //print("TOK"+ token.toString());
159                 //  this.timerPrint("parseScope AFTER lookT: " + token.toString()); 
160                   
161                 if (token.is('WHIT')) {
162                       
163                  
164                     if (token.name != 'JSDOC') {
165                         continue; //skip.
166                     }
167                     if (this.currentDoc) {
168                         // add it to the current scope????
169                         
170                         this.addSymbol('', true);
171
172                         //throw "Unconsumed Doc (TOKwhitespace): " + this.currentDoc.toSource();
173                     }
174                     
175                     
176                     var newDoc = new DocComment(token.data);
177                     
178                     // it's a scope changer..
179                     if (newDoc.getTag("scope").length) {
180                         //print(newDoc.getTag("scope").toSource());
181                         //throw "done";
182                         scope.ident = '$private$|' + newDoc.getTag("scope")[0].desc;
183                         continue;
184                     }
185                     
186                     // it's a scope changer..
187                     if (newDoc.getTag("scopeAlias").length) {
188                         //print(newDoc.getTag("scopeAlias").toSource());
189                         // @scopeAlias a=b
190                         var sal = newDoc.getTag("scopeAlias")[0].desc.split("=");
191                         aliases[sal[0]] = sal[1];
192                         
193                         continue;
194                     }
195                     
196                     
197                     /// got a  doc comment..
198                     //token.data might be this.??? (not sure though)
199                     this.currentDoc = newDoc;
200                     continue;
201                 }
202                 
203                 // catch the various issues .. - scoe changes or doc actions..
204                 
205               
206                 
207                 // things that stop comments carrying on...??
208                 
209                 if (this.currentDoc && (
210                         token.tokN.data == ';' || 
211                         token.tokN.data == '}')) {
212                     this.addSymbol('', true);
213                     //throw "Unconsumed Doc ("+ token.toString() +"): " + this.currentDoc.toSource();
214                 }
215                     
216                 
217                 // the rest are scoping issues...
218                 
219                 // var a = b;
220                 
221                  if (token.name == 'VAR' &&
222                  
223                         this.ts.lookTok(1).type == 'NAME' &&
224                         this.ts.lookTok(2).data == '-' &&
225                         this.ts.lookTok(3).type == 'NAME'  &&
226                         this.ts.lookTok(4).data == ';'  
227                         
228                  
229                  ) {
230                     //print("SET ALIAS:" + this.ts.lookTok(1).data +'=' + this.ts.lookTok(3).data);
231                      
232                     aliases[this.ts.lookTok(1).data] = this.ts.lookTok(3).data;
233                     
234                 
235                 }
236                 
237                 
238               
239                 // extends scoping  *** not sure if the can be x = Roo.apply(....)
240                 // xxx.extends(a,b, {
241                     // $this$=b|b.prototype
242                 // xxx.apply(a, {
243                     // a  << scope
244                 // xxx.applyIf(a, {
245                     // a  << scope
246                 if (token.type = 'NAME') {
247                     
248                     //print("TOK(ident)"+ token.toString());
249                     
250                     
251                        
252                     
253                     
254                     if (/\.extend$/.test(token.data) &&
255                         this.ts.lookTok(1).data == '(' &&
256                         this.ts.lookTok(2).type == 'NAME' &&
257                         this.ts.lookTok(3).data == ',' &&
258                         this.ts.lookTok(4).type == 'NAME' &&
259                         this.ts.lookTok(5).data == ',' &&
260                         this.ts.lookTok(6).data == '{' 
261                            
262                         ) {
263                         // ignore test for ( a and ,
264                         this.ts.nextTok(); /// (
265                         token = this.ts.nextTok(); // a
266                         scopeName = token.data;
267                         
268                         if (this.currentDoc) {
269                             this.addSymbol(scopeName,false,'OBJECT');
270
271                         }
272                         this.ts.nextTok(); // ,
273                         this.ts.nextTok(); // b
274                         
275                         
276                         this.ts.nextTok(); // ,
277                         token = this.ts.nextTok(); // {
278                             
279                         scopeName = fixAlias(scopeName);
280                         
281                         var fnScope = new Scope(this.braceNesting, scope, token.n, 
282                             '$this$=' + scopeName  + '|'+scopeName+'.prototype');
283                         this.indexedScopes[this.ts.cursor] = fnScope;
284                         scope = fnScope;
285                         this.scopesIn(fnScope);
286                        
287                         locBraceNest++;
288                         //print(">>" +locBraceNest);
289                         continue; // no more processing..
290                         
291                     }
292                     
293                     // a = Roo.extend(parentname, {
294                         
295                      if (/\.extend$/.test(token.data) &&
296                         this.ts.lookTok(-2).type == 'NAME'  &&
297                         this.ts.lookTok(-1).data == '=' &&
298                         this.ts.lookTok(1).data == '(' &&
299                         this.ts.lookTok(2).type == 'NAME' &&
300                         this.ts.lookTok(3).data == ',' &&
301                         this.ts.lookTok(4).data == '{' 
302                         ) {
303                         // ignore test for ( a and ,
304                         token = this.ts.lookTok(-2);
305                         scopeName = token.data;
306                         if (this.currentDoc) {
307                             this.addSymbol(scopeName,false,'OBJECT');
308
309                         }
310                         this.ts.nextTok(); /// (
311                         this.ts.nextTok(); // parent
312                         
313                         this.ts.nextTok(); // ,
314                         token =  this.ts.nextTok(); // {
315                              
316                         
317                         scopeName = fixAlias(scopeName);
318                         var fnScope = new Scope(this.braceNesting, scope, token.n, 
319                             '$this$=' + scopeName  + '|'+scopeName+'.prototype');
320                         this.indexedScopes[this.ts.cursor] = fnScope;
321                         scope = fnScope;
322                         this.scopesIn(fnScope);
323                        
324                         locBraceNest++;
325                         //print(">>" +locBraceNest);
326                         continue; // no more processing..
327                         
328                     }
329                     
330                     
331                      // apply ( XXXX,  {
332                          
333                     if (/\.(applyIf|apply)$/.test(token.data) && 
334                         this.ts.lookTok(1).data == '('  &&
335                         this.ts.lookTok(2).type == 'NAME' &&
336                         this.ts.lookTok(3).data == ','  &&
337                         this.ts.lookTok(4).data == '{' 
338                         
339                         ) {
340                         this.ts.nextTok(); /// (
341                          
342                         //print("GOT : applyIF!"); 
343                          
344                         token = this.ts.nextTok(); // b
345                         scopeName = token.data;
346                         
347                                       
348                         if (this.currentDoc) {
349                             this.addSymbol(scopeName,false,'OBJECT');
350
351                         }
352                      
353
354                         
355                         this.ts.nextTok(); /// ,
356                         this.ts.nextTok(); // {
357                             scopeName = fixAlias(scopeName);
358                         var fnScope = new Scope(this.braceNesting, scope, token.n, scopeName);
359                         this.indexedScopes[this.ts.cursor] = fnScope;
360                         scope = fnScope;
361                         this.scopesIn(fnScope);
362                          
363                         locBraceNest++;
364                         //print(">>" +locBraceNest);
365                         continue; // no more processing..
366                     }
367                     
368                     
369                     // xxx = new yyy ( {
370                         
371                     // change scope to xxxx
372                     
373                     if ( this.ts.lookTok(1).data == '=' &&
374                         this.ts.lookTok(2).name == 'NEW' &&
375                         this.ts.lookTok(3).type == 'NAME' &&
376                         this.ts.lookTok(4).data == '(' &&
377                         this.ts.lookTok(5).data == '{' 
378                         ) {
379                         scopeName = token.data;
380                         if (this.currentDoc) {
381                             this.addSymbol(scopeName,false,'OBJECT');
382                             
383                         }
384                         
385                         this.ts.nextTok(); /// =
386                         this.ts.nextTok(); /// new
387                         this.ts.nextTok(); /// yyy
388                         this.ts.nextTok(); /// (
389                         this.ts.nextTok(); /// {
390                             
391                         scopeName = fixAlias(scopeName);
392                         var fnScope = new Scope(this.braceNesting, scope, token.n, scopeName);
393                         this.indexedScopes[this.ts.cursor] = fnScope;
394                         scope = fnScope;
395                         this.scopesIn(fnScope);
396                          
397                         locBraceNest++;
398                         //print(">>" +locBraceNest);
399                         
400                         continue; // no more processing..
401                     }
402                     
403
404                     
405                     
406                     
407                     
408                     
409                     
410                     
411                     
412                     
413                     
414                     
415                     
416                     
417                     
418                     
419                     
420                     
421                     // eval can be prefixed with a hint hider for the compresser..
422                     if ((token.data == 'eval') || /\.eval$/.test(token.data)) {
423                         this.currentDoc = false;
424                         continue;
425                     }
426                     
427                     if (this.currentDoc) {
428                         //print(token.toString());
429                         
430                         // ident : function ()
431                         // ident = function ()
432                         var atype = 'OBJECT';
433                         
434                         if (((this.ts.lookTok(1).data == ':' )|| (this.ts.lookTok(1).data == '=')) &&
435                             (this.ts.lookTok(2).name == "FUNCTION")
436                             ) {
437                                 atype = 'FUNCTION';
438                         }
439                         
440                         //print("ADD SYM:" + atype + ":" + token.toString() + this.ts.lookTok(1).toString() + this.ts.lookTok(2).toString());
441                         
442                         this.addSymbol(
443                             this.ts.lookTok(-1).tokN == Script.TOKdot ? token.data :    fixAlias(token.data),
444                             false,
445                             atype);
446                         
447                     }
448                  
449                     
450                     continue; // dont care about other idents..
451                     
452                 }        
453                 if (token.type == "STRN")   {
454                     if (this.currentDoc) {
455                         this.addSymbol(token.data.substring(1,token.data.length-1),false,'OBJECT');
456
457                     }
458                 }
459             
460                 // really we only have to deal with object constructs and function calls that change the scope...
461                 
462                 
463                  if (token.name == 'FUNCTION') {
464                      
465                     // see if we have an unconsumed doc...
466                     
467                     if (this.currentDoc) {
468                             print(this.ts.dumpToCur());
469                             throw "Unhandled doc (TOKfunction)" + token.toString();
470                             //this.addSymbol(this.currentDoc.getTag('class')[0].name, true);
471
472                             //throw "Unconsumed Doc: (TOKrbrace)" + this.currentDoc.toSource();
473                     }
474                     
475                      
476                      
477                      
478                      
479                     /// foo = function() {} << really it set's the 'this' scope to foo.prototype
480                     //$this$=foo.prototype|$private$|foo.prototype
481         
482                     if (
483                             (this.ts.lookTok(-1).data == '=') && 
484                             (this.ts.lookTok(-2).type == 'NAME')
485                         ) {
486                         scopeName = this.ts.lookTok(-2).data;
487                         this.ts.balanceN('(');
488                         token = this.ts.nextTok(); // should be {
489                         //print("FOO=FUNCITON() {}" + this.ts.context() + "\n" + token.toString());
490                         
491                         
492                         scopeName = fixAlias(scopeName);
493                         var fnScope = new Scope(this.braceNesting, scope, token.n, 
494                             '$this$='+scopeName+'.prototype|$private$|'+scopeName+'.prototype');
495                         this.indexedScopes[this.ts.cursor] = fnScope;
496                         //scope = fnScope;
497                         //this.scopesIn(fnScope);
498                         this.parseScope(fnScope, aliases);
499                         
500                         
501                        
502                         locBraceNest++;
503                         //print(">>" +locBraceNest);
504                         continue; // no more processing..    
505                           
506                         
507                     }
508                         
509                 
510                 // foo = new function() {}
511                         // is this actually used much!?!?!
512                         //$private$
513                         
514                     if (
515                             (this.ts.lookTok(-1).name == 'NEW') && 
516                             (this.ts.lookTok(-2).data == '=') &&
517                             (this.ts.lookTok(-3).type = 'FUNCTION')
518                         ) {
519                         //scopeName = this.ts.look(-3).data;
520                         this.ts.balanceN(Script.TOKlparen);
521                         token = this.ts.nextTok(); // should be {
522                             scopeName = fixAlias(scopeName);
523                         var fnScope = new Scope(this.braceNesting, scope, token.n, '$private$');
524                         this.indexedScopes[this.ts.cursor] = fnScope;
525                         //scope = fnScope;
526                         //this.scopesIn(fnScope);
527                         this.parseScope(fnScope, aliases);
528                         
529                         locBraceNest++;
530                         //print(">>" +locBraceNest);
531                         continue; // no more processing..    
532                           
533                         
534                     }    
535                    
536                     
537     ///==== check/set isObjectLitAr ??                
538                     
539                     
540                  // foo: function() {}
541                         // no change to scoping..
542                         
543                     //print("checking for : function() {"); 
544                     //print( [this.ts.lookTok(-3).type , this.ts.lookTok(-2).type , this.ts.lookTok(-1).type ].join(":"));
545                     if (
546                             (this.ts.lookTok(-1).data == ':') && 
547                             (this.ts.lookTok(-2).type == 'NAME') &&
548                             (this.ts.lookTok(-3).data == '(' || this.ts.lookTok(-3).data== ',') 
549                         ) {
550                         //print("got for : function() {"); 
551                             
552                         //scopeName = this.ts.look(-3).data;
553                         this.ts.balanceN(Script.TOKlparen);
554                         //print(token.toString())
555                         token = this.ts.nextTok(); // should be {
556                         //print(token.toString())
557                         scopeName = fixAlias(scopeName);
558                         var fnScope = new Scope(this.braceNesting, scope, token.n, '');
559                         this.indexedScopes[this.ts.cursor] = fnScope;
560                         //scope = fnScope;
561                         //this.scopesIn(fnScope);
562                          this.parseScope(fnScope, aliases);
563                         locBraceNest++;
564                         //print(">>" +locBraceNest);
565                         continue; // no more processing..    
566                           
567                     } 
568                /// function foo() {} << really it set's the 'this' scope to foo.prototype
569                         //$this$=foo|$private$
570                         //$this$=foo
571                         
572                     if (
573                             (this.ts.lookTok(1).type == 'NAME') 
574                         ) {
575                         //scopeName = this.ts.look(-3).data;
576                         this.ts.balanceN('(');
577                         token = this.ts.nextTok(); // should be {
578                             
579                         var fnScope = new Scope(this.braceNesting, scope, token.n, '');
580                         this.indexedScopes[this.ts.cursor] = fnScope;
581                         //scope = fnScope;
582                         //this.scopesIn(fnScope);
583                         this.parseScope(fnScope, aliases);
584                         locBraceNest++;
585                         //print(">>" +locBraceNest);
586                         continue; // no more processing..    
587                           
588                     }
589                     
590                      
591                 // foo = new (function() { }
592                 // (function() { }
593                 // RETURN function(...) {
594                     
595                     if (
596                            // (this.ts.lookTok(-1).tokN == Script.TOKlparen) && 
597                             (this.ts.lookTok(1).name != 'NAME')   
598                             
599                         //    (this.ts.lookTok(-2).tokN == Script.TOKnew) &&
600                          //   (this.ts.lookTok(-3).tokN == Script.TOKassign) &&
601                          //   (this.ts.lookTok(-4).tokN == Script.TOKidentifier)
602                         ) {
603                         //scopeName = this.ts.look(-3).data;
604                         this.ts.balanceN('(');
605                         token = this.ts.nextTok(); // should be {
606                         var fnScope = new Scope(this.braceNesting, scope, token.n, '$private$');
607                         this.indexedScopes[this.ts.cursor] = fnScope;
608                         //scope = ;
609                         //this.scopesIn(fnScope);
610                          this.parseScope(fnScope, aliases);
611                         locBraceNest++;
612                         //print(">>" +locBraceNest);
613                         continue; // no more processing..    
614                           
615                         
616                     }
617                     
618                     
619                     print(this.ts.context());
620                     throw "dont know how to handle function syntax??";
621                     
622                     continue;
623                     
624                     
625                     
626                     
627                 } // end checking for TOKfunction
628                     
629                 if (token.data == '{') {
630                     
631                      // foo = { // !var!!!
632                         //$this$=foo|Foo
633                
634                 
635                     if (
636                             (this.ts.lookTok(-1).data == '=') &&
637                             (this.ts.lookTok(-2).type == 'NAME') &&
638                             (this.ts.lookTok(-3).nane != 'VAR')  
639                         ) {
640                             
641                             scopeName = this.ts.look(-2).data;
642                             scopeName = fixAlias(scopeName);
643                             var fnScope = new Scope(this.braceNesting, scope, token.n, 
644                                 '$this$='+scopeName + '|'+scopeName
645                             );
646                             this.indexedScopes[this.ts.cursor] = fnScope;
647                             scope = fnScope;
648                             this.scopesIn(fnScope);
649                             
650                               
651                             locBraceNest++;
652                             //print(">>" +locBraceNest);
653                             continue; // no more processing..   
654                     }
655                     // foo : {
656                     // ?? add |foo| ????
657                       
658                     //print("GOT LBRACE : check for :");
659                     if (
660                             (this.ts.lookTok(-1).data == ':') &&
661                             (this.ts.lookTok(-2).type == 'NAME') &&
662                             (this.ts.lookTok(-3).name != 'VAR') 
663                         ) {
664                             
665                             scopeName = this.ts.lookTok(-2).data;
666                             scopeName = fixAlias(scopeName);
667                             var fnScope = new Scope(this.braceNesting, scope, token.n, scopeName);
668                             this.indexedScopes[this.ts.cursor] = fnScope;
669                             scope = fnScope;
670                             this.scopesIn(fnScope);
671                             
672                             locBraceNest++;
673                             //print(">>" +locBraceNest);
674                             continue; // no more processing..   
675                     }
676                     var fnScope = new Scope(this.braceNesting, scope, token.n, '');
677                     this.indexedScopes[this.ts.cursor] = fnScope;
678                     scope = fnScope;
679                     this.scopesIn(fnScope);
680                    
681                     locBraceNest++;
682                     //print(">>" +locBraceNest);
683                     continue;
684                     
685                 }
686                 if (token.data == '{') {
687                     
688                      
689                         if (this.currentDoc) {
690                             this.addSymbol('', true);
691
692                             //throw "Unconsumed Doc: (TOKrbrace)" + this.currentDoc.toSource();
693                         }
694                         
695                        
696                         locBraceNest--;
697                         
698                             //assert braceNesting >= scope.getBraceNesting();
699                         var closescope = this.scopeOut();   
700                         scope = this.scopes[this.scopes.length-1];
701                         //print("<<:" +  locBraceNest)
702                         //print("<<<<<< " + locBraceNest );
703                         if (locBraceNest < 0) {
704                            // print("POPED OF END OF SCOPE!");
705                             ///this.scopeOut();   
706                             //var ls = this.scopeOut();
707                             //ls.getUsedSymbols();
708                             return;
709                         }
710                         continue;
711                 }
712               
713                 
714             }
715             
716             
717         },
718      
719          
720         addSymbol: function(lastIdent, appendIt, atype )
721         {
722             
723             /*if (!this.currentDoc.tags.length) {
724                 
725               
726                 //print(this.currentDoc.toSource());
727                 //  this.currentDoc = false;
728                 
729                 print("SKIP ADD SYM: no tags");
730                 print(this.currentDoc.src);
731                 return;
732             }
733             */
734             if (this.currentDoc.getTag('private').length) {
735                 
736               
737                 //print(this.currentDoc.toSource());
738                  this.currentDoc = false;
739                 print("SKIP ADD SYM:  it's private");
740                 return;
741             }
742             
743             var token = this.ts.cur();
744             if (typeof(appendIt) == 'undefined') {
745                 appendIt= false;
746             }
747           //  print(this.currentDoc.toSource(););
748             if (this.currentDoc.getTag('event').length) {
749                 //?? why does it end up in desc - and not name/...
750                 print(this.currentDoc.getTag('event')[0]);
751                 lastIdent = '*' + this.currentDoc.getTag('event')[0].desc;
752                 //lastIdent = '*' + lastIdent ;
753             }
754             if (!lastIdent.length && this.currentDoc.getTag('property').length) {
755                 lastIdent = this.currentDoc.getTag('property')[0].name;
756                 //lastIdent = '*' + lastIdent ;
757             }
758             
759             var _s = lastIdent;
760             if (!/\./.test(_s)) {
761                     
762                 //print("WALKER ADDsymbol: " + lastIdent);
763                 
764                 var s = [];
765                 for (var i = 0; i < this.scopes.length;i++) {
766                     s.push(this.scopes[i].ident);
767                 }
768                 s.push(lastIdent);
769                 
770                 var s = s.join('|').split('|');
771                print("Walker:ADDSymbol: " + s.join('|') );
772                 var _t = '';
773                  _s = '';
774                 
775                 /// fixme - needs
776                 for (var i = 0; i < s.length;i++) {
777                     
778                     if (!s[i].length) {
779                         continue;
780                     }
781                     if ((s[i] == '$private$') || (s[i] == '$global$')) {
782                         _s = '';
783                         continue;
784                     }
785                     if (s[i].substring(0,6) == '$this$') {
786                         var ts = s[i].split('=');
787                         _t = ts[1];
788                         continue;
789                     }
790                     // when to use $this$ (probabl for events)
791                     _s += _s.length ? '.' : '';
792                     _s += s[i];
793                 }
794                     
795                 
796                 /// calc scope!!
797                 //print("ADDING SYMBOL: "+ s.join('|') +"\n"+ _s + "\n" +Script.prettyDump(this.currentDoc.toSource()));
798                 
799                 if (appendIt && !lastIdent.length) {
800                     
801                     // append, and no symbol???
802                     
803                     // see if it's a @class
804                     if (this.currentDoc.getTag('class').length) {
805                         _s = this.currentDoc.getTag('class')[0].desc;
806                         var symbol = new Symbol(_s, [], "CONSTRUCTOR", this.currentDoc);
807                         Parser.addSymbol(symbol);
808                         this.symbols[_s] = symbol;
809                         return;
810                     }
811                     
812                    // if (this.currentDoc.getTag('property').length) {
813                      //   print(Script.pretStringtyDump(this.currentDoc.toSource));
814                     //    throw "Add Prop?";
815                     //}
816                     
817                     _s = _s.replace(/\.prototype.*$/, '');
818                     if (typeof(this.symbols[_s]) == 'undefined') {
819                         print("Symbol:" + _s);
820                         print(this.currentDoc.src);
821                         
822                         throw "Trying to append symbol, but no doc available";
823                     }
824                         
825                     for (var i =0; i < this.currentDoc.tags.length;i++) {
826                         this.symbols[_s].addDocTag(this.currentDoc.tags[i]);
827                     }
828                     this.currentDoc = false;
829                     return;
830                 }
831             }    
832             if (typeof(this.symbols[_s]) != 'undefined') {
833                 
834                 if (this.symbols[_s].comment.hasTags) {
835                     // then existing comment doesnt has tags 
836                      throw "DUPLICATE Symbol " + _s;
837                 }
838                 // otherwise existing comment has tags - overwrite..
839                 
840                 
841             }
842             if (typeof(atype) == "undefined") {
843                 atype = 'OBJECT'; //this.currentDoc.getTag('class').length ? 'OBJECT' : 'FUNCTION';;
844                }
845             
846             var symbol = new Symbol(_s, [], atype, this.currentDoc);
847             
848             Parser.addSymbol(symbol);
849             this.symbols[_s] = symbol;
850             
851              this.currentDoc = false;
852             
853         },
854         
855         
856         
857         
858         scopesIn : function(s)
859         {
860             this.scopes.push(s);
861             //print(">>>" + this.ts.context()  + "\n>>>"+this.scopes.length+":" +this.scopeListToStr());
862             
863         },
864         scopeOut : function()
865         {
866             
867            // print("<<<" + this.ts.context()  + "\n<<<"+this.scopes.length+":" +this.scopeListToStr());
868             return this.scopes.pop();
869             
870         },
871         
872         scopeListToStr : function()
873         {
874             var s = [];
875             for (var i = 0; i < this.scopes.length;i++) {
876                 s.push(this.scopes[i].ident);
877             }
878             return  s.join('\n\t');
879             
880         }
881         
882     
883     
884      
885 });