- @type JSDOC.Token
- */
- look : function(/**Number*/n, /**Boolean*/considerWhitespace) {
- if (typeof n == "undefined") n = 0;
-
- if (considerWhitespace == true) {
- if (this.cursor+n < 0 || this.cursor+n > this.tokens.length) return {};
- return this.tokens[this.cursor+n];
- }
- else {
+ * @constructor
+ *
+ *
+ */
+
+ function(tokens) {
+
+
+ this.tokens = (tokens || []);
+ // Seed.print(this.tokens.length);
+ this.rewind();
+ },
+ Object,
+ {
+ cursor : -1, // where are we in the stream.
+
+ rewind : function() {
+ this.cursor = -1;
+ },
+
+ /**
+ @type JSDOC.Token
+ */
+ look : function(/**Number*/n, /**Boolean*/considerWhitespace) {
+ if (typeof n == "undefined") n = 0;
+
+ if (considerWhitespace == true) {
+ 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 {
+ var count = 0;
+ var i = this.cursor;
+
+ while (true) {
+ if (i < 0) return new Token("", "VOID", "START_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"))) {
+ if (n < 0) i--; else i++;
+ continue;
+ }
+
+ if (count == Math.abs(n)) {
+ return this.tokens[i];
+ }
+ count++;
+ (n < 0)? i-- : i++;
+ }
+
+ return new Token("", "VOID", "STREAM_ERROR"); // because null isn't an object and caller always expects an object
+ }
+ },
+
+ lookFor : function (data)
+ {
+ // non tree version..
+ var i = this.cursor < 0 ? 0 : this.cursor ;
+
+ while (true) {
+ if (i >= this.tokens.length) return -1;
+ if (this.tokens[i].data == data) {
+ return i;
+ }
+ i++;
+
+ }
+ // should not get here!
+ return -1;
+
+ },
+
+
+ /**
+ * look ahead (or back) x number of tokens (which are not comment or whitespace)
+ * ?? used any more?
+ */
+ lookTok : function(/**Number*/n) {
+ if (typeof n == "undefined") n = 1;
+
+