1 //<script type="text/javscript">
3 imports['Object.js'].load(Object);
5 JSDOC = imports['JSDOC.js'].JSDOC;
6 console = imports['console.js'].console;
7 Token = imports['JSDOC/Token.js'].Token;
8 Lang = imports['JSDOC/Lang.js'].Lang;
14 TokenStream = Object.define(
18 this.tokens = (tokens || []);
19 // Seed.print(this.tokens.length);
32 look : function(/**Number*/n, /**Boolean*/considerWhitespace) {
33 if (typeof n == "undefined") n = 0;
35 if (considerWhitespace == true) {
36 if (this.cursor+n < 0 || this.cursor+n > this.tokens.length) return {};
37 return this.tokens[this.cursor+n];
44 if (i < 0) return new Token("", "VOID", "START_OF_STREAM");
45 else if (i > this.tokens.length) return new Token("", "VOID", "END_OF_STREAM");
47 if (i != this.cursor && (this.tokens[i] === undefined || this.tokens[i].is("WHIT"))) {
48 if (n < 0) i--; else i++;
52 if (count == Math.abs(n)) {
53 return this.tokens[i];
59 return new Token("", "VOID", "STREAM_ERROR"); // because null isn't an object and caller always expects an object
63 lookFor : function (data)
66 var i = this.cursor < 0 ? 0 : this.cursor ;
69 if (i >= this.tokens.length) return -1;
70 if (this.tokens[i].data == data) {
76 // should not get here!
83 * look ahead (or back) x number of tokens (which are not comment or whitespace)
86 lookTok : function(/**Number*/n) {
87 if (typeof n == "undefined") n = 1;
94 if (i < 0) return false;
95 else if (i > this.tokens.length) return false;
97 if (i != this.cursor && (this.tokens[i] === undefined || this.tokens[i].is("WHIT") || this.tokens[i].is("COMM"))) {
98 if (n < 0) i--; else i++;
102 if (count == Math.abs(n)) {
103 return this.tokens[i];
109 return false; // because null isn't an object and caller always expects an object;
114 @type JSDOC.Token|JSDOC.Token[]| null!
116 next : function(/**Number*/howMany) {
117 if (typeof howMany == "undefined") howMany = 1;
118 if (howMany < 1) return null;
121 for (var i = 1; i <= howMany; i++) {
122 if (this.cursor+i >= this.tokens.length) {
125 got.push(this.tokens[this.cursor+i]);
127 this.cursor += howMany;
134 // what about comments after 'function'...
137 nextNonSpace : function ()
145 if (tok.is('WHIT') || tok.is('COMM')) {
154 balance : function(/**String*/start, /**String*/stop) {
155 if (!stop) stop = Lang.matching(start);
160 //Seed.print("STOP:" + stop);
161 while ((token = this.look())) {
162 if (token.is(start)) {
171 if (token.is(stop)) {
173 if (depth == 0) return got;
175 if (!this.next()) break;
179 getMatchingToken : function(/**String*/start, /**String*/stop) {
181 var cursor = this.cursor;
184 start = Lang.matching(stop);
187 if (!stop) stop = Lang.matching(start);
189 while ((token = this.tokens[cursor])) {
190 if (token.is(start)) {
194 if (token.is(stop) && cursor) {
196 if (depth == 0) return this.tokens[cursor];
202 insertAhead : function(/**JSDOC.Token*/token) {
203 this.tokens.splice(this.cursor+1, 0, token);
206 remaining : function() {
209 var tok = this.look(1,true);
210 if (!tok || !tok.is || tok.is('VOID')) {
213 ret.push(this.next(1));
218 arrayToString : function(ar) {
219 console.log(typeof(ar));
221 Roo.each(ar, function(e) {