X-Git-Url: http://git.roojs.org/?p=gnome.introspection-doc-generator;a=blobdiff_plain;f=JSDOC%2FTokenStream.js;h=7b3328f3eefe541c02d2d850d23810080890d27e;hp=cc526518c5f375a8ba552804e161549cc15d5ae0;hb=759466942f163998373b165f409fd9cfaaa9910f;hpb=85ea2c49f7e1a4250920fdd74db2f22126e9c5ae diff --git a/JSDOC/TokenStream.js b/JSDOC/TokenStream.js index cc52651..7b3328f 100644 --- a/JSDOC/TokenStream.js +++ b/JSDOC/TokenStream.js @@ -7,13 +7,28 @@ XObject = imports.XObject.XObject; console = imports.console.console; Token = imports.Token.Token; -Lang = imports.Lange.Lang; +Lang = imports.Lang.Lang; + /** - @constructor -*/ + * @class TokenStream + * + * BC notes: + * + * nextT => nextTok + * lookT => lookTok + * + */ + TokenStream = XObject.define( + + /** + * @constructor + * + * + */ + function(tokens) { @@ -122,8 +137,11 @@ TokenStream = XObject.define( }, /** - @type JSDOC.Token|JSDOC.Token[]| null! - */ + * @return {Token|null} + * next token (with white space) + */ + + next : function(/**Number*/howMany) { if (typeof howMany == "undefined") howMany = 1; if (howMany < 1) return null; @@ -168,16 +186,19 @@ TokenStream = XObject.define( */ balance : function(/**String*/start, /**String*/stop) { - start = typeof(Lang.matching(start)) == 'undefined' ? Lang.punc(start) : start; + + start = typeof(Lang.punc(start)) == 'undefined' ? start : Lang.punc(start); if (!stop) stop = Lang.matching(start); var depth = 0; var got = []; var started = false; + //Seed.print("START:" + start); //Seed.print("STOP:" + stop); while ((token = this.look())) { if (token.is(start)) { + // Seed.print("balance: START : " + depth + " " + token.data); depth++; started = true; } @@ -188,7 +209,8 @@ TokenStream = XObject.define( if (token.is(stop)) { depth--; - if (depth == 0) return got; + // Seed.print("balance: STOP: " + depth + " " + token.data); + if (depth < 1) return got; } if (!this.next()) break; } @@ -241,11 +263,16 @@ TokenStream = XObject.define( }) return ret.join(''); }, - dump: function() + dump: function(start, end) { - this.tokens.forEach(function(t) { - print(t.toString()); - }); + start = Math.max(start || 0, 0); + end = Math.min(end || this.tokens.length, this.tokens.length); + var out=''; + for (var i =start;i < end; i++) { + + out += (this.tokens[i].outData == false) ? this.tokens[i].data : this.tokens[i].outData; + }; + print(out); } }); \ No newline at end of file