// make sure parent is loaded..
TokenStream = imports.TokenStream.TokenStream;
-
-/**
- * @namespace JSDOC
- */
-
+
/**
+ * @scope JSDOC
* @class Collapse
+ * @extends JSDOC.TokenStream
* base class for parsing segments of token array..
*
*
( ) - collapse into first element.
[ ] - collapse into first element.
* c) items = , seperation within the above..
- *
- * usage: x = new Collapse(token_array)
+ * d) props = for { xx: ... , yy: ....}
*
*
+ * usage:
+ * x = new Collapse({
+ * srcFile : ....
+ * })
+ * x.collapse();
*
*
+ * @param {Object} array tokens
+
*/
Collapse = XObject.define(
- function (ar, srcFile)
+
+ function (cfg)
{
-
- Collapse.superclass.constructor.call(this, ar, srcFile);
+ Collapse.superclass.constructor.call(this, cfg);
- this.spaces();
- this.tokens = this.collapse(this.tokens);
+ this.allJSDOC = [];
// console.dump(ar);
},
TokenStream,
{
-
- spaces : function () {
+
+ /**
+ * @cfg {Boolean} collapseTop make statements array of top level tokens.
+ */
+ collapseTop : false,
+
+ /**
+ * @type {Array} top level statements
+ */
+ statements : false,
+
+ /**
+ * @cfg {Boolean} createJSDOC create .jsdoc properties on tokens.
+ */
+ createJSDOC : false,
+
+ /**
+ * @type {Array} allJSDOC if createJSDOC is set, then all the files JSDOC comments
+ * are stored here, in theory to verify that all have been used up..
+ */
+ allJSDOC : false,
+
+ /**
+ * collapse the token array
+ * if collapseTop is set, then statments is set to the array statements (which is an array of tokens)
+ * otherwise this.tokens is set..
+ */
+ collapse : function(ar) {
+
+ ar = ar || this.tokens ;
+ this.rewind();
+ ar = this.spaces(ar);
+ ar = this._collapse(ar);
+
+ if (this.collapseTop) {
+ //print(JSON.stringify(ar, null,4));
+
+ return this.toItems(ar, [ ';', '{'] );
+
+ }
+ return ar;
+ },
+
+ /**
+ * Add all the comments to the closed token.
+ * adds :
+ * token.comments = [] (array of COMMENTS)
+ * token.comment = combined string
+ * token.jsdoc = last comment (as DocComment)
+ *
+ *
+ */
+ spaces : function (toks)
+ {
+ this.tokens = toks;
+ this.rewind();
var ar = [];
var pref = [];
var tok;
+ var jsdoc;
+ var _this = this;
for (var i = 0; i < this.tokens.length; i ++) {
tok = this.tokens[i];
+
+ if (this.createJSDOC) {
+ tok.jsdoc = false;
+ }
+
if (tok.is("COMM") || tok.is("WHIT")) {
pref.push(tok);
continue;
}
tok.prefix = '';
if (pref.length) {
+ tok.comments = [];
pref.forEach( function(e) {
if (!e) {
return;
}
+ if (e.name == "JSDOC") {
+ tok.comment = e.data;
+ if (_this.createJSDOC) {
+ tok.jsdoc = new imports.DocComment.DocComment(tok.comment);
+ _this.allJSDOC.push(tok.jsdoc);
+ }
+ }
+ // kludge for private..
+ if (e.is("COMM") && e.data.match(/\/\/\s+private/)) {
+ tok.comment = '/** @private */';
+ if (_this.createJSDOC) {
+ tok.jsdoc = new imports.DocComment.DocComment(tok.comment);
+ _this.allJSDOC.push(tok.jsdoc);
+ }
+ }
tok.prefix += e.data;
- if (e.is("COMM")) {
- tok.comment = e;
- }
})
}
pref= [];
}
- this.tokens = ar;
+ return ar;
},
- collapse : function(ar) {
+
+
+
+ _collapse : function(ar, depth) {
- var st = new TokenStream(ar);
+ depth = depth || 0;
+ var st = new TokenStream({ tokens : ar });
var ret = [];
while (true) {
var tok = st.look(1,true);
+ tok.depth = depth;
if (!tok || !tok.is) {
// Seed.print(TokenStream.toString(ret));
return ret;
- var toks = add ? this.collapse(add) : [];
+ var toks = add ? this._collapse(add, depth+1) : [];
tok.items = false;
tok.props = false;
if (tok.data != '{') {
// paramters or array elements..
tok.items = this.toItems(toks, [',']);
- } else {
- // check for types.. it could be a list of statements.. or object
+ tok.args = [];
+ tok.items.forEach(function(tar) {
+ if (tar[0].is('NAME')) {
+ tok.args.push(tar[0].data);
+ }
+ });
+
+
+
+ ret.push(tok);
- var ost = new TokenStream(toks);
- //console.dump(ost.look(2,true) );
- if (ost.look(2,true) && ost.look(2,true).data == ":") {
- tok.props = this.toProps(toks);
- } else {
- // list of statemetns..
- tok.items = this.toItems(toks,[ ';', '{'] );;
- }
+ continue;
+ }
+ // check for types.. it could be a list of statements.. or object
+
+ var ost = new TokenStream({tokens : toks});
+ //console.dump(ost.look(2,true) );
+ if (ost.look(2,true) && ost.look(2,true).data == ":") {
+ tok.props = this.toProps(toks);
+ } else {
+ // list of statemetns..
+ tok.items = this.toItems(toks,[ ';', '{'] );
}
-
+
+
+
//Seed.print(" ADD : " + add.length + " ITEMS: " + tok.items.length);
ret.push(tok);
continue;
}
}
+
+
+
+
+
+
+
+
+
},
toItems : function(ar,sep)
toProps : function(ar)
{
- var ret = { }
+ var ret = { };
- var g = { key : '', keytok : false, val: [] }
+ var g = { key : '', val: [] };
var k = '';
case 0:
k = ar[i].data;
g.key = ar[i];
- g.keytok = ar[i];
state = 1;
continue;
-
case 1:
state =2; // should be ':'
continue;
-
case 2:
g.val.push(ar[i]);
if (ar[i].data != ',') {