JSDOC/TokenReader.vala
[gnome.introspection-doc-generator] / JSDOC / TokenReader.vala
index bbdc179..a60dccb 100644 (file)
@@ -41,6 +41,14 @@ namespace JSDOC {
         public void push (Token t) {
             this.tokens.add(t);
         }
+        public Token? pop ()
+        {
+            if (this.size > 0) {
+                return this.tokens.remove_at(this.size-1);
+            }
+            return null;
+        }
+        
         public Token get(int i) {
             return this.tokens.get(i);
         }
@@ -290,9 +298,7 @@ namespace JSDOC {
             }
             //print("WHITE = " + JSON.stringify(found));
             
-            // if we found a new line, then we could check if previous character was a ';' - if so we can drop it.
-            // otherwise generally keep it.. in which case it should reduce our issue with stripping new lines..
-            
+             
             if (this.collapseWhite) {
                 found = " "; // this might work better if it was a '\n' ???
             }
@@ -301,7 +307,7 @@ namespace JSDOC {
             }
             return true;
         
-        },
+        }
 
         /**
             @returns {Boolean} Was the token found?
@@ -309,7 +315,7 @@ namespace JSDOC {
         public bool read_newline  (TokenStream stream, TokenArray tokens)
             var found = "";
             var line = this.line;
-            while (!stream.look().eof && Lang.isNewline(stream.look())) {
+            while (!stream.lookEOF() && Lang.isNewline(stream.look())) {
                 this.line++;
                 found += stream.next();
             }
@@ -317,16 +323,22 @@ namespace JSDOC {
             if (found === "") {
                 return false;
             }
+            
+            // if we found a new line, then we could check if previous character was a ';' - if so we can drop it.
+            // otherwise generally keep it.. in which case it should reduce our issue with stripping new lines..
+           
+            
             //this.line++;
             if (this.collapseWhite) {
                 found = "\n";
             }
-             if (this.keepWhite) {
-                var last = tokens ? tokens.pop() : false;
-                if (last && last.name != "WHIT") {
+            
+            if (this.keepWhite) {
+                var last = tokens.pop();
+                if (last != null && last.name != "WHIT") {
                     tokens.push(last);
                 }
-                
+                // replaces last new line... 
                 tokens.push(new Token(found, "WHIT", "NEWLINE", line));
             }
             return true;