X-Git-Url: http://git.roojs.org/?p=gnome.introspection-doc-generator;a=blobdiff_plain;f=JSDOC%2FTokenStream.js;fp=JSDOC%2FTokenStream.js;h=b5385a696b5318cb4068c43e3d2d1ad06eade6e1;hp=cc3f6af92bc78b72bcd1bfaf8d074811f12b3ccd;hb=8b882e6abb3281639eea6cb3850054af2550f6ce;hpb=82b17ee1cb07377fb1a2ceac634ad0c3757180a6 diff --git a/JSDOC/TokenStream.js b/JSDOC/TokenStream.js index cc3f6af..b5385a6 100644 --- a/JSDOC/TokenStream.js +++ b/JSDOC/TokenStream.js @@ -21,6 +21,7 @@ TokenStream = Object.define( }, Object, { + cursor : -1, // where are we in the stream. rewind : function() { this.cursor = -1; @@ -33,7 +34,9 @@ TokenStream = Object.define( if (typeof n == "undefined") n = 0; if (considerWhitespace == true) { - if (this.cursor+n < 0 || this.cursor+n > this.tokens.length) return {}; + if (this.cursor+n < 0 || this.cursor+n > (this.tokens.length -1)) { + return new Token("", "VOID", "START_OF_STREAM"); + } return this.tokens[this.cursor+n]; } else { @@ -91,8 +94,14 @@ TokenStream = Object.define( var i = this.cursor; while (true) { - if (i < 0) return false; - else if (i > this.tokens.length) return false; + // print(i); + if (i < 0) { + if (n > -1) { + i = 0; continue; + } + return new Token("", "VOID", "END_OF_STREAM"); + } + else if (i > this.tokens.length) return new Token("", "VOID", "END_OF_STREAM"); if (i != this.cursor && (this.tokens[i] === undefined || this.tokens[i].is("WHIT") || this.tokens[i].is("COMM"))) { if (n < 0) i--; else i++; @@ -105,7 +114,7 @@ TokenStream = Object.define( count++; (n < 0)? i-- : i++; } - + // should never get here.. return false; // because null isn't an object and caller always expects an object; }, @@ -133,7 +142,9 @@ TokenStream = Object.define( }, // what about comments after 'function'... // is this used ??? - + nextTok : function() { + return this.nextNonSpace(); + }, nextNonSpace : function () { @@ -149,9 +160,14 @@ TokenStream = Object.define( } }, /** - @type JSDOC.Token[] - */ + * @type JSDOC.Token[] + * @param start {String} token name or data (eg. '{' + * @param stop {String} (Optional) token name or data (eg. '}' + */ balance : function(/**String*/start, /**String*/stop) { + + start = typeof(Lang.matching(start)) == 'undefined' ? Lang.punc(start) : start; + if (!stop) stop = Lang.matching(start); var depth = 0; @@ -218,10 +234,16 @@ TokenStream = Object.define( arrayToString : function(ar) { console.log(typeof(ar)); var ret = []; - Roo.each(ar, function(e) { + ar.forEach(function(e) { ret.push(e.data); }) return ret.join(''); + }, + dump: function() + { + this.tokens.forEach(function(t) { + print(t.toString()); + }); } }); \ No newline at end of file