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;
13 * @extends JSDOC.TokenStream
14 * base class for parsing segments of token array..
17 * We want to make parsing the whole thing easy..
19 * so we do various tricks:
22 * a) white space collased
25 * { } - collapse into first element.
26 ( ) - collapse into first element.
27 [ ] - collapse into first element.
28 * c) items = , seperation within the above..
29 * d) props = for { xx: ... , yy: ....}
39 * @param {Object} array tokens
43 Collapse = XObject.define(
47 Collapse.superclass.constructor.call(this, cfg);
58 * @cfg {Boolean} collapseTop make statements array of top level tokens.
63 * @type {Array} top level statements
68 * @cfg {Boolean} createJSDOC create .jsdoc properties on tokens.
73 * @type {Array} allJSDOC if createJSDOC is set, then all the files JSDOC comments
74 * are stored here, in theory to verify that all have been used up..
79 * collapse the token array
80 * if collapseTop is set, then statments is set to the array statements (which is an array of tokens)
81 * otherwise this.tokens is set..
83 collapse : function(ar) {
85 ar = ar || this.tokens ;
88 ar = this._collapse(ar);
90 if (this.collapseTop) {
91 //print(JSON.stringify(ar, null,4));
93 return this.toItems(ar, [ ';', '{'] );
100 * Add all the comments to the closed token.
102 * token.comments = [] (array of COMMENTS)
103 * token.comment = combined string
104 * token.jsdoc = last comment (as DocComment)
108 spaces : function (toks)
119 for (var i = 0; i < this.tokens.length; i ++) {
120 tok = this.tokens[i];
122 if (this.createJSDOC) {
126 if (tok.is("COMM") || tok.is("WHIT")) {
133 pref.forEach( function(e) {
137 if (e.name == "JSDOC") {
138 tok.comment = e.data;
139 if (_this.createJSDOC) {
140 tok.jsdoc = new imports.DocComment.DocComment(tok.comment);
141 _this.allJSDOC.push(tok.jsdoc);
144 // kludge for private..
145 if (e.is("COMM") && e.data.match(/\/\/\s+private/)) {
146 tok.comment = '/** @private */';
147 if (_this.createJSDOC) {
148 tok.jsdoc = new imports.DocComment.DocComment(tok.comment);
149 _this.allJSDOC.push(tok.jsdoc);
153 tok.prefix += e.data;
168 _collapse : function(ar, depth) {
171 var st = new TokenStream({ tokens : ar });
175 var tok = st.look(1,true);
177 if (!tok || !tok.is) {
178 // Seed.print(TokenStream.toString(ret));
181 // console.log(tok.data);
193 ret.push(st.next(1));
202 var start = st.cursor;
204 var add = st.balance(tok.data);
207 console.dump(start + '...' + st.cursor);
208 console.dump(st.tokens);
215 //Seed.print(JSON.stringify(add, null,4));
219 var toks = add ? this._collapse(add, depth+1) : [];
225 if (tok.data != '{') {
226 // paramters or array elements..
227 tok.items = this.toItems(toks, [',']);
229 tok.items.forEach(function(tar) {
230 if (tar[0].is('NAME')) {
231 tok.args.push(tar[0].data);
243 // check for types.. it could be a list of statements.. or object
245 var ost = new TokenStream({tokens : toks});
246 //console.dump(ost.look(2,true) );
247 if (ost.look(2,true) && ost.look(2,true).data == ":") {
248 tok.props = this.toProps(toks);
250 // list of statemetns..
251 tok.items = this.toItems(toks,[ ';', '{'] );
256 //Seed.print(" ADD : " + add.length + " ITEMS: " + tok.items.length);
263 ret.push(st.next(1));
269 Seed.print("OOPS" + tok.type);
284 toItems : function(ar,sep)
289 for (var i = 0; i < ar.length; i ++) {
290 if (sep.indexOf(ar[i].data) < 0) {
295 if ((ar[i].data != ';') && g.length && (g[0].name == "VAR")) {;
312 toProps : function(ar)
317 var g = { key : '', val: [] };
322 for (var i = 0; i < ar.length; i ++) {
331 state =2; // should be ':'
335 if (ar[i].data != ',') {
339 g = { key : '', val: [] }
345 // last.. - if g.val.length is 0 then it's a trailing ','...
346 // we should really throw a syntax error in that case..
347 if (k.length && g.val.length) {