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() {
252 print(JSON.stringify(this.imports,null,4));
253 print(JSON.stringify(this.giImports,null,4));
255 var pos = this.lookFor('XObject');
257 throw "Can not find XObject";
259 print(JSON.stringify(this.tokens[pos]));
261 print(JSON.stringify(this.tokens,null,4)); Seed.quit();
269 * parse Imports lines.
273 parseImports : function()
275 // console.dump(this.tokens);
279 var pos = this.lookFor('=');
284 var k = this.look(-1, true);
285 var v = this.look(1, true);
286 // Seed.print(k.data + " => " + v.data);
288 /// finish!!! - not an import ...
290 if (!v.data.match(/^imports/)) {
296 if (v.data.match(/^imports\.gi/)) {
298 this.giImports.push(v.data.replace(/imports\.gi\./, ''));
304 // two types of import left
306 if (v.data.match(/^imports\./)) {
307 this.imports[k.data] = v.data.replace(/imports\./, '') + '.js';
313 if (this.lookFor('[') > this.lookFor('=')) {
316 var bpos = this.lookFor('[');
317 // console.dump(this.tokens[bpos]);
319 this.imports[k.data] = this.tokens[bpos].items[0][0].toJS();
324 // console.dump(this.giImports);
325 // console.dump(this.imports);
330 ///------------------- GENERIC PARSING ------------------
337 parseProps: function(o)
339 //print(JSON.stringify(o,null,4));
345 //print( "parsing prop: " + k);
346 if (o[k].key.data == '}') {
347 // typo trailing comma in object def.
352 if (o[k].key.type == 'STRN') {
353 kv = o[k].key.toJS();
355 if (!o[k].val.length) {
359 //console.dump(o[k]);
360 if (o[k].val[0].data == "function") {
362 // console.dump(o[k].key.prefix);
363 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
364 pr = this.clean_prefix( pr) ;
368 //print("running expand");
369 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
374 if (o[k].val[0].data == "[") {
376 if (o[k].val[0].items[0][0].data == '{') {
377 // array of objects..
379 // this works for items..
381 // used elsewhere for buttons: -> in which case we have a fake xtype
385 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
386 var add = this.parseArray(o[k].val[0].items);
392 xtype : 'Array.' + kv,
396 fakeItems.push(fake_array);
402 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
405 if (o[k].val[0].data == "(") {
406 ret['|' +kv ] = this.expand(o[k].val);
409 // value is an object..
411 if (o[k].val[0].data == "{") {
413 // things that can be property of object type:
415 var add = this.parseProps(o[k].val[0].props);
419 if (kv == 'set' || kv =='listeners') {
423 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
430 ret[ '|' + kv ] = this.expand(o[k].val);
433 // this hsould be added to 'items', with a *prop element..
436 //console.dump(o[k].val);
438 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
439 // single item piece of data...
441 switch(o[k].val[0].type) {
445 ret[ kv ] = t1.toJS();
448 ret[ '|' + kv ] = t1.data;
454 ret[ '|' + kv ] = this.expand(o[k].val);
457 if (!ret.items && fakeItems.length) {
460 fakeItems.forEach( function(e) {
468 parseArray: function(ar) {
472 ar.map(function (e) {
474 if (typeof(e[0].props) == 'undefined') {
479 ret.push( this.parseProps(e[0].props));
491 //print(JSON.stringify(ar,null,4));
493 for(var i =0 ; i < ar.length -1; i++) {
494 ret += ar[i].toRaw();
501 clean_body : function(str)
503 var lns = str.split("\n");
505 lns.map( function(l, i) {
506 if (!i || !l.length || l.match(/^\s+$/)) {
510 var spc = l.match(/\s+/);
511 if (!spc || !spc[0].length) {
514 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
517 //console.log(mindent + ":" + lns[0]);
522 lns.map( function(l,i) {
524 ar.push(l.replace(/^\s+/, ''));
527 ar.push(l.substring(mindent));
529 return ar.join("\n");
531 clean_prefix: function(str) {
538 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
539 return ret == "\n" ? '' : ret;