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...
20 * - xtype is combined on generated files. (not xns + xtype)
21 * - listeners are prefixed with '|' ...
26 RooFile = XObject.define(
29 RooFile.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;
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 //console.dump(this.tokens);
251 //print(JSON.stringify(cfg,null,4)); Seed.quit();
253 // print("Trying standard dialog");Seed.quit();;
255 this.cfg.items = [ this.parseProps(cfg) ];
260 // Seed xobject file.
261 parseXObject : function() {
265 var pos = this.lookFor('XObject');
267 throw "Can not find XObject";
269 this.cfg.name = this.tokens[pos-3].data;
271 var cfg = this.tokens[pos+1].items[0][0].props;
272 this.cfg.items = [ this.parseProps(cfg) ];
274 //print(JSON.stringify(this.tokens[pos]));
276 //print(JSON.stringify(this.tokens,null,4)); Seed.quit();
284 * parse Imports lines.
288 parseImports : function()
290 // console.dump(this.tokens);
291 this.cfg.giImports = [];
292 this.cfg.imports= [];
294 var pos = this.lookFor('=');
299 var k = this.look(-1, true);
300 var v = this.look(1, true);
301 // Seed.print(k.data + " => " + v.data);
303 /// finish!!! - not an import ...
305 if (!v.data.match(/^imports/)) {
311 if (v.data.match(/^imports\.gi/)) {
313 this.cfg.giImports.push(v.data.replace(/imports\.gi\./, ''));
319 // two types of import left
321 if (v.data.match(/^imports\./)) {
322 this.cfg.imports[k.data] = v.data.replace(/imports\./, '') + '.js';
328 if (this.lookFor('[') > this.lookFor('=')) {
331 var bpos = this.lookFor('[');
332 // console.dump(this.tokens[bpos]);
334 this.cfg.imports[k.data] = this.tokens[bpos].items[0][0].toJS();
339 // console.dump(this.giImports);
340 // console.dump(this.imports);
345 ///------------------- GENERIC PARSING ------------------
352 parseProps: function(o)
354 //print(JSON.stringify(o,null,4));
360 //print( "parsing prop: " + k);
361 if (o[k].key.data == '}') {
362 // typo trailing comma in object def.
367 if (o[k].key.type == 'STRN') {
368 kv = o[k].key.toJS();
370 if (!o[k].val.length) {
374 //console.dump(o[k]);
375 if (o[k].val[0].data == "function") {
377 // console.dump(o[k].key.prefix);
378 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
379 pr = this.clean_prefix( pr) ;
383 //print("running expand");
384 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
389 if (o[k].val[0].data == "[") {
391 if (o[k].val[0].items[0][0].data == '{') {
392 // array of objects..
394 // this works for items..
396 // used elsewhere for buttons: -> in which case we have a fake xtype
400 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
401 var add = this.parseArray(o[k].val[0].items);
407 xtype : 'Array.' + kv,
411 fakeItems.push(fake_array);
417 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
420 if (o[k].val[0].data == "(") {
421 ret['|' +kv ] = this.expand(o[k].val);
424 // value is an object..
426 if (o[k].val[0].data == "{") {
428 // things that can be property of object type:
430 var add = this.parseProps(o[k].val[0].props);
434 if (kv == 'set' || kv =='listeners') {
438 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
445 ret[ '|' + kv ] = this.expand(o[k].val);
448 // this hsould be added to 'items', with a *prop element..
451 //console.dump(o[k].val);
453 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
454 // single item piece of data...
456 switch(o[k].val[0].type) {
460 ret[ kv ] = t1.toJS();
463 ret[ '|' + kv ] = t1.data;
469 ret[ '|' + kv ] = this.expand(o[k].val);
472 if (!ret.items && fakeItems.length) {
475 fakeItems.forEach( function(e) {
483 parseArray: function(ar) {
487 ar.map(function (e) {
489 if (typeof(e[0].props) == 'undefined') {
494 ret.push( this.parseProps(e[0].props));
503 * convert a function call token array back into a string
508 //print(JSON.stringify(ar,null,4));
510 for(var i =0 ; i < ar.length -1; i++) {
511 ret += ar[i].toRaw();
520 * change the indentation on a function
523 clean_body : function(str)
525 var lns = str.split("\n");
527 lns.map( function(l, i) {
528 if (!i || !l.length || l.match(/^\s+$/)) {
532 var spc = l.match(/\s+/);
533 if (!spc || !spc[0].length) {
536 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
539 //console.log(mindent + ":" + lns[0]);
544 lns.map( function(l,i) {
546 ar.push(l.replace(/^\s+/, ''));
549 ar.push(l.substring(mindent));
551 return ar.join("\n");
553 clean_prefix: function(str) {
560 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
561 return ret == "\n" ? '' : ret;