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(Gee.ArrayList<Token> tokens)
38 ar = this.collapse(this.tokens);
47 var ar = new Gee.ArrayList<Token>()
48 var pref = new Gee.ArrayList<Token>();
52 for (var i = 0; i < this.tokens.size; i ++) {
53 var tok = this.tokens[i];
54 if (tok.is("COMM") || tok.is("WHIT")) {
60 pref.forEach( function(e) {
75 collapse : function(ar) {
77 var st = new TokenStream(ar);
81 var tok = st.look(1,true);
82 if (!tok || !tok.is) {
83 // Seed.print(TokenStream.toString(ret));
86 // console.log(tok.data);
107 var start = st.cursor;
109 var add = st.balance(tok.data);
112 console.dump(start + '...' + st.cursor);
113 console.dump(st.tokens);
120 //Seed.print(JSON.stringify(add, null,4));
124 var toks = add ? this.collapse(add) : [];
130 if (tok.data != '{') {
131 // paramters or array elements..
132 tok.items = this.toItems(toks, [',']);
134 // check for types.. it could be a list of statements.. or object
136 var ost = new TokenStream(toks);
137 //console.dump(ost.look(2,true) );
138 if (ost.look(2,true) && ost.look(2,true).data == ":") {
139 tok.props = this.toProps(toks);
141 // list of statemetns..
142 tok.items = this.toItems(toks,[ ';', '{'] );;
154 //Seed.print(" ADD : " + add.length + " ITEMS: " + tok.items.length);
161 ret.push(st.next(1));
167 Seed.print("OOPS" + tok.type);
182 toItems : function(ar,sep)
187 for (var i = 0; i < ar.length; i ++) {
188 if (sep.indexOf(ar[i].data) < 0) {
193 if ((ar[i].data != ';') && g.length && (g[0].name == "VAR")) {;
210 toProps : function(ar)
215 var g = { key : '', val: [] }
220 for (var i = 0; i < ar.length; i ++) {
229 state =2; // should be ':'
233 if (ar[i].data != ',') {
237 g = { key : '', val: [] }
243 // last.. - if g.val.length is 0 then it's a trailing ','...
244 // we should really throw a syntax error in that case..
245 if (k.length && g.val.length) {