reset to working status
[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._isDoc) {
165                         continue; //skip.
166                     }
167                     if (this.currentDoc) {
168                         // add it to the current scope????
169                         
170                         this.addSymbol('', true);
171
172                         
173                         //throw "Unconsumed Doc (TOKwhitespace): " + this.currentDoc.toSource();
174                     }
175                     
176                     
177                     var newDoc = new DocComment(token.data);
178                     
179                     // it's a scope changer..
180                     if (newDoc.getTag("scope").length) {
181                         //print(newDoc.getTag("scope").toSource());
182                         //throw "done";
183                         scope.ident = '$private$|' + newDoc.getTag("scope")[0].desc;
184                         continue;
185                     }
186                     
187                     // it's a scope changer..
188                     if (newDoc.getTag("scopeAlias").length) {
189                         //print(newDoc.getTag("scopeAlias").toSource());
190                         // @scopeAlias a=b
191                         var sal = newDoc.getTag("scopeAlias")[0].desc.split("=");
192                         aliases[sal[0]] = sal[1];
193                         
194                         continue;
195                     }
196                     
197                     
198                     /// got a  doc comment..
199                     //token.data might be this.??? (not sure though)
200                     this.currentDoc = newDoc;
201                     continue;
202                 }
203                 
204                 // catch the various issues .. - scoe changes or doc actions..
205                 
206               
207                 
208                 // things that stop comments carrying on...??
209                 
210                 if (this.currentDoc && (
211                         token.tokN.data == ';' || 
212                         token.tokN.data == '}')) {
213                     this.addSymbol('', true);
214                     //throw "Unconsumed Doc ("+ token.toString() +"): " + this.currentDoc.toSource();
215                 }
216                     
217                 
218                 // the rest are scoping issues...
219                 
220                 // var a = b;
221                 
222                  if (token.name == 'VAR' &&
223                  
224                         this.ts.lookTok(1).type == 'NAME' &&
225                         this.ts.lookTok(2).data == '-' &&
226                         this.ts.lookTok(3).type == 'NAME'  &&
227                         this.ts.lookTok(4).data == ';'  
228                         
229                  
230                  ) {
231                     //print("SET ALIAS:" + this.ts.lookTok(1).data +'=' + this.ts.lookTok(3).data);
232                      
233                     aliases[this.ts.lookTok(1).data] = this.ts.lookTok(3).data;
234                     
235                 
236                 }
237                 
238                 
239               
240                 // extends scoping  *** not sure if the can be x = Roo.apply(....)
241                 // xxx.extends(a,b, {
242                     // $this$=b|b.prototype
243                 // xxx.apply(a, {
244                     // a  << scope
245                 // xxx.applyIf(a, {
246                     // a  << scope
247                 if (token.type = 'NAME') {
248                     
249                     //print("TOK(ident)"+ token.toString());
250                     
251                     
252                        
253                     
254                     
255                     if (/\.extend$/.test(token.data) &&
256                         this.ts.lookTok(1).data == '(' &&
257                         this.ts.lookTok(2).type == 'NAME' &&
258                         this.ts.lookTok(3).data == ',' &&
259                         this.ts.lookTok(4).type == 'NAME' &&
260                         this.ts.lookTok(5).data == ',' &&
261                         this.ts.lookTok(6).data == '{' 
262                            
263                         ) {
264                         // ignore test for ( a and ,
265                         this.ts.nextTok(); /// (
266                         token = this.ts.nextTok(); // a
267                         scopeName = token.data;
268                         
269                         if (this.currentDoc) {
270                             this.addSymbol(scopeName,false,'OBJECT');
271
272                         }
273                         this.ts.nextTok(); // ,
274                         this.ts.nextTok(); // b
275                         
276                         
277                         this.ts.nextTok(); // ,
278                         token = this.ts.nextTok(); // {
279                             
280                         scopeName = fixAlias(scopeName);
281                         
282                         var fnScope = new Scope(this.braceNesting, scope, token.n, 
283                             '$this$=' + scopeName  + '|'+scopeName+'.prototype');
284                         this.indexedScopes[this.ts.cursor] = fnScope;
285                         scope = fnScope;
286                         this.scopesIn(fnScope);
287                        
288                         locBraceNest++;
289                         //print(">>" +locBraceNest);
290                         continue; // no more processing..
291                         
292                     }
293                     
294                     // a = Roo.extend(parentname, {
295                         
296                      if (/\.extend$/.test(token.data) &&
297                         this.ts.lookTok(-2).type == 'NAME'  &&
298                         this.ts.lookTok(-1).data == '=' &&
299                         this.ts.lookTok(1).data == '(' &&
300                         this.ts.lookTok(2).type == 'NAME' &&
301                         this.ts.lookTok(3).data == ',' &&
302                         this.ts.lookTok(4).data == '{' 
303                         ) {
304                         // ignore test for ( a and ,
305                         token = this.ts.lookTok(-2);
306                         scopeName = token.data;
307                         if (this.currentDoc) {
308                             this.addSymbol(scopeName,false,'OBJECT');
309
310                         }
311                         this.ts.nextTok(); /// (
312                         this.ts.nextTok(); // parent
313                         
314                         this.ts.nextTok(); // ,
315                         token =  this.ts.nextTok(); // {
316                              
317                         
318                         scopeName = fixAlias(scopeName);
319                         var fnScope = new Scope(this.braceNesting, scope, token.n, 
320                             '$this$=' + scopeName  + '|'+scopeName+'.prototype');
321                         this.indexedScopes[this.ts.cursor] = fnScope;
322                         scope = fnScope;
323                         this.scopesIn(fnScope);
324                        
325                         locBraceNest++;
326                         //print(">>" +locBraceNest);
327                         continue; // no more processing..
328                         
329                     }
330                     
331                     
332                      // apply ( XXXX,  {
333                          
334                     if (/\.(applyIf|apply)$/.test(token.data) && 
335                         this.ts.lookTok(1).data == '('  &&
336                         this.ts.lookTok(2).type == 'NAME' &&
337                         this.ts.lookTok(3).data == ','  &&
338                         this.ts.lookTok(4).data == '{' 
339                         
340                         ) {
341                         this.ts.nextTok(); /// (
342                          
343                         //print("GOT : applyIF!"); 
344                          
345                         token = this.ts.nextTok(); // b
346                         scopeName = token.data;
347                         
348                                       
349                         if (this.currentDoc) {
350                             this.addSymbol(scopeName,false,'OBJECT');
351
352                         }
353                      
354
355                         
356                         this.ts.nextTok(); /// ,
357                         this.ts.nextTok(); // {
358                             scopeName = fixAlias(scopeName);
359                         var fnScope = new Scope(this.braceNesting, scope, token.n, scopeName);
360                         this.indexedScopes[this.ts.cursor] = fnScope;
361                         scope = fnScope;
362                         this.scopesIn(fnScope);
363                          
364                         locBraceNest++;
365                         //print(">>" +locBraceNest);
366                         continue; // no more processing..
367                     }
368                     
369                     
370                     // xxx = new yyy ( {
371                         
372                     // change scope to xxxx
373                     
374                     if ( this.ts.lookTok(1).data == '=' &&
375                         this.ts.lookTok(2).name == 'NEW' &&
376                         this.ts.lookTok(3).type == 'NAME' &&
377                         this.ts.lookTok(4).data == '(' &&
378                         this.ts.lookTok(5).data == '{' 
379                         ) {
380                         scopeName = token.data;
381                         if (this.currentDoc) {
382                             this.addSymbol(scopeName,false,'OBJECT');
383                             
384                         }
385                         
386                         this.ts.nextTok(); /// =
387                         this.ts.nextTok(); /// new
388                         this.ts.nextTok(); /// yyy
389                         this.ts.nextTok(); /// (
390                         this.ts.nextTok(); /// {
391                             
392                         scopeName = fixAlias(scopeName);
393                         var fnScope = new Scope(this.braceNesting, scope, token.n, scopeName);
394                         this.indexedScopes[this.ts.cursor] = fnScope;
395                         scope = fnScope;
396                         this.scopesIn(fnScope);
397                          
398                         locBraceNest++;
399                         //print(">>" +locBraceNest);
400                         
401                         continue; // no more processing..
402                     }
403                     
404
405                     
406                     
407                     
408                     
409                     
410                     
411                     
412                     
413                     
414                     
415                     
416                     
417                     
418                     
419                     
420                     
421                     
422                     // eval can be prefixed with a hint hider for the compresser..
423                     if ((token.data == 'eval') || /\.eval$/.test(token.data)) {
424                         this.currentDoc = false;
425                         continue;
426                     }
427                     
428                     if (this.currentDoc) {
429                         //print(token.toString());
430                         
431                         // ident : function ()
432                         // ident = function ()
433                         var atype = 'OBJECT';
434                         
435                         if (((this.ts.lookTok(1).data == ':' )|| (this.ts.lookTok(1).data == '=')) &&
436                             (this.ts.lookTok(2).name == "FUNCTION")
437                             ) {
438                                 atype = 'FUNCTION';
439                         }
440                         
441                         //print("ADD SYM:" + atype + ":" + token.toString() + this.ts.lookTok(1).toString() + this.ts.lookTok(2).toString());
442                         
443                         this.addSymbol(
444                             this.ts.lookTok(-1).tokN == Script.TOKdot ? token.data :    fixAlias(token.data),
445                             false,
446                             atype);
447                         
448                     }
449                  
450                     
451                     continue; // dont care about other idents..
452                     
453                 }        
454                 if (token.type == "STRN")   {
455                     if (this.currentDoc) {
456                         this.addSymbol(token.data.substring(1,token.data.length-1),false,'OBJECT');
457
458                     }
459                 }
460             
461                 // really we only have to deal with object constructs and function calls that change the scope...
462                 
463                 
464                  if (token.name == 'FUNCTION') {
465                      
466                     // see if we have an unconsumed doc...
467                     
468                     if (this.currentDoc) {
469                             print(this.ts.dumpToCur());
470                             throw "Unhandled doc (TOKfunction)" + token.toString();
471                             //this.addSymbol(this.currentDoc.getTag('class')[0].name, true);
472
473                             //throw "Unconsumed Doc: (TOKrbrace)" + this.currentDoc.toSource();
474                     }
475                     
476                      
477                      
478                      
479                      
480                     /// foo = function() {} << really it set's the 'this' scope to foo.prototype
481                     //$this$=foo.prototype|$private$|foo.prototype
482         
483                     if (
484                             (this.ts.lookTok(-1).data == '=') && 
485                             (this.ts.lookTok(-2).type == 'NAME')
486                         ) {
487                         scopeName = this.ts.lookTok(-2).data;
488                         this.ts.balanceN('(');
489                         token = this.ts.nextTok(); // should be {
490                         //print("FOO=FUNCITON() {}" + this.ts.context() + "\n" + token.toString());
491                         
492                         
493                         scopeName = fixAlias(scopeName);
494                         var fnScope = new Scope(this.braceNesting, scope, token.n, 
495                             '$this$='+scopeName+'.prototype|$private$|'+scopeName+'.prototype');
496                         this.indexedScopes[this.ts.cursor] = fnScope;
497                         //scope = fnScope;
498                         //this.scopesIn(fnScope);
499                         this.parseScope(fnScope, aliases);
500                         
501                         
502                        
503                         locBraceNest++;
504                         //print(">>" +locBraceNest);
505                         continue; // no more processing..    
506                           
507                         
508                     }
509                         
510                 
511                 // foo = new function() {}
512                         // is this actually used much!?!?!
513                         //$private$
514                         
515                     if (
516                             (this.ts.lookTok(-1).name == 'NEW') && 
517                             (this.ts.lookTok(-2).data == '=') &&
518                             (this.ts.lookTok(-3).type = 'FUNCTION')
519                         ) {
520                         //scopeName = this.ts.look(-3).data;
521                         this.ts.balanceN(Script.TOKlparen);
522                         token = this.ts.nextTok(); // should be {
523                             scopeName = fixAlias(scopeName);
524                         var fnScope = new Scope(this.braceNesting, scope, token.n, '$private$');
525                         this.indexedScopes[this.ts.cursor] = fnScope;
526                         //scope = fnScope;
527                         //this.scopesIn(fnScope);
528                         this.parseScope(fnScope, aliases);
529                         
530                         locBraceNest++;
531                         //print(">>" +locBraceNest);
532                         continue; // no more processing..    
533                           
534                         
535                     }    
536                    
537                     
538     ///==== check/set isObjectLitAr ??                
539                     
540                     
541                  // foo: function() {}
542                         // no change to scoping..
543                         
544                     //print("checking for : function() {"); 
545                     //print( [this.ts.lookTok(-3).type , this.ts.lookTok(-2).type , this.ts.lookTok(-1).type ].join(":"));
546                     if (
547                             (this.ts.lookTok(-1).data == ':') && 
548                             (this.ts.lookTok(-2).type == 'NAME') &&
549                             (this.ts.lookTok(-3).data == '(' || this.ts.lookTok(-3).data== ',') 
550                         ) {
551                         //print("got for : function() {"); 
552                             
553                         //scopeName = this.ts.look(-3).data;
554                         this.ts.balanceN(Script.TOKlparen);
555                         //print(token.toString())
556                         token = this.ts.nextTok(); // should be {
557                         //print(token.toString())
558                         scopeName = fixAlias(scopeName);
559                         var fnScope = new Scope(this.braceNesting, scope, token.n, '');
560                         this.indexedScopes[this.ts.cursor] = fnScope;
561                         //scope = fnScope;
562                         //this.scopesIn(fnScope);
563                          this.parseScope(fnScope, aliases);
564                         locBraceNest++;
565                         //print(">>" +locBraceNest);
566                         continue; // no more processing..    
567                           
568                     } 
569                /// function foo() {} << really it set's the 'this' scope to foo.prototype
570                         //$this$=foo|$private$
571                         //$this$=foo
572                         
573                     if (
574                             (this.ts.lookTok(1).type == 'NAME') 
575                         ) {
576                         //scopeName = this.ts.look(-3).data;
577                         this.ts.balanceN('(');
578                         token = this.ts.nextTok(); // should be {
579                             
580                         var fnScope = new Scope(this.braceNesting, scope, token.n, '');
581                         this.indexedScopes[this.ts.cursor] = fnScope;
582                         //scope = fnScope;
583                         //this.scopesIn(fnScope);
584                         this.parseScope(fnScope, aliases);
585                         locBraceNest++;
586                         //print(">>" +locBraceNest);
587                         continue; // no more processing..    
588                           
589                     }
590                     
591                      
592                 // foo = new (function() { }
593                 // (function() { }
594                 // RETURN function(...) {
595                     
596                     if (
597                            // (this.ts.lookTok(-1).tokN == Script.TOKlparen) && 
598                             (this.ts.lookTok(1).name != 'NAME')   
599                             
600                         //    (this.ts.lookTok(-2).tokN == Script.TOKnew) &&
601                          //   (this.ts.lookTok(-3).tokN == Script.TOKassign) &&
602                          //   (this.ts.lookTok(-4).tokN == Script.TOKidentifier)
603                         ) {
604                         //scopeName = this.ts.look(-3).data;
605                         this.ts.balanceN('(');
606                         token = this.ts.nextTok(); // should be {
607                         var fnScope = new Scope(this.braceNesting, scope, token.n, '$private$');
608                         this.indexedScopes[this.ts.cursor] = fnScope;
609                         //scope = ;
610                         //this.scopesIn(fnScope);
611                          this.parseScope(fnScope, aliases);
612                         locBraceNest++;
613                         //print(">>" +locBraceNest);
614                         continue; // no more processing..    
615                           
616                         
617                     }
618                     
619                     
620                     print(this.ts.context());
621                     throw "dont know how to handle function syntax??";
622                     
623                     continue;
624                     
625                     
626                     
627                     
628                 } // end checking for TOKfunction
629                     
630                 if (token.data == '{') {
631                     
632                      // foo = { // !var!!!
633                         //$this$=foo|Foo
634                
635                 
636                     if (
637                             (this.ts.lookTok(-1).data == '=') &&
638                             (this.ts.lookTok(-2).type == 'NAME') &&
639                             (this.ts.lookTok(-3).nane != 'VAR')  
640                         ) {
641                             
642                             scopeName = this.ts.look(-2).data;
643                             scopeName = fixAlias(scopeName);
644                             var fnScope = new Scope(this.braceNesting, scope, token.n, 
645                                 '$this$='+scopeName + '|'+scopeName
646                             );
647                             this.indexedScopes[this.ts.cursor] = fnScope;
648                             scope = fnScope;
649                             this.scopesIn(fnScope);
650                             
651                               
652                             locBraceNest++;
653                             //print(">>" +locBraceNest);
654                             continue; // no more processing..   
655                     }
656                     // foo : {
657                     // ?? add |foo| ????
658                       
659                     //print("GOT LBRACE : check for :");
660                     if (
661                             (this.ts.lookTok(-1).data == ':') &&
662                             (this.ts.lookTok(-2).type == 'NAME') &&
663                             (this.ts.lookTok(-3).name != 'VAR') 
664                         ) {
665                             
666                             scopeName = this.ts.lookTok(-2).data;
667                             scopeName = fixAlias(scopeName);
668                             var fnScope = new Scope(this.braceNesting, scope, token.n, scopeName);
669                             this.indexedScopes[this.ts.cursor] = fnScope;
670                             scope = fnScope;
671                             this.scopesIn(fnScope);
672                             
673                             locBraceNest++;
674                             //print(">>" +locBraceNest);
675                             continue; // no more processing..   
676                     }
677                     var fnScope = new Scope(this.braceNesting, scope, token.n, '');
678                     this.indexedScopes[this.ts.cursor] = fnScope;
679                     scope = fnScope;
680                     this.scopesIn(fnScope);
681                    
682                     locBraceNest++;
683                     //print(">>" +locBraceNest);
684                     continue;
685                     
686                 }
687                 if (token.data == '{') {
688                     
689                      
690                         if (this.currentDoc) {
691                             this.addSymbol('', true);
692
693                             //throw "Unconsumed Doc: (TOKrbrace)" + this.currentDoc.toSource();
694                         }
695                         
696                        
697                         locBraceNest--;
698                         
699                             //assert braceNesting >= scope.getBraceNesting();
700                         var closescope = this.scopeOut();   
701                         scope = this.scopes[this.scopes.length-1];
702                         //print("<<:" +  locBraceNest)
703                         //print("<<<<<< " + locBraceNest );
704                         if (locBraceNest < 0) {
705                            // print("POPED OF END OF SCOPE!");
706                             ///this.scopeOut();   
707                             //var ls = this.scopeOut();
708                             //ls.getUsedSymbols();
709                             return;
710                         }
711                         continue;
712                 }
713               
714                 
715             }
716             
717             
718         },
719      
720          
721         addSymbol: function(lastIdent, appendIt, atype )
722         {
723             
724             /*if (!this.currentDoc.tags.length) {
725                 
726               
727                 //print(this.currentDoc.toSource());
728                 //  this.currentDoc = false;
729                 
730                 print("SKIP ADD SYM: no tags");
731                 print(this.currentDoc.src);
732                 return;
733             }
734             */
735             if (this.currentDoc.getTag('private').length) {
736                 
737               
738                 //print(this.currentDoc.toSource());
739                  this.currentDoc = false;
740                 print("SKIP ADD SYM:  it's private");
741                 return;
742             }
743             
744             var token = this.ts.cur();
745             if (typeof(appendIt) == 'undefined') {
746                 appendIt= false;
747             }
748           //  print(this.currentDoc.toSource(););
749             if (this.currentDoc.getTag('event').length) {
750                 //?? why does it end up in desc - and not name/...
751                 print(this.currentDoc.getTag('event')[0]);
752                 lastIdent = '*' + this.currentDoc.getTag('event')[0].desc;
753                 //lastIdent = '*' + lastIdent ;
754             }
755             if (!lastIdent.length && this.currentDoc.getTag('property').length) {
756                 lastIdent = this.currentDoc.getTag('property')[0].name;
757                 //lastIdent = '*' + lastIdent ;
758             }
759             
760             var _s = lastIdent;
761             if (!/\./.test(_s)) {
762                     
763                 //print("WALKER ADDsymbol: " + lastIdent);
764                 
765                 var s = [];
766                 for (var i = 0; i < this.scopes.length;i++) {
767                     s.push(this.scopes[i].ident);
768                 }
769                 s.push(lastIdent);
770                 
771                 var s = s.join('|').split('|');
772                print("Walker:ADDSymbol: " + s.join('|') );
773                 var _t = '';
774                  _s = '';
775                 
776                 /// fixme - needs
777                 for (var i = 0; i < s.length;i++) {
778                     
779                     if (!s[i].length) {
780                         continue;
781                     }
782                     if ((s[i] == '$private$') || (s[i] == '$global$')) {
783                         _s = '';
784                         continue;
785                     }
786                     if (s[i].substring(0,6) == '$this$') {
787                         var ts = s[i].split('=');
788                         _t = ts[1];
789                         continue;
790                     }
791                     // when to use $this$ (probabl for events)
792                     _s += _s.length ? '.' : '';
793                     _s += s[i];
794                 }
795                     
796                 
797                 /// calc scope!!
798                 //print("ADDING SYMBOL: "+ s.join('|') +"\n"+ _s + "\n" +Script.prettyDump(this.currentDoc.toSource()));
799                 
800                 if (appendIt && !lastIdent.length) {
801                     
802                     // append, and no symbol???
803                     
804                     // see if it's a @class
805                     if (this.currentDoc.getTag('class').length) {
806                         _s = this.currentDoc.getTag('class')[0].desc;
807                         var symbol = new Symbol(_s, [], "CONSTRUCTOR", this.currentDoc);
808                         Parser.addSymbol(symbol);
809                         this.symbols[_s] = symbol;
810                         return;
811                     }
812                     
813                    // if (this.currentDoc.getTag('property').length) {
814                      //   print(Script.pretStringtyDump(this.currentDoc.toSource));
815                     //    throw "Add Prop?";
816                     //}
817                     
818                     _s = _s.replace(/\.prototype.*$/, '');
819                     if (typeof(this.symbols[_s]) == 'undefined') {
820                         print("Symbol:" + _s);
821                         print(this.currentDoc.src);
822                         
823                         throw "Trying to append symbol, but no doc available";
824                     }
825                         
826                     for (var i =0; i < this.currentDoc.tags.length;i++) {
827                         this.symbols[_s].addDocTag(this.currentDoc.tags[i]);
828                     }
829                     this.currentDoc = false;
830                     return;
831                 }
832             }    
833             if (typeof(this.symbols[_s]) != 'undefined') {
834                 
835                 if (this.symbols[_s].comment.hasTags) {
836                     // then existing comment doesnt has tags 
837                      throw "DUPLICATE Symbol " + _s;
838                 }
839                 // otherwise existing comment has tags - overwrite..
840                 
841                 
842             }
843             if (typeof(atype) == "undefined") {
844                 atype = 'OBJECT'; //this.currentDoc.getTag('class').length ? 'OBJECT' : 'FUNCTION';;
845                }
846             
847             var symbol = new Symbol(_s, [], atype, this.currentDoc);
848             
849             Parser.addSymbol(symbol);
850             this.symbols[_s] = symbol;
851             
852              this.currentDoc = false;
853             
854         },
855         
856         
857         
858         
859         scopesIn : function(s)
860         {
861             this.scopes.push(s);
862             //print(">>>" + this.ts.context()  + "\n>>>"+this.scopes.length+":" +this.scopeListToStr());
863             
864         },
865         scopeOut : function()
866         {
867             
868            // print("<<<" + this.ts.context()  + "\n<<<"+this.scopes.length+":" +this.scopeListToStr());
869             return this.scopes.pop();
870             
871         },
872         
873         scopeListToStr : function()
874         {
875             var s = [];
876             for (var i = 0; i < this.scopes.length;i++) {
877                 s.push(this.scopes[i].ident);
878             }
879             return  s.join('\n\t');
880             
881         }
882         
883     
884     
885      
886 });