4 * base class for parsing segments of token array..
7 * We want to make parsing the whole thing easy..
9 * so we do various tricks:
12 * a) white space collased
15 * { } - collapse into first element.
16 ( ) - collapse into first element.
17 [ ] - collapse into first element.
18 * c) items = , seperation within the above..
20 * usage: x = new Collapse(token_array)
29 public class Collapse : TokenStream {
32 public Collapse(TokenArray ar)
34 Collapse.superclass.constructor.call(this, ar);
37 ar = this.collapse(this.tokens);
47 spaces : function () {
53 for (var i = 0; i < this.tokens.length; i ++) {
55 if (tok.is("COMM") || tok.is("WHIT")) {
61 pref.forEach( function(e) {
76 collapse : function(ar) {
78 var st = new TokenStream(ar);
82 var tok = st.look(1,true);
83 if (!tok || !tok.is) {
84 // Seed.print(TokenStream.toString(ret));
87 // console.log(tok.data);
108 var start = st.cursor;
110 var add = st.balance(tok.data);
113 console.dump(start + '...' + st.cursor);
114 console.dump(st.tokens);
121 //Seed.print(JSON.stringify(add, null,4));
125 var toks = add ? this.collapse(add) : [];
131 if (tok.data != '{') {
132 // paramters or array elements..
133 tok.items = this.toItems(toks, [',']);
135 // check for types.. it could be a list of statements.. or object
137 var ost = new TokenStream(toks);
138 //console.dump(ost.look(2,true) );
139 if (ost.look(2,true) && ost.look(2,true).data == ":") {
140 tok.props = this.toProps(toks);
142 // list of statemetns..
143 tok.items = this.toItems(toks,[ ';', '{'] );;
155 //Seed.print(" ADD : " + add.length + " ITEMS: " + tok.items.length);
162 ret.push(st.next(1));
168 Seed.print("OOPS" + tok.type);
183 toItems : function(ar,sep)
188 for (var i = 0; i < ar.length; i ++) {
189 if (sep.indexOf(ar[i].data) < 0) {
194 if ((ar[i].data != ';') && g.length && (g[0].name == "VAR")) {;
211 toProps : function(ar)
216 var g = { key : '', val: [] }
221 for (var i = 0; i < ar.length; i ++) {
230 state =2; // should be ':'
234 if (ar[i].data != ',') {
238 g = { key : '', val: [] }
244 // last.. - if g.val.length is 0 then it's a trailing ','...
245 // we should really throw a syntax error in that case..
246 if (k.length && g.val.length) {