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 '|' ...
22 * - modkey is not getting picked up..
23 * - suspect some of the elements are not getting flattened
27 JsParser = XObject.define(
30 JsParser.superclass.constructor.call(this, ar);
31 // console.log("STARTING OUTPUT");
43 // standard pman dialog
44 if (this.tokens[0].data == 'Pman.on') {
45 this.parsePmanLayout();
50 // Standard Pman Dialog -
51 if (this.tokens[2].props && typeof(this.tokens[2].props.create) != 'undefined') {
52 this.parsePmanDialog();
57 // Seed Gtk XObject application.
58 if (this.tokens.length > 2 && this.tokens[2].data.match(/^imports\./)) {
63 Seed.print("Unknown format");
64 Seed.print(JSON.stringify(this.tokens,null,4));
74 // perfect for dialogs... - is this our 'generic, non-pman code?'
77 var pos = this.lookFor( 'function');
82 if (pos > -1 && (this.tokens[pos-1].data == '=') && (this.tokens[pos-2].type == 'NAME')) {
85 '*class' : this.tokens[pos-2].data,
87 '//constructor' : this.tokens[pos-2].prefix,
88 '|constructor' : 'function ' + this.tokens[pos+1].toRaw() +
89 this.tokens[pos+2].toRaw()
97 // no function - we have a static one...
98 pos = this.lookFor( '=');
100 (this.tokens[pos-1].type == 'NAME') &&
101 (this.tokens[pos+1].data == '{')
104 '*class' : this.tokens[pos-1].data,
105 '//*class' : this.tokens[pos-1].prefix
109 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].props));
120 var pos = this.lookFor( 'Roo.apply');
121 //console.dump(this.tokens);
126 (this.tokens[pos+1].items[0][0].data == this.cfg['*class'] + '.prototype')
128 // XXXXXx.prototype = {
132 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[1][0].props));
138 var pos = this.lookFor('new');
141 (this.tokens[pos-2].type == 'NAME') &&
142 (this.tokens[pos-1].data == '=') &&
143 (this.tokens[pos+1].type == 'NAME') &&
144 (this.tokens[pos+2].data == '(')
148 '//*class' : this.tokens[pos-2].prefix,
149 '*class' : this.tokens[pos-2].data,
150 '*extends' : this.tokens[pos+1].data
153 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+2].items[0][0].props));
159 ///Builder.Provider.ProjectManager = new Roo.Observable({
163 var pos = this.lookFor( 'Roo.extend');
166 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
167 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
175 var pos = this.lookFor( 'Roo.extend');
178 this.cfg['*extends'] = this.tokens[pos+1].items[1][0].data;
179 XObject.extend(this.cfg, this.parseProps(this.tokens[pos+1].items[2][0].props));
192 // other type of layout
193 // console.dump(this.tokens);
195 // this type of file..
196 // xxxx.xxx = function
197 // -> into |constructor..
198 // -> extend + prototype
206 parsePmanLayout : function()
208 // then it's a layout style..
213 //console.dump(this.tokens);
214 // the list of statements inside of function..?
217 var stmts = this.tokens[1].items[1][2].items;
219 // look for register..
221 stmts.map( function(s, i) {
222 if (s[0].data == 'Pman.register') {
223 topp = brace = s[1].items[0][0].props;
227 console.dump(this.tokens);
228 throw "could not find top props...";
231 //print(JSON.stringify(topp,null,4));
233 this.cfg = this.parseProps(topp);
234 for(var k in this.cfg) {
235 this.cfg[k.replace(/^\|/, '')] = this.cfg[k];
238 this.cfg.title = this.cfg.name;
239 delete this.cfg.name;
241 // this.cfg.fullname = this.cfg.name;
242 this.cfg.type = 'Roo';
246 // looking for parent / name..
249 this.cfg.modOrder = this.cfg.modKey.split('-').shift();
250 print(JSON.stringify(this.cfg,null,4));
253 // ( { add { this.panel ( {
254 var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
255 this.cfg.items = [ this.parseProps(cfg) ];
256 //console.dump(this.cfg);
260 parsePmanDialog : function() {
262 //console.dump(this.tokens);
263 this.cfg.name = this.tokens[0].data;
267 var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
268 this.cfg.type = 'Roo';
269 //console.dump(this.tokens);
270 //print(JSON.stringify(cfg,null,4)); Seed.quit();
272 // print("Trying standard dialog");Seed.quit();;
274 this.cfg.items = [ this.parseProps(cfg) ];
279 // Seed xobject file.
280 parseXObject : function() {
284 var pos = this.lookFor('XObject');
286 throw "Can not find XObject";
288 this.cfg.name = this.tokens[pos-3].data;
289 this.cfg.type = 'Gtk';
290 var cfg = this.tokens[pos+1].items[0][0].props;
291 this.cfg.items = [ this.parseProps(cfg) ];
293 //print(JSON.stringify(this.tokens[pos]));
295 //print(JSON.stringify(this.tokens,null,4)); Seed.quit();
303 * parse Imports lines.
307 parseImports : function()
309 // console.dump(this.tokens);
310 this.cfg.giImports = [];
311 this.cfg.imports= [];
313 var pos = this.lookFor('=');
318 var k = this.look(-1, true);
319 var v = this.look(1, true);
320 // Seed.print(k.data + " => " + v.data);
322 /// finish!!! - not an import ...
324 if (!v.data.match(/^imports/)) {
330 if (v.data.match(/^imports\.gi/)) {
332 this.cfg.giImports.push(v.data.replace(/imports\.gi\./, ''));
338 // two types of import left
340 if (v.data.match(/^imports\./)) {
341 this.cfg.imports[k.data] = v.data.replace(/imports\./, '') + '.js';
347 if (this.lookFor('[') > this.lookFor('=')) {
350 var bpos = this.lookFor('[');
351 // console.dump(this.tokens[bpos]);
353 this.cfg.imports[k.data] = this.tokens[bpos].items[0][0].toJS();
358 // console.dump(this.giImports);
359 // console.dump(this.imports);
364 ///------------------- GENERIC PARSING ------------------
371 parseProps: function(o)
373 //print(JSON.stringify(o,null,4));
379 //print( "parsing prop: " + k);
380 if (o[k].key.data == '}') {
381 // typo trailing comma in object def.
386 if (o[k].key.type == 'STRN') {
387 kv = o[k].key.toJS();
389 if (!o[k].val.length) {
393 //console.dump(o[k]);
394 if (o[k].val[0].data == "function") {
396 // console.dump(o[k].key.prefix);
397 var pr = typeof(o[k].key.prefix) == 'undefined' ? '' : o[k].key.prefix ;
398 pr = this.clean_prefix( pr) ;
402 //print("running expand");
403 ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
408 if (o[k].val[0].data == "[") {
410 if (o[k].val[0].items[0][0].data == '{') {
411 // array of objects..
413 // this works for items..
415 // used elsewhere for buttons: -> in which case we have a fake xtype
419 // if K is not ITEMS - we need to add '*prop' -> and add it to the items array..
420 var add = this.parseArray(o[k].val[0].items);
425 add.forEach(function(a) {
426 a['*prop'] = kv + '[]';
435 ret['|' +kv ] = this.clean_body(this.expand(o[k].val)); // remove ','...
438 if (o[k].val[0].data == "(") {
439 ret['|' +kv ] = this.expand(o[k].val);
442 // value is an object..
444 if (o[k].val[0].data == "{") {
446 // things that can be property of object type:
448 var add = this.parseProps(o[k].val[0].props);
452 if (kv == 'set' || kv =='listeners') {
456 if ((typeof(add.xtype) != 'undefined') || ['sortInfo', 'center', 'east', 'west', 'north', 'south'].indexOf(kv) > -1) {
463 ret[ '|' + kv ] = this.expand(o[k].val);
466 // this hsould be added to 'items', with a *prop element..
469 //console.dump(o[k].val);
471 if (o[k].val[1].data == ',' || o[k].val[1].data == '}') {
472 // single item piece of data...
474 switch(o[k].val[0].type) {
478 ret[ kv ] = t1.toJS();
481 ret[ '|' + kv ] = t1.data;
487 ret[ '|' + kv ] = this.clean_body(this.expand(o[k].val));
490 if (!ret.items && fakeItems.length) {
493 fakeItems.forEach( function(e) {
501 parseArray: function(ar) {
505 ar.map(function (e) {
507 if (typeof(e[0].props) == 'undefined') {
512 ret.push( this.parseProps(e[0].props));
521 * convert a function call token array back into a string
526 //print(JSON.stringify(ar,null,4));
528 for(var i =0 ; i < ar.length -1; i++) {
529 ret += ar[i].toRaw();
538 * change the indentation on a function
541 clean_body : function(str)
543 var lns = str.split("\n");
545 lns.map( function(l, i) {
546 if (!i || !l.length || l.match(/^\s+$/)) {
550 var spc = l.match(/\s+/);
551 if (!spc || !spc[0].length) {
554 mindent = mindent < 0 ? spc[0].length : Math.min(spc[0].length, mindent);
557 //console.log(mindent + ":" + lns[0]);
562 lns.map( function(l,i) {
564 ar.push(l.replace(/^\s+/, ''));
567 ar.push(l.substring(mindent));
570 //print(JSON.stringify(ar,null,4));
573 return ar.join("\n");
575 clean_prefix: function(str) {
582 var ret = str.replace(/^\s+/gm, "\n").replace(/\n+/gm, "\n");
583 return ret == "\n" ? '' : ret;