JSDOC/TokenReader.js
[gnome.introspection-doc-generator] / JSDOC / TokenStream.js
index cc52651..a660873 100644 (file)
@@ -1,19 +1,34 @@
 //<script type="text/javscript">
 
 
-XObject = imports.XObject.XObject;
+const XObject = imports.XObject.XObject;
  
 
 
-console = imports.console.console;
-Token   = imports.Token.Token;
-Lang    = imports.Lange.Lang;
+const console = imports.console.console;
+const Token   = imports.Token.Token;
+const Lang    = imports.Lang.Lang;
+
 
 /**
-       @constructor
-*/
+ * @class TokenStream
+ * 
+ * BC notes:
+ * 
+ * nextT => nextTok
+ * lookT => lookTok
+ * 
+ */
+       
  
-TokenStream = XObject.define(
+const TokenStream = XObject.define(
+
+    /**
+     * @constructor
+     * 
+     * 
+     */
+
     function(tokens) {
      
         
@@ -99,7 +114,10 @@ TokenStream = XObject.define(
                // print(i);
                 if (i < 0) {
                     if (n > -1) {
-                        i = 0; continue;
+                        i = 0; 
+                        count++;
+                        continue;
+                        
                     }
                     return   new Token("", "VOID", "END_OF_STREAM");
                 }
@@ -122,8 +140,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 +189,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,10 +212,12 @@ 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;
             }
+            return false;
         },
 
         getMatchingToken : function(/**String*/start, /**String*/stop) {
@@ -215,6 +241,7 @@ TokenStream = XObject.define(
                 }
                 cursor++;
             }
+            return false;
         },
 
         insertAhead : function(/**JSDOC.Token*/token) {
@@ -241,11 +268,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
+