JSDOC/TokenReader.vala
authorAlan Knowles <alan@roojs.com>
Tue, 15 Sep 2015 09:08:46 +0000 (17:08 +0800)
committerAlan Knowles <alan@roojs.com>
Tue, 15 Sep 2015 09:08:46 +0000 (17:08 +0800)
JSDOC/TokenReader.vala

index ee88721..66034d1 100644 (file)
@@ -46,6 +46,10 @@ namespace JSDOC {
         }
     }
 
+    errordomain TokenReader_Error {
+            ArgumentError
+    }
+    
 
     public class TokenReader : Object
     {
@@ -188,8 +192,8 @@ namespace JSDOC {
             if (name != null) {
                 
                 // look for "()return" ?? why ???
-                
-                if (found == "return" && tokens.lastSym().data == ")") {
+                var ls = tokens.lastSym();
+                if (found == "return" && ls != null && ls.data == ")") {
                     //Seed.print('@' + tokens.length);
                     var n = this.findPuncToken(tokens, ")");
                     //Seed.print(')@' + n);
@@ -201,10 +205,9 @@ namespace JSDOC {
                     //print(JSON.stringify(lt));
                     if (lt.type != "KEYW" || ["IF", 'WHILE'].indexOf(lt.name) < -1) {
                         if (!this.ignoreBadGrammer) {
-                            throw {
-                                name : "ArgumentError", 
-                                message: "\n" + this.filename + ':' + this.line + " Error - return found after )"
-                            }
+                            throw new TokenReader_Error.ArgumentError(
+                                this.filename + ":" + this.line + " Error - return found after )"
+                            );
                         }
                     }
                     
@@ -215,20 +218,20 @@ namespace JSDOC {
                 tokens.push(new Token(found, "KEYW", name, this.line));
                 return true;
             }
+            
             if (!this.sepIdents || found.indexOf('.') < 0 ) {
                 tokens.push(new Token(found, "NAME", "NAME", this.line));
                 return true;
             }
             var n = found.split('.');
             var p = false;
-            var _this = this;
-            n.forEach(function(nm) {
+            foreach (unowned string nm in n) {
                 if (p) {
-                    tokens.push(new Token('.', "PUNC", "DOT", _this.line));
+                    tokens.push(new Token('.', "PUNC", "DOT", this.line));
                 }
                 p=true;
-                tokens.push(new Token(nm, "NAME", "NAME", _this.line));
-            });
+                tokens.push(new Token(nm, "NAME", "NAME", this.line));
+            }
             return true;
                 
 
@@ -237,10 +240,11 @@ namespace JSDOC {
         /**
             @returns {Boolean} Was the token found?
          */
-        read_punc : function(/**JSDOC.TokenStream*/stream, tokens) {
+        public bool read_punc (TokenStream stream, TokenArray tokens)
+        {
             var found = "";
             var name;
-            while (!stream.look().eof && Lang.punc(found+stream.look())) {
+            while (!stream.look().eof && Lang.punc(found + stream.look())) {
                 found += stream.next();
             }
             
@@ -249,7 +253,9 @@ namespace JSDOC {
                 return false;
             }
             
-            if ((found == '}' || found == ']') && tokens.lastSym().data == ',') {
+            var ls = tokens.lastSym();
+            
+            if ((found == "}" || found == "]") && ls != null && ls.data == ",") {
                 //print("Error - comma found before " + found);
                 //print(JSON.stringify(tokens.lastSym(), null,4));
                 if (this.ignoreBadGrammer) {