JSDOC/BuildDocs.js
[gnome.introspection-doc-generator] / JSDOC / RooFile.js
1 //<script type="text/javscript">
2
3 XObject = imports.XObject.XObject;
4 console     = imports.console.console;
5 TokenStream = imports.TokenStream.TokenStream;
6 /**
7  * 
8  * this takes our collased file, and turns it into the config array..
9  * 
10  * 
11  * 
12  * 
13  * 
14  * 
15  */
16
17 RooFile  =  XObject.define(
18     function (ar)
19     {
20         RooFile.superclass.constructor.call(this, ar);
21        // console.log("STARTING OUTPUT");
22         
23          
24
25     },
26     TokenStream, 
27     {
28         
29         cfg : { },
30
31         parse: function()
32         {
33             
34             if (this.tokens[0].data == 'Pman.on') {
35                 // then it's a layout style..
36                 
37                 //Seed.quit();
38                 
39                 
40                 //console.dump(this.tokens);
41                 //              the list of statements inside of function..?
42                 var stmts =  this.tokens[1].items[1][2].items;
43                 // look for register..
44                 var topp = false;
45                 stmts.map( function(s, i) {
46                     if (s[0].data == 'Pman.register') {
47                         topp = brace = s[1].items[0][0].props;
48                     }
49                 });
50                 if (!topp) {
51                     console.dump(this.tokens);
52                     throw "could not find top props...";
53                     
54                 }
55                 
56                 this.cfg = this.parseProps(topp);
57                 this.cfg.name = this.tokens[3].data;
58                 
59                 
60                 //                  (            {          add    { this.panel (  {
61                 var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
62                 this.cfg.items = [ this.parseProps(cfg) ];
63                // console.dump(this.cfg); 
64                 
65                 return;
66             }
67             
68             if (this.tokens[2].props && typeof(this.tokens[2].props.create) != 'undefined') {
69                 //console.dump(this.tokens);
70                 this.cfg.name = this.tokens[0].data;
71                 
72                 
73                 
74                 var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
75                 //console.dump(this.tokens);
76                 this.cfg.items = [ this.parseProps(cfg) ];
77                 
78             }
79             // perfect for dialogs...
80             
81             
82             var pos = this.lookFor( 'function');
83             
84             // XXXXX = function(
85             var cfg = {};
86             
87             if (pos > -1 && (this.tokens[pos-1].data == '=') && (this.tokens[pos-2].type == 'NAME')) {
88                 
89                 this.cfg = {
90                     '*class' : this.tokens[pos-2].data,
91                     '*extends' : '',
92                     '//constructor' :  this.tokens[pos-2].prefix,
93                     '|constructor' : 'function ' + this.tokens[pos+1].toRaw() + 
94                             this.tokens[pos+2].toRaw(),
95                     
96                 };
97                 this.cursor = pos+2;
98                 
99             }
100             
101             if (pos < 0) {
102                 // no function - we have a static one...
103                 pos = this.lookFor( '=');
104                 if (pos > 1 && 
105                     (this.tokens[pos-1].type == 'NAME') &&
106                     (this.tokens[pos+1].data == '{')
107                 ) {
108                     this.cfg = {
109                         '*class' : this.tokens[pos-1].data,
110                         '//*class' :  this.tokens[pos-1].prefix,
111                         
112                         
113                     };
114                     XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].props));
115                     return;
116                     
117                 }
118                 
119                 
120                 
121             }
122             
123             
124               // Roo.apply (l
125             var pos = this.lookFor( 'Roo.apply');
126             //console.dump(this.tokens);
127             
128             
129             if (
130                 (pos > -1) &&
131                 (this.tokens[pos+1].items[0][0].data  == this.cfg['*class'] + '.prototype')
132             ) {
133                 // XXXXXx.prototype = {
134                 
135                 
136                     
137                 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[1][0].props));
138                 return;
139                 
140             }
141             
142             
143             var pos = this.lookFor('new');
144             
145             if (pos > -1 && 
146                 (this.tokens[pos-2].type == 'NAME') &&
147                 (this.tokens[pos-1].data == '=') && 
148                 (this.tokens[pos+1].type == 'NAME') &&
149                 (this.tokens[pos+2].data == '(') 
150             ) {
151                 
152                 this.cfg = {
153                     '//*class' : this.tokens[pos-2].prefix,
154                     '*class' : this.tokens[pos-2].data,
155                     '*extends' : this.tokens[pos+1].data
156                 };
157                     
158                 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+2].items[0][0].props));
159                 
160                 return;
161                 
162             }
163             
164             ///Builder.Provider.ProjectManager = new Roo.Observable({
165                 
166             
167             
168             var pos = this.lookFor( 'Roo.extend');
169             if (pos > -1) {
170                 
171                 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
172                 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
173                 
174                 // no more..
175                 return;
176             }
177             
178              
179                 
180             var pos = this.lookFor( 'Roo.extend');
181             if (pos > -1) {
182                 
183                 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
184                 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
185                 
186                 // no more..
187                 return;
188             }
189             
190             
191             
192             //console.dump(cfg);
193             //Seed.quit();
194             
195             
196             
197             // other type of layout
198           //  console.dump(this.tokens);
199             
200             // this type of file..
201             // xxxx.xxx = function
202             // -> into |constructor..
203             // -> extend + prototype
204              
205             
206             
207                 
208         },
209         
210         parseProps:  function(o)
211         {
212             var ret = { };
213             var fakeItems =  [];
214             for(var k in o) {
215                 
216                 
217                 if (o[k].key.data == '}') {
218                     // typo trailing comma in object def.
219                     continue;
220                 }
221                 
222                 var kv = k;
223                 if (o[k].key.type == 'STRN') {
224                     kv = o[k].key.toJS();
225                 }
226                 if (!o[k].val.length) {
227                     console.dump(o[k]);
228                 }
229                 //console.dump(o[k]);
230                 if (o[k].val[0].data == "function") {
231                     // add comments..
232                   //   console.dump(o[k].key.prefix); 
233                     var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
234                     pr = this.clean_prefix( pr) ;
235                     if (pr.length) {
236                         ret['//' +kv ] =  pr;
237                     }
238                     
239                     ret['|' +kv ] =  this.clean_body( this.expand(o[k].val));
240                     continue;
241                 }
242                 if (o[k].val[0].data == "[") {
243                     
244                     if (o[k].val[0].items[0][0].data == '{') {
245                         // array of objects..
246                         
247                         // this works for items..
248                         
249                         // used elsewhere for buttons: -> in which case we have a fake xtype
250                         
251                         
252                         
253                         // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
254                         var add = this.parseArray(o[k].val[0].items);
255                         if (kv == 'items') {
256                             ret[kv] = add;
257                             continue;
258                         }
259                         var fake_array = {
260                             xtype : 'Array.' + kv,
261                             '*prop' : kv,
262                             items : add
263                         }
264                         fakeItems.push(fake_array);
265                         continue;
266                     } 
267                     // raw array 
268                     
269                     
270                     ret['|' +kv ] =  this.clean_body(this.expand(o[k].val)); // remove ','...
271                     continue;
272                 }
273                 if (o[k].val[0].data == "(") {
274                     ret['|' +kv ] =  this.expand(o[k].val);
275                     continue;
276                 }
277                 if (o[k].val[0].data == "{") {
278                     
279                     // things that can be property of object type:
280                     // listeners, set, 
281                     var add = this.parseProps(o[k].val[0].props);
282                     if (kv == 'set' || kv =='listeners') {
283                         ret[kv ] = add;
284                         continue;
285                     }
286                     if ((typeof(add.xtype) != 'undefined') ||  ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
287                         add['*prop'] =  kv;
288                         fakeItems.push(add);
289                         continue;
290                     }
291                     
292                     
293                     ret[ '|' + kv ] =  this.expand(o[k].val);
294                     
295                     
296                     // this hsould be added to 'items', with a *prop element..
297                     continue;
298                 }
299                 //console.dump(o[k].val);
300                 
301                 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
302                     // single item piece of data...
303                     var t1= o[k].val[0];
304                     switch(o[k].val[0].type) {
305                         case 'STRN':
306                         case 'NUMB':
307                         case 'KEYW':
308                             ret[  kv ]  = t1.toJS();
309                             continue;
310                         case 'NAME':
311                             ret[ '|' + kv ] =  t1.data;
312                             continue;
313                         
314                     }
315                 }
316                
317                 ret[ '|' + kv ] =  this.expand(o[k].val);
318                 
319             }
320             if (!ret.items && fakeItems.length) {
321                 ret.items = [];
322             }
323             XObject.extend(fakeItems, function(e) {
324                 ret.items.push(e);
325             })
326             // merge fakeItems;
327             //console.dump(ret);
328             
329             return ret;
330         },
331         parseArray: function(ar) {
332           // console.dump(ar);
333            // Seed.quit();
334             var ret = [];
335             ar.map(function (e) {
336                 // has no props...
337                 if (typeof(e[0].props) == 'undefined') {
338                     return;
339                 }
340                
341                 
342                 ret.push( this.parseProps(e[0].props));
343                      
344             },this);
345              
346             return ret;
347           
348         },
349         
350         
351         expand: function(ar)
352         {
353             var ret = '';
354            
355             
356             for(var i =0 ; i < ar.length -1; i++) {
357                 ret += ar[i].toRaw();
358             }
359             
360            
361            
362             return ret;
363             
364             
365         },
366         clean_body : function(str)
367         {
368             var lns = str.split("\n");
369             var mindent = -1;
370             lns.map( function(l, i) {
371                 if (!i || !l.length || l.match(/^\s+$/)) {
372                     return;
373                 }
374                 
375                 var spc = l.match(/\s+/);
376                 if (!spc || !spc[0].length) {
377                     return;
378                 }
379                 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
380                 
381             });
382             //console.log(mindent + ":" + lns[0]);
383             var ar = [];
384             if (mindent < 0) {
385                 return str;
386             }
387             lns.map( function(l,i) {
388                 if (!i) {
389                     ar.push(l.replace(/^\s+/, ''));
390                     return;
391                 }
392                 ar.push(l.substring(mindent));
393             });
394             return ar.join("\n");
395         },
396         clean_prefix: function(str) {
397             
398             
399             
400             if (!str.length) {
401                 return '';
402             }
403             var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
404             return ret == "\n" ? '' : ret;
405             
406         }    
407              
408     
409 });