JSDOC/Walker2.js
[gnome.introspection-doc-generator] / JSDOC / TokenStream.js
index b5385a6..7b3328f 100644 (file)
@@ -1,17 +1,34 @@
 //<script type="text/javscript">
 
-imports['Object.js'].load(Object);
 
-JSDOC   = imports['JSDOC.js'].JSDOC;
-console = imports['console.js'].console;
-Token   = imports['JSDOC/Token.js'].Token;
-Lang    = imports['JSDOC/Lang.js'].Lang;
+XObject = imports.XObject.XObject;
+
+
+console = imports.console.console;
+Token   = imports.Token.Token;
+Lang    = imports.Lang.Lang;
+
 
 /**
-       @constructor
-*/
+ * @class TokenStream
+ * 
+ * BC notes:
+ * 
+ * nextT => nextTok
+ * lookT => lookTok
+ * 
+ */
+       
  
-TokenStream = Object.define(
+TokenStream = XObject.define(
+
+    /**
+     * @constructor
+     * 
+     * 
+     */
+
     function(tokens) {
      
         
@@ -120,8 +137,11 @@ TokenStream = Object.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;
@@ -166,16 +186,19 @@ TokenStream = Object.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;
                 }
@@ -186,7 +209,8 @@ TokenStream = Object.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;
             }
@@ -239,11 +263,16 @@ TokenStream = Object.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