1 //<script type="text/javscript">
2 XObject = imports.XObject.XObject;
5 console = imports.console.console;
7 // make sure parent is loaded..
8 TokenStream = imports.TokenStream.TokenStream;
16 * base class for parsing segments of token array..
19 * We want to make parsing the whole thing easy..
21 * so we do various tricks:
24 * a) white space collased
27 * { } - collapse into first element.
28 ( ) - collapse into first element.
29 [ ] - collapse into first element.
30 * c) items = , seperation within the above..
32 * usage: x = new Collapse(token_array)
39 Collapse = XObject.define(
40 function (ar, scrFile)
43 Collapse.superclass.constructor.call(this, ar, scrFile);
46 var nar = this.collapse(this.tokens);
56 spaces : function () {
62 for (var i = 0; i < this.tokens.length; i ++) {
65 if (tok.is("COMM") || tok.is("WHIT")) {
71 pref.forEach( function(e) {
75 if (e.name == "JSDOC") {
90 collapse : function(ar, depth) {
93 var st = new TokenStream(ar);
97 var tok = st.look(1,true);
99 if (!tok || !tok.is) {
100 // Seed.print(TokenStream.toString(ret));
103 // console.log(tok.data);
115 ret.push(st.next(1));
124 var start = st.cursor;
126 var add = st.balance(tok.data);
129 console.dump(start + '...' + st.cursor);
130 console.dump(st.tokens);
137 //Seed.print(JSON.stringify(add, null,4));
141 var toks = add ? this.collapse(add, depth+1) : [];
147 if (tok.data != '{') {
148 // paramters or array elements..
149 tok.items = this.toItems(toks, [',']);
153 // check for types.. it could be a list of statements.. or object
155 var ost = new TokenStream(toks);
156 //console.dump(ost.look(2,true) );
157 if (ost.look(2,true) && ost.look(2,true).data == ":") {
158 tok.props = this.toProps(toks);
160 // list of statemetns..
161 tok.items = this.toItems(toks,[ ';', '{'] );;
173 //Seed.print(" ADD : " + add.length + " ITEMS: " + tok.items.length);
180 ret.push(st.next(1));
186 Seed.print("OOPS" + tok.type);
201 toItems : function(ar,sep)
206 for (var i = 0; i < ar.length; i ++) {
207 if (sep.indexOf(ar[i].data) < 0) {
212 if ((ar[i].data != ';') && g.length && (g[0].name == "VAR")) {;
229 toProps : function(ar)
234 var g = { key : '', val: [] }
239 for (var i = 0; i < ar.length; i ++) {
248 state =2; // should be ':'
252 if (ar[i].data != ',') {
256 g = { key : '', val: [] }
262 // last.. - if g.val.length is 0 then it's a trailing ','...
263 // we should really throw a syntax error in that case..
264 if (k.length && g.val.length) {