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,null,4)); Seed.quit();
267 * parse Imports lines.
271 parseImports : function()
273 // console.dump(this.tokens);
277 var pos = this.lookFor('=');
282 var k = this.look(-1, true);
283 var v = this.look(1, true);
284 // Seed.print(k.data + " => " + v.data);
286 /// finish!!! - not an import ...
288 if (!v.data.match(/^imports/)) {
294 if (v.data.match(/^imports\.gi/)) {
296 this.giImports.push(v.data.replace(/imports\.gi\./, ''));
302 // two types of import left
304 if (v.data.match(/^imports\./)) {
305 this.imports[k.data] = v.data.replace(/imports\./, '') + '.js';
311 if (this.lookFor('[') > this.lookFor('=')) {
314 var bpos = this.lookFor('[');
315 // console.dump(this.tokens[bpos]);
317 this.imports[k.data] = this.tokens[bpos].items[0][0].toJS();
322 // console.dump(this.giImports);
323 // console.dump(this.imports);
328 ///------------------- GENERIC PARSING ------------------
335 parseProps: function(o)
337 //print(JSON.stringify(o,null,4));
343 //print( "parsing prop: " + k);
344 if (o[k].key.data == '}') {
345 // typo trailing comma in object def.
350 if (o[k].key.type == 'STRN') {
351 kv = o[k].key.toJS();
353 if (!o[k].val.length) {
357 //console.dump(o[k]);
358 if (o[k].val[0].data == "function") {
360 // console.dump(o[k].key.prefix);
361 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
362 pr = this.clean_prefix( pr) ;
366 //print("running expand");
367 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
372 if (o[k].val[0].data == "[") {
374 if (o[k].val[0].items[0][0].data == '{') {
375 // array of objects..
377 // this works for items..
379 // used elsewhere for buttons: -> in which case we have a fake xtype
383 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
384 var add = this.parseArray(o[k].val[0].items);
390 xtype : 'Array.' + kv,
394 fakeItems.push(fake_array);
400 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
403 if (o[k].val[0].data == "(") {
404 ret['|' +kv ] = this.expand(o[k].val);
407 // value is an object..
409 if (o[k].val[0].data == "{") {
411 // things that can be property of object type:
413 var add = this.parseProps(o[k].val[0].props);
417 if (kv == 'set' || kv =='listeners') {
421 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
428 ret[ '|' + kv ] = this.expand(o[k].val);
431 // this hsould be added to 'items', with a *prop element..
434 //console.dump(o[k].val);
436 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
437 // single item piece of data...
439 switch(o[k].val[0].type) {
443 ret[ kv ] = t1.toJS();
446 ret[ '|' + kv ] = t1.data;
452 ret[ '|' + kv ] = this.expand(o[k].val);
455 if (!ret.items && fakeItems.length) {
458 fakeItems.forEach( function(e) {
466 parseArray: function(ar) {
470 ar.map(function (e) {
472 if (typeof(e[0].props) == 'undefined') {
477 ret.push( this.parseProps(e[0].props));
489 //print(JSON.stringify(ar,null,4));
491 for(var i =0 ; i < ar.length -1; i++) {
492 ret += ar[i].toRaw();
499 clean_body : function(str)
501 var lns = str.split("\n");
503 lns.map( function(l, i) {
504 if (!i || !l.length || l.match(/^\s+$/)) {
508 var spc = l.match(/\s+/);
509 if (!spc || !spc[0].length) {
512 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
515 //console.log(mindent + ":" + lns[0]);
520 lns.map( function(l,i) {
522 ar.push(l.replace(/^\s+/, ''));
525 ar.push(l.substring(mindent));
527 return ar.join("\n");
529 clean_prefix: function(str) {
536 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
537 return ret == "\n" ? '' : ret;