1 //<script type="text/javscript">
3 XObject = imports.XObject.XObject;
4 console = imports.console.console;
5 Collapse = imports.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...
19 RooFile = XObject.define(
22 RooFile.superclass.constructor.call(this, ar);
23 // console.log("STARTING OUTPUT");
35 // standard pman dialog
36 if (this.tokens[0].data == 'Pman.on') {
37 this.parsePmanLayout();
42 // Standard Pman Dialog -
43 if (this.tokens[2].props && typeof(this.tokens[2].props.create) != 'undefined') {
44 this.parsePmanDialog();
49 // Seed Gtk XObject application.
50 if (this.tokens.length > 2 && this.tokens[2].data.match(/^imports\./)) {
55 Seed.print("Unknown format");
56 Seed.print(JSON.stringify(this.tokens,null,4));
61 // perfect for dialogs...
64 var pos = this.lookFor( 'function');
69 if (pos > -1 && (this.tokens[pos-1].data == '=') && (this.tokens[pos-2].type == 'NAME')) {
72 '*class' : this.tokens[pos-2].data,
74 '//constructor' : this.tokens[pos-2].prefix,
75 '|constructor' : 'function ' + this.tokens[pos+1].toRaw() +
76 this.tokens[pos+2].toRaw()
84 // no function - we have a static one...
85 pos = this.lookFor( '=');
87 (this.tokens[pos-1].type == 'NAME') &&
88 (this.tokens[pos+1].data == '{')
91 '*class' : this.tokens[pos-1].data,
92 '//*class' : this.tokens[pos-1].prefix
96 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].props));
107 var pos = this.lookFor( 'Roo.apply');
108 //console.dump(this.tokens);
113 (this.tokens[pos+1].items[0][0].data == this.cfg['*class'] + '.prototype')
115 // XXXXXx.prototype = {
119 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[1][0].props));
125 var pos = this.lookFor('new');
128 (this.tokens[pos-2].type == 'NAME') &&
129 (this.tokens[pos-1].data == '=') &&
130 (this.tokens[pos+1].type == 'NAME') &&
131 (this.tokens[pos+2].data == '(')
135 '//*class' : this.tokens[pos-2].prefix,
136 '*class' : this.tokens[pos-2].data,
137 '*extends' : this.tokens[pos+1].data
140 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+2].items[0][0].props));
146 ///Builder.Provider.ProjectManager = new Roo.Observable({
150 var pos = this.lookFor( 'Roo.extend');
153 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
154 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
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));
179 // other type of layout
180 // console.dump(this.tokens);
182 // this type of file..
183 // xxxx.xxx = function
184 // -> into |constructor..
185 // -> extend + prototype
193 parsePmanLayout : function()
195 // then it's a layout style..
200 //console.dump(this.tokens);
201 // the list of statements inside of function..?
204 var stmts = this.tokens[1].items[1][2].items;
206 // look for register..
208 stmts.map( function(s, i) {
209 if (s[0].data == 'Pman.register') {
210 topp = brace = s[1].items[0][0].props;
214 console.dump(this.tokens);
215 throw "could not find top props...";
219 this.cfg = this.parseProps(topp);
220 this.cfg.name = this.tokens[3].data;
223 // ( { add { this.panel ( {
224 var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
225 this.cfg.items = [ this.parseProps(cfg) ];
226 //console.dump(this.cfg);
230 parsePmanDialog : function() {
232 //console.dump(this.tokens);
233 this.cfg.name = this.tokens[0].data;
237 var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
238 //console.dump(this.tokens);
239 //print(JSON.stringify(cfg,null,4)); Seed.quit();
241 // print("Trying standard dialog");Seed.quit();;
243 this.cfg.items = [ this.parseProps(cfg) ];
248 // Seed xobject file.
249 parseXObject : function() {
253 var pos = this.lookFor('XObject');
255 throw "Can not find XObject";
257 this.cfg.name = this.tokens[pos-3].data;
259 var cfg = this.tokens[pos+1].items[0][0].props;
260 this.cfg.items = [ this.parseProps(cfg) ];
262 //print(JSON.stringify(this.tokens[pos]));
264 //print(JSON.stringify(this.tokens,null,4)); Seed.quit();
272 * parse Imports lines.
276 parseImports : function()
278 // console.dump(this.tokens);
279 this.cfg.giImports = [];
280 this.cfg.imports= [];
282 var pos = this.lookFor('=');
287 var k = this.look(-1, true);
288 var v = this.look(1, true);
289 // Seed.print(k.data + " => " + v.data);
291 /// finish!!! - not an import ...
293 if (!v.data.match(/^imports/)) {
299 if (v.data.match(/^imports\.gi/)) {
301 this.cfg.giImports.push(v.data.replace(/imports\.gi\./, ''));
307 // two types of import left
309 if (v.data.match(/^imports\./)) {
310 this.cfg.imports[k.data] = v.data.replace(/imports\./, '') + '.js';
316 if (this.lookFor('[') > this.lookFor('=')) {
319 var bpos = this.lookFor('[');
320 // console.dump(this.tokens[bpos]);
322 this.cfg.imports[k.data] = this.tokens[bpos].items[0][0].toJS();
327 // console.dump(this.giImports);
328 // console.dump(this.imports);
333 ///------------------- GENERIC PARSING ------------------
340 parseProps: function(o)
342 //print(JSON.stringify(o,null,4));
348 //print( "parsing prop: " + k);
349 if (o[k].key.data == '}') {
350 // typo trailing comma in object def.
355 if (o[k].key.type == 'STRN') {
356 kv = o[k].key.toJS();
358 if (!o[k].val.length) {
362 //console.dump(o[k]);
363 if (o[k].val[0].data == "function") {
365 // console.dump(o[k].key.prefix);
366 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
367 pr = this.clean_prefix( pr) ;
371 //print("running expand");
372 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
377 if (o[k].val[0].data == "[") {
379 if (o[k].val[0].items[0][0].data == '{') {
380 // array of objects..
382 // this works for items..
384 // used elsewhere for buttons: -> in which case we have a fake xtype
388 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
389 var add = this.parseArray(o[k].val[0].items);
395 xtype : 'Array.' + kv,
399 fakeItems.push(fake_array);
405 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
408 if (o[k].val[0].data == "(") {
409 ret['|' +kv ] = this.expand(o[k].val);
412 // value is an object..
414 if (o[k].val[0].data == "{") {
416 // things that can be property of object type:
418 var add = this.parseProps(o[k].val[0].props);
422 if (kv == 'set' || kv =='listeners') {
426 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
433 ret[ '|' + kv ] = this.expand(o[k].val);
436 // this hsould be added to 'items', with a *prop element..
439 //console.dump(o[k].val);
441 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
442 // single item piece of data...
444 switch(o[k].val[0].type) {
448 ret[ kv ] = t1.toJS();
451 ret[ '|' + kv ] = t1.data;
457 ret[ '|' + kv ] = this.expand(o[k].val);
460 if (!ret.items && fakeItems.length) {
463 fakeItems.forEach( function(e) {
471 parseArray: function(ar) {
475 ar.map(function (e) {
477 if (typeof(e[0].props) == 'undefined') {
482 ret.push( this.parseProps(e[0].props));
494 //print(JSON.stringify(ar,null,4));
496 for(var i =0 ; i < ar.length -1; i++) {
497 ret += ar[i].toRaw();
504 clean_body : function(str)
506 var lns = str.split("\n");
508 lns.map( function(l, i) {
509 if (!i || !l.length || l.match(/^\s+$/)) {
513 var spc = l.match(/\s+/);
514 if (!spc || !spc[0].length) {
517 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
520 //console.log(mindent + ":" + lns[0]);
525 lns.map( function(l,i) {
527 ar.push(l.replace(/^\s+/, ''));
530 ar.push(l.substring(mindent));
532 return ar.join("\n");
534 clean_prefix: function(str) {
541 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
542 return ret == "\n" ? '' : ret;