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;
17 * @extends JSDOC.TokenStream
18 * base class for parsing segments of token array..
21 * We want to make parsing the whole thing easy..
23 * so we do various tricks:
26 * a) white space collased
29 * { } - collapse into first element.
30 ( ) - collapse into first element.
31 [ ] - collapse into first element.
32 * c) items = , seperation within the above..
33 * d) props = for { xx: ... , yy: ....}
43 * @param {Object} array tokens
47 Collapse = XObject.define(
51 Collapse.superclass.constructor.call(this, cfg);
62 * @cfg {Boolean} collapseTop make statements array of top level tokens.
67 * @type {Array} top level statements
72 * @cfg {Boolean} createJSDOC create .jsdoc properties on tokens.
77 * @type {Array} allJSDOC if createJSDOC is set, then all the files JSDOC comments
78 * are stored here, in theory to verify that all have been used up..
83 * collapse the token array
84 * if collapseTop is set, then statments is set to the array statements (which is an array of tokens)
85 * otherwise this.tokens is set..
87 collapse : function(ar) {
89 ar = ar || this.tokens ;
92 ar = this._collapse(ar);
94 if (this.collapseTop) {
95 //print(JSON.stringify(ar, null,4));
97 return this.toItems(ar, [ ';', '{'] );
104 * Add all the comments to the closed token.
106 * token.comments = [] (array of COMMENTS)
107 * token.comment = combined string
108 * token.jsdoc = last comment (as DocComment)
112 spaces : function (toks)
123 for (var i = 0; i < this.tokens.length; i ++) {
124 tok = this.tokens[i];
126 if (this.createJSDOC) {
130 if (tok.is("COMM") || tok.is("WHIT")) {
137 pref.forEach( function(e) {
141 if (e.name == "JSDOC") {
142 tok.comment = e.data;
143 if (_this.createJSDOC) {
144 tok.jsdoc = new imports.DocComment.DocComment(tok.comment);
145 _this.allJSDOC.push(tok.jsdoc);
148 // kludge for private..
149 if (e.is("COMM") && e.data.match(/\/\/\s+private/)) {
150 tok.comment = '/** @private */';
151 if (_this.createJSDOC) {
152 tok.jsdoc = new imports.DocComment.DocComment(tok.comment);
153 _this.allJSDOC.push(tok.jsdoc);
157 tok.prefix += e.data;
172 _collapse : function(ar, depth) {
175 var st = new TokenStream({ tokens : ar });
179 var tok = st.look(1,true);
181 if (!tok || !tok.is) {
182 // Seed.print(TokenStream.toString(ret));
185 // console.log(tok.data);
197 ret.push(st.next(1));
206 var start = st.cursor;
208 var add = st.balance(tok.data);
211 console.dump(start + '...' + st.cursor);
212 console.dump(st.tokens);
219 //Seed.print(JSON.stringify(add, null,4));
223 var toks = add ? this._collapse(add, depth+1) : [];
229 if (tok.data != '{') {
230 // paramters or array elements..
231 tok.items = this.toItems(toks, [',']);
233 tok.items.forEach(function(tar) {
234 if (tar[0].is('NAME')) {
235 tok.args.push(tar[0].data);
247 // check for types.. it could be a list of statements.. or object
249 var ost = new TokenStream({tokens : toks});
250 //console.dump(ost.look(2,true) );
251 if (ost.look(2,true) && ost.look(2,true).data == ":") {
252 tok.props = this.toProps(toks);
254 // list of statemetns..
255 tok.items = this.toItems(toks,[ ';', '{'] );
260 //Seed.print(" ADD : " + add.length + " ITEMS: " + tok.items.length);
267 ret.push(st.next(1));
273 Seed.print("OOPS" + tok.type);
288 toItems : function(ar,sep)
293 for (var i = 0; i < ar.length; i ++) {
294 if (sep.indexOf(ar[i].data) < 0) {
299 if ((ar[i].data != ';') && g.length && (g[0].name == "VAR")) {;
316 toProps : function(ar)
321 var g = { key : '', val: [] }
326 for (var i = 0; i < ar.length; i ++) {
335 state =2; // should be ':'
339 if (ar[i].data != ',') {
343 g = { key : '', val: [] }
349 // last.. - if g.val.length is 0 then it's a trailing ','...
350 // we should really throw a syntax error in that case..
351 if (k.length && g.val.length) {