JsTemplate/Template.js
[gnome.introspection-doc-generator] / JSDOC / TokenStream.js
index 763a74e..cc52651 100644 (file)
@@ -1,17 +1,19 @@
 //<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.Lange.Lang;
 
 /**
        @constructor
 */
  
-TokenStream = Object.define(
+TokenStream = XObject.define(
     function(tokens) {
      
         
@@ -34,7 +36,9 @@ TokenStream = Object.define(
             if (typeof n == "undefined") n = 0;
 
             if (considerWhitespace == true) {
-                if (this.cursor+n < 0 || this.cursor+n > this.tokens.length) return {};
+                if (this.cursor+n < 0 || this.cursor+n > (this.tokens.length -1)) {
+                    return new Token("", "VOID", "START_OF_STREAM");
+                }
                 return this.tokens[this.cursor+n];
             }
             else {
@@ -92,8 +96,14 @@ TokenStream = Object.define(
             var i = this.cursor;
 
             while (true) {
-                if (i < 0) return false;
-                else if (i > this.tokens.length) return false;
+               // print(i);
+                if (i < 0) {
+                    if (n > -1) {
+                        i = 0; continue;
+                    }
+                    return   new Token("", "VOID", "END_OF_STREAM");
+                }
+                else if (i > this.tokens.length) return  new Token("", "VOID", "END_OF_STREAM");
 
                 if (i != this.cursor && (this.tokens[i] === undefined || this.tokens[i].is("WHIT") || this.tokens[i].is("COMM"))) {
                     if (n < 0) i--; else i++;
@@ -106,7 +116,7 @@ TokenStream = Object.define(
                 count++;
                 (n < 0)? i-- : i++;
             }
-
+        // should never get here..
             return false; // because null isn't an object and caller always expects an object;
             
         },
@@ -134,7 +144,9 @@ TokenStream = Object.define(
         },
         // what about comments after 'function'...
         // is this used ???
-
+        nextTok  : function() {
+            return this.nextNonSpace();
+        },
         nextNonSpace : function ()
         {
             
@@ -224,10 +236,16 @@ TokenStream = Object.define(
         arrayToString : function(ar) {
             console.log(typeof(ar));
             var ret = [];
-            Roo.each(ar, function(e) {
+            ar.forEach(function(e) {
                 ret.push(e.data);
             })
             return ret.join('');
+        },
+        dump: function()
+        {
+            this.tokens.forEach(function(t) {
+                print(t.toString());
+            });
         }
 });
     
\ No newline at end of file