1 //<script type="text/javscript">
3 XObject = imports.XObject.XObject;
4 console = imports.console.console;
5 Collapse = imports.JSDOC.Collapse.Collapse;
8 * this takes our collased file, and turns it into the config array..
10 * @see rconv.js (our tester file)
14 * - Pman.Tab.* appears to work.
15 * .. next up ..Dialog...
20 * - xtype is combined on generated files. (not xns + xtype)
21 * - listeners are prefixed with '|' ...
26 JsParser = XObject.define(
29 JsParser.superclass.constructor.call(this, ar);
30 // console.log("STARTING OUTPUT");
42 // standard pman dialog
43 if (this.tokens[0].data == 'Pman.on') {
44 this.parsePmanLayout();
49 // Standard Pman Dialog -
50 if (this.tokens[2].props && typeof(this.tokens[2].props.create) != 'undefined') {
51 this.parsePmanDialog();
56 // Seed Gtk XObject application.
57 if (this.tokens.length > 2 && this.tokens[2].data.match(/^imports\./)) {
62 Seed.print("Unknown format");
63 Seed.print(JSON.stringify(this.tokens,null,4));
73 // perfect for dialogs... - is this our 'generic, non-pman code?'
76 var pos = this.lookFor( 'function');
81 if (pos > -1 && (this.tokens[pos-1].data == '=') && (this.tokens[pos-2].type == 'NAME')) {
84 '*class' : this.tokens[pos-2].data,
86 '//constructor' : this.tokens[pos-2].prefix,
87 '|constructor' : 'function ' + this.tokens[pos+1].toRaw() +
88 this.tokens[pos+2].toRaw()
96 // no function - we have a static one...
97 pos = this.lookFor( '=');
99 (this.tokens[pos-1].type == 'NAME') &&
100 (this.tokens[pos+1].data == '{')
103 '*class' : this.tokens[pos-1].data,
104 '//*class' : this.tokens[pos-1].prefix
108 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].props));
119 var pos = this.lookFor( 'Roo.apply');
120 //console.dump(this.tokens);
125 (this.tokens[pos+1].items[0][0].data == this.cfg['*class'] + '.prototype')
127 // XXXXXx.prototype = {
131 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[1][0].props));
137 var pos = this.lookFor('new');
140 (this.tokens[pos-2].type == 'NAME') &&
141 (this.tokens[pos-1].data == '=') &&
142 (this.tokens[pos+1].type == 'NAME') &&
143 (this.tokens[pos+2].data == '(')
147 '//*class' : this.tokens[pos-2].prefix,
148 '*class' : this.tokens[pos-2].data,
149 '*extends' : this.tokens[pos+1].data
152 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+2].items[0][0].props));
158 ///Builder.Provider.ProjectManager = new Roo.Observable({
162 var pos = this.lookFor( 'Roo.extend');
165 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
166 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
174 var pos = this.lookFor( 'Roo.extend');
177 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
178 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
191 // other type of layout
192 // console.dump(this.tokens);
194 // this type of file..
195 // xxxx.xxx = function
196 // -> into |constructor..
197 // -> extend + prototype
205 parsePmanLayout : function()
207 // then it's a layout style..
212 //console.dump(this.tokens);
213 // the list of statements inside of function..?
216 var stmts = this.tokens[1].items[1][2].items;
218 // look for register..
220 stmts.map( function(s, i) {
221 if (s[0].data == 'Pman.register') {
222 topp = brace = s[1].items[0][0].props;
226 console.dump(this.tokens);
227 throw "could not find top props...";
231 this.cfg = this.parseProps(topp);
232 this.cfg.name = this.tokens[3].data;
233 this.cfg.type = 'Roo';
235 // ( { add { this.panel ( {
236 var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
237 this.cfg.items = [ this.parseProps(cfg) ];
238 //console.dump(this.cfg);
242 parsePmanDialog : function() {
244 //console.dump(this.tokens);
245 this.cfg.name = this.tokens[0].data;
249 var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
250 his.cfg.type = 'Roo';
251 //console.dump(this.tokens);
252 //print(JSON.stringify(cfg,null,4)); Seed.quit();
254 // print("Trying standard dialog");Seed.quit();;
256 this.cfg.items = [ this.parseProps(cfg) ];
261 // Seed xobject file.
262 parseXObject : function() {
266 var pos = this.lookFor('XObject');
268 throw "Can not find XObject";
270 this.cfg.name = this.tokens[pos-3].data;
271 this.cfg.type = 'Gtk';
272 var cfg = this.tokens[pos+1].items[0][0].props;
273 this.cfg.items = [ this.parseProps(cfg) ];
275 //print(JSON.stringify(this.tokens[pos]));
277 //print(JSON.stringify(this.tokens,null,4)); Seed.quit();
285 * parse Imports lines.
289 parseImports : function()
291 // console.dump(this.tokens);
292 this.cfg.giImports = [];
293 this.cfg.imports= [];
295 var pos = this.lookFor('=');
300 var k = this.look(-1, true);
301 var v = this.look(1, true);
302 // Seed.print(k.data + " => " + v.data);
304 /// finish!!! - not an import ...
306 if (!v.data.match(/^imports/)) {
312 if (v.data.match(/^imports\.gi/)) {
314 this.cfg.giImports.push(v.data.replace(/imports\.gi\./, ''));
320 // two types of import left
322 if (v.data.match(/^imports\./)) {
323 this.cfg.imports[k.data] = v.data.replace(/imports\./, '') + '.js';
329 if (this.lookFor('[') > this.lookFor('=')) {
332 var bpos = this.lookFor('[');
333 // console.dump(this.tokens[bpos]);
335 this.cfg.imports[k.data] = this.tokens[bpos].items[0][0].toJS();
340 // console.dump(this.giImports);
341 // console.dump(this.imports);
346 ///------------------- GENERIC PARSING ------------------
353 parseProps: function(o)
355 //print(JSON.stringify(o,null,4));
361 //print( "parsing prop: " + k);
362 if (o[k].key.data == '}') {
363 // typo trailing comma in object def.
368 if (o[k].key.type == 'STRN') {
369 kv = o[k].key.toJS();
371 if (!o[k].val.length) {
375 //console.dump(o[k]);
376 if (o[k].val[0].data == "function") {
378 // console.dump(o[k].key.prefix);
379 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
380 pr = this.clean_prefix( pr) ;
384 //print("running expand");
385 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
390 if (o[k].val[0].data == "[") {
392 if (o[k].val[0].items[0][0].data == '{') {
393 // array of objects..
395 // this works for items..
397 // used elsewhere for buttons: -> in which case we have a fake xtype
401 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
402 var add = this.parseArray(o[k].val[0].items);
408 xtype : 'Array.' + kv,
412 fakeItems.push(fake_array);
418 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
421 if (o[k].val[0].data == "(") {
422 ret['|' +kv ] = this.expand(o[k].val);
425 // value is an object..
427 if (o[k].val[0].data == "{") {
429 // things that can be property of object type:
431 var add = this.parseProps(o[k].val[0].props);
435 if (kv == 'set' || kv =='listeners') {
439 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
446 ret[ '|' + kv ] = this.expand(o[k].val);
449 // this hsould be added to 'items', with a *prop element..
452 //console.dump(o[k].val);
454 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
455 // single item piece of data...
457 switch(o[k].val[0].type) {
461 ret[ kv ] = t1.toJS();
464 ret[ '|' + kv ] = t1.data;
470 ret[ '|' + kv ] = this.expand(o[k].val);
473 if (!ret.items && fakeItems.length) {
476 fakeItems.forEach( function(e) {
484 parseArray: function(ar) {
488 ar.map(function (e) {
490 if (typeof(e[0].props) == 'undefined') {
495 ret.push( this.parseProps(e[0].props));
504 * convert a function call token array back into a string
509 //print(JSON.stringify(ar,null,4));
511 for(var i =0 ; i < ar.length -1; i++) {
512 ret += ar[i].toRaw();
521 * change the indentation on a function
524 clean_body : function(str)
526 var lns = str.split("\n");
528 lns.map( function(l, i) {
529 if (!i || !l.length || l.match(/^\s+$/)) {
533 var spc = l.match(/\s+/);
534 if (!spc || !spc[0].length) {
537 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
540 //console.log(mindent + ":" + lns[0]);
545 lns.map( function(l,i) {
547 ar.push(l.replace(/^\s+/, ''));
550 ar.push(l.substring(mindent));
553 print(JSON.stringify(ar,null,4));
556 return ar.join("\n");
558 clean_prefix: function(str) {
565 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
566 return ret == "\n" ? '' : ret;