*
* - Pman.Tab.* appears to work.
* .. next up ..Dialog...
+ *
+ *
+ *
+ * Current issues:
+ * - xtype is combined on generated files. (not xns + xtype)
+ * - listeners are prefixed with '|' ...
+ *
*
*/
parse: function()
{
-
+ // standard pman dialog
if (this.tokens[0].data == 'Pman.on') {
- // then it's a layout style..
-
- //Seed.quit();
-
-
- //console.dump(this.tokens);
- // the list of statements inside of function..?
-
-
- var stmts = this.tokens[1].items[1][2].items;
-
- // look for register..
- var topp = false;
- stmts.map( function(s, i) {
- if (s[0].data == 'Pman.register') {
- topp = brace = s[1].items[0][0].props;
- }
- });
- if (!topp) {
- console.dump(this.tokens);
- throw "could not find top props...";
-
- }
-
- this.cfg = this.parseProps(topp);
- this.cfg.name = this.tokens[3].data;
-
-
- // ( { add { this.panel ( {
- var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
- this.cfg.items = [ this.parseProps(cfg) ];
- //console.dump(this.cfg);
-
+ this.parsePmanLayout();
return;
}
-
- //print(JSON.stringify(this.tokens,null,4)); Seed.quit();
-
-
+
// Standard Pman Dialog -
if (this.tokens[2].props && typeof(this.tokens[2].props.create) != 'undefined') {
- //console.dump(this.tokens);
- this.cfg.name = this.tokens[0].data;
-
-
-
- var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
- //console.dump(this.tokens);
-
- // print("Trying standard dialog");Seed.quit();;
-
- this.cfg.items = [ this.parseProps(cfg) ];
+ this.parsePmanDialog();
return;
-
}
- // perfect for dialogs...
+
+
+ // Seed Gtk XObject application.
+ if (this.tokens.length > 2 && this.tokens[2].data.match(/^imports\./)) {
+ this.parseXObject();
+ return;
+ }
+
+ Seed.print("Unknown format");
+ Seed.print(JSON.stringify(this.tokens,null,4));
+ Seed.quit();
+
+
+
+
+
+
+
+
+ // perfect for dialogs... - is this our 'generic, non-pman code?'
var pos = this.lookFor( 'function');
},
+
+ parsePmanLayout : function()
+ {
+ // then it's a layout style..
+
+ //Seed.quit();
+
+
+ //console.dump(this.tokens);
+ // the list of statements inside of function..?
+
+
+ var stmts = this.tokens[1].items[1][2].items;
+
+ // look for register..
+ var topp = false;
+ stmts.map( function(s, i) {
+ if (s[0].data == 'Pman.register') {
+ topp = brace = s[1].items[0][0].props;
+ }
+ });
+ if (!topp) {
+ console.dump(this.tokens);
+ throw "could not find top props...";
+
+ }
+
+ this.cfg = this.parseProps(topp);
+ this.cfg.name = this.tokens[3].data;
+
+
+ // ( { add { this.panel ( {
+ var cfg = this.tokens[7].items[0][0].props.add.val[2].items[2][3].items[0][0].props;
+ this.cfg.items = [ this.parseProps(cfg) ];
+ //console.dump(this.cfg);
+ },
+
+
+ parsePmanDialog : function() {
+
+ //console.dump(this.tokens);
+ this.cfg.name = this.tokens[0].data;
+
+
+
+ var cfg = this.tokens[2].props.create.val[2].items[1][3].items[0][0].props;
+ //console.dump(this.tokens);
+ //print(JSON.stringify(cfg,null,4)); Seed.quit();
+
+ // print("Trying standard dialog");Seed.quit();;
+
+ this.cfg.items = [ this.parseProps(cfg) ];
+ return;
+
+ },
+
+ // Seed xobject file.
+ parseXObject : function() {
+
+ this.parseImports();
+
+ var pos = this.lookFor('XObject');
+ if (pos < 0) {
+ throw "Can not find XObject";
+ }
+ this.cfg.name = this.tokens[pos-3].data;
+
+ var cfg = this.tokens[pos+1].items[0][0].props;
+ this.cfg.items = [ this.parseProps(cfg) ];
+
+ //print(JSON.stringify(this.tokens[pos]));
+
+ //print(JSON.stringify(this.tokens,null,4)); Seed.quit();
+ //Seed.quit();
+
+ },
+
+
+
+ /**
+ * parse Imports lines.
+ *
+ */
+
+ parseImports : function()
+ {
+ // console.dump(this.tokens);
+ this.cfg.giImports = [];
+ this.cfg.imports= [];
+ while (true) {
+ var pos = this.lookFor('=');
+ if (pos < 0) {
+ break;
+ }
+ this.cursor = pos;
+ var k = this.look(-1, true);
+ var v = this.look(1, true);
+ // Seed.print(k.data + " => " + v.data);
+
+ /// finish!!! - not an import ...
+
+ if (!v.data.match(/^imports/)) {
+ return; ///
+
+ this.cursor++;
+ continue;
+ }
+ if (v.data.match(/^imports\.gi/)) {
+ // gi import..
+ this.cfg.giImports.push(v.data.replace(/imports\.gi\./, ''));
+
+ this.cursor++;
+ continue;
+ }
+
+ // two types of import left
+ // imports.xnew
+ if (v.data.match(/^imports\./)) {
+ this.cfg.imports[k.data] = v.data.replace(/imports\./, '') + '.js';
+ this.cursor++;
+ continue;
+ }
+ // imports[.....]
+ this.cursor++;
+ if (this.lookFor('[') > this.lookFor('=')) {
+ continue;
+ }
+ var bpos = this.lookFor('[');
+ // console.dump(this.tokens[bpos]);
+
+ this.cfg.imports[k.data] = this.tokens[bpos].items[0][0].toJS();
+
+ this.cursor++;
+
+ }
+ // console.dump(this.giImports);
+ // console.dump(this.imports);
+ //Seed.quit();
+
+ },
+
+ ///------------------- GENERIC PARSING ------------------
+
+
+
+
+
+
parseProps: function(o)
{
- print(JSON.stringify(o,null,4));
+ //print(JSON.stringify(o,null,4));
var ret = { };
var fakeItems = [];
for(var k in o) {
-
+ //print( "parsing prop: " + k);
if (o[k].key.data == '}') {
// typo trailing comma in object def.
continue;
if (pr.length) {
ret['//' +kv ] = pr;
}
-
+ //print("running expand");
ret['|' +kv ] = this.clean_body( this.expand(o[k].val));
continue;
}
},
-
+ /**
+ * convert a function call token array back into a string
+ */
expand: function(ar)
{
var ret = '';
-
+ //print(JSON.stringify(ar,null,4));
for(var i =0 ; i < ar.length -1; i++) {
ret += ar[i].toRaw();
}
-
-
return ret;
},
+
+ /***
+ * change the indentation on a function
+ *
+ */
clean_body : function(str)
{
var lns = str.split("\n");