JSDOC/TokenStream.vala
authorAlan Knowles <alan@roojs.com>
Wed, 30 Sep 2015 09:51:10 +0000 (17:51 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 30 Sep 2015 09:51:10 +0000 (17:51 +0800)
JSDOC/TokenStream.vala

index 829fc09..c7c97cd 100644 (file)
@@ -46,28 +46,33 @@ namespace JSDOC {
                            }
                            return this.tokens.get(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");
+                   var count = 0;
+                   var i = this.cursor;
 
-                               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++;
-                           }
+                   while (true) {
+                       if (i < 0) {
+                               return new Token("", "VOID", "START_OF_STREAM");
+                       }
+                       if (i > this.tokens.length) {
+                               return new Token("", "VOID", "END_OF_STREAM");
+                       }
 
-                           return new Token("", "VOID", "STREAM_ERROR"); // because null isn't an object and caller always expects an object
-                       }
+                       if (i != this.cursor && this.tokens.get(i).is("WHIT")) {
+                               i += (n < 0) ? -1 : 1;
+                           continue;
+                       }
+                       
+                       if (count == n) {
+                           return this.tokens.get(i);
+                       }
+                       count++;
+                       i += (n < 0) ? -1 : 1;
+                   }
+
+                   return new Token("", "VOID", "STREAM_ERROR"); // because null isn't an object and caller always expects an object
+                       
                    },
 
                    lookFor : function (data)