1eeb44cbb4f331a592fe9f2e544af6fb92da9386
1 if (typeof JSDOC
== "undefined") JSDOC
= {};
6 JSDOC
.TokenStream
= function(tokens
) {
7 this.tokens
= (tokens
|| []);
15 function VoidToken(/**String*/type
) {
16 this.toString
= function() {return "<VOID type=\""+type
+"\">"};
17 this.is
= function(){return false;}
20 JSDOC
.TokenStream
.prototype.rewind
= function() {
27 JSDOC
.TokenStream
.prototype.look
= function(/**Number*/n
, /**Boolean*/considerWhitespace
) {
28 if (typeof n
== "undefined") n
= 0;
30 if (considerWhitespace
== true) {
31 if (this.cursor
+n
< 0 || this.cursor
+n
> this.tokens
.length
) return {};
32 return this.tokens
[this.cursor
+n
];
39 if (i
< 0) return new JSDOC
.Token("", "VOID", "START_OF_STREAM");
40 else if (i
> this.tokens
.length
) return new JSDOC
.Token("", "VOID", "END_OF_STREAM");
42 if (i
!= this.cursor
&& (this.tokens
[i
] === undefined
|| this.tokens
[i
].is("WHIT"))) {
43 if (n
< 0) i
--; else i
++;
47 if (count
== Math
.abs(n
)) {
48 return this.tokens
[i
];
54 return new JSDOC
.Token("", "VOID", "STREAM_ERROR"); // because null isn't an object and caller always expects an object
59 @type JSDOC.Token|JSDOC.Token[]
61 JSDOC
.TokenStream
.prototype.next
= function(/**Number*/howMany
) {
62 if (typeof howMany
== "undefined") howMany
= 1;
63 if (howMany
< 1) return null;
66 for (var i
= 1; i
<= howMany
; i
++) {
67 if (this.cursor
+i
>= this.tokens
.length
) {
70 got
.push(this.tokens
[this.cursor
+i
]);
72 this.cursor
+= howMany
;
83 JSDOC
.TokenStream
.prototype.balance
= function(/**String*/start
, /**String*/stop
) {
84 if (!stop
) stop
= JSDOC
.Lang
.matching(start
);
90 while ((token
= this.look())) {
91 if (token
.is(start
)) {
100 if (token
.is(stop
)) {
102 if (depth
== 0) return got
;
104 if (!this.next()) break;
108 JSDOC
.TokenStream
.prototype.getMatchingToken
= function(/**String*/start
, /**String*/stop
) {
110 var cursor
= this.cursor
;
113 start
= JSDOC
.Lang
.matching(stop
);
116 if (!stop
) stop
= JSDOC
.Lang
.matching(start
);
118 while ((token
= this.tokens
[cursor
])) {
119 if (token
.is(start
)) {
123 if (token
.is(stop
) && cursor
) {
125 if (depth
== 0) return this.tokens
[cursor
];
131 JSDOC
.TokenStream
.prototype.insertAhead
= function(/**JSDOC.Token*/token
) {
132 this.tokens
.splice(this.cursor
+1, 0, token
);