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;
11 * base class for parsing segments of token array..
14 * We want to make parsing the whole thing easy..
16 * so we do various tricks:
19 * a) white space collased
22 * { } - collapse into first element.
23 ( ) - collapse into first element.
24 [ ] - collapse into first element.
25 * c) items = , seperation within the above..
27 * usage: x = new Collapse(token_array)
34 Collapse = XObject.define(
38 Collapse.superclass.constructor.call(this, ar);
41 var ar = this.collapse(this.tokens);
51 spaces : function () {
57 for (var i = 0; i < this.tokens.length; i ++) {
59 if (tok.is("COMM") || tok.is("WHIT")) {
65 pref.forEach( function(e) {
80 collapse : function(ar) {
82 var st = new TokenStream(ar);
86 var tok = st.look(1,true);
87 if (!tok || !tok.is) {
88 // Seed.print(TokenStream.toString(ret));
91 // console.log(tok.data);
103 ret.push(st.next(1));
112 var start = st.cursor;
114 var add = st.balance(tok.data);
117 console.dump(start + '...' + st.cursor);
118 console.dump(st.tokens);
125 //Seed.print(JSON.stringify(add, null,4));
129 var toks = add ? this.collapse(add) : [];
135 if (tok.data != '{') {
136 // paramters or array elements..
137 tok.items = this.toItems(toks, [',']);
139 // check for types.. it could be a list of statements.. or object
141 var ost = new TokenStream(toks);
142 //console.dump(ost.look(2,true) );
143 if (ost.look(2,true) && ost.look(2,true).data == ":") {
144 tok.props = this.toProps(toks);
146 // list of statemetns..
147 tok.items = this.toItems(toks,[ ';', '{'] );;
159 //Seed.print(" ADD : " + add.length + " ITEMS: " + tok.items.length);
166 ret.push(st.next(1));
172 Seed.print("OOPS" + tok.type);
187 toItems : function(ar,sep)
192 for (var i = 0; i < ar.length; i ++) {
193 if (sep.indexOf(ar[i].data) < 0) {
209 toProps : function(ar)
214 var g = { key : '', val: [] }
219 for (var i = 0; i < ar.length; i ++) {
228 state =2; // should be ':'
232 if (ar[i].data != ',') {
236 g = { key : '', val: [] }
242 // last.. - if g.val.length is 0 then it's a trailing ','...
243 // we should really throw a syntax error in that case..
244 if (k.length && g.val.length) {