Skip to content

Commit d95dca6

Browse files
committed
Fix spacing in TokenStreamBase.js
1 parent c6ce1e8 commit d95dca6

File tree

1 file changed

+69
-69
lines changed

1 file changed

+69
-69
lines changed

src/util/TokenStreamBase.js

+69-69
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @class TokenStreamBase
66
* @namespace parserlib.util
77
* @constructor
8-
* @param {String|StringReader} input The text to tokenize or a reader from
8+
* @param {String|StringReader} input The text to tokenize or a reader from
99
* which to read the input.
1010
*/
1111
function TokenStreamBase(input, tokenData){
@@ -17,39 +17,39 @@ function TokenStreamBase(input, tokenData){
1717
* @private
1818
*/
1919
this._reader = input ? new StringReader(input.toString()) : null;
20-
20+
2121
/**
2222
* Token object for the last consumed token.
2323
* @type Token
2424
* @property _token
2525
* @private
2626
*/
27-
this._token = null;
28-
27+
this._token = null;
28+
2929
/**
3030
* The array of token information.
3131
* @type Array
3232
* @property _tokenData
3333
* @private
3434
*/
3535
this._tokenData = tokenData;
36-
36+
3737
/**
3838
* Lookahead token buffer.
3939
* @type Array
4040
* @property _lt
4141
* @private
4242
*/
4343
this._lt = [];
44-
44+
4545
/**
4646
* Lookahead token buffer index.
4747
* @type int
4848
* @property _ltIndex
4949
* @private
5050
*/
5151
this._ltIndex = 0;
52-
52+
5353
this._ltIndexCache = [];
5454
}
5555

@@ -69,7 +69,7 @@ TokenStreamBase.createTokenData = function(tokens){
6969
tokenData = tokens.concat([]),
7070
i = 0,
7171
len = tokenData.length+1;
72-
72+
7373
tokenData.UNKNOWN = -1;
7474
tokenData.unshift({name:"EOF"});
7575

@@ -80,27 +80,27 @@ TokenStreamBase.createTokenData = function(tokens){
8080
typeMap[tokenData[i].text] = i;
8181
}
8282
}
83-
83+
8484
tokenData.name = function(tt){
8585
return nameMap[tt];
8686
};
87-
87+
8888
tokenData.type = function(c){
8989
return typeMap[c];
9090
};
91-
91+
9292
return tokenData;
9393
};
9494

9595
TokenStreamBase.prototype = {
9696

9797
//restore constructor
98-
constructor: TokenStreamBase,
99-
98+
constructor: TokenStreamBase,
99+
100100
//-------------------------------------------------------------------------
101101
// Matching methods
102102
//-------------------------------------------------------------------------
103-
103+
104104
/**
105105
* Determines if the next token matches the given token type.
106106
* If so, that token is consumed; if not, the token is placed
@@ -116,27 +116,27 @@ TokenStreamBase.prototype = {
116116
* @method match
117117
*/
118118
match: function(tokenTypes, channel){
119-
119+
120120
//always convert to an array, makes things easier
121121
if (!(tokenTypes instanceof Array)){
122122
tokenTypes = [tokenTypes];
123123
}
124-
124+
125125
var tt = this.get(channel),
126126
i = 0,
127127
len = tokenTypes.length;
128-
128+
129129
while(i < len){
130130
if (tt == tokenTypes[i++]){
131131
return true;
132132
}
133133
}
134-
134+
135135
//no match found, put the token back
136136
this.unget();
137137
return false;
138-
},
139-
138+
},
139+
140140
/**
141141
* Determines if the next token matches the given token type.
142142
* If so, that token is consumed; if not, an error is thrown.
@@ -147,7 +147,7 @@ TokenStreamBase.prototype = {
147147
* provided, reads from the default (unnamed) channel.
148148
* @return {void}
149149
* @method mustMatch
150-
*/
150+
*/
151151
mustMatch: function(tokenTypes, channel){
152152

153153
var token;
@@ -157,17 +157,17 @@ TokenStreamBase.prototype = {
157157
tokenTypes = [tokenTypes];
158158
}
159159

160-
if (!this.match.apply(this, arguments)){
160+
if (!this.match.apply(this, arguments)){
161161
token = this.LT(1);
162-
throw new SyntaxError("Expected " + this._tokenData[tokenTypes[0]].name +
162+
throw new SyntaxError("Expected " + this._tokenData[tokenTypes[0]].name +
163163
" at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
164164
}
165165
},
166-
166+
167167
//-------------------------------------------------------------------------
168168
// Consuming methods
169169
//-------------------------------------------------------------------------
170-
170+
171171
/**
172172
* Keeps reading from the token stream until either one of the specified
173173
* token types is found or until the end of the input is reached.
@@ -180,21 +180,21 @@ TokenStreamBase.prototype = {
180180
* @method advance
181181
*/
182182
advance: function(tokenTypes, channel){
183-
183+
184184
while(this.LA(0) !== 0 && !this.match(tokenTypes, channel)){
185185
this.get();
186186
}
187187

188-
return this.LA(0);
188+
return this.LA(0);
189189
},
190-
190+
191191
/**
192-
* Consumes the next token from the token stream.
192+
* Consumes the next token from the token stream.
193193
* @return {int} The token type of the token that was just consumed.
194194
* @method get
195-
*/
195+
*/
196196
get: function(channel){
197-
197+
198198
var tokenInfo = this._tokenData,
199199
reader = this._reader,
200200
value,
@@ -203,76 +203,76 @@ TokenStreamBase.prototype = {
203203
found = false,
204204
token,
205205
info;
206-
206+
207207
//check the lookahead buffer first
208-
if (this._lt.length && this._ltIndex >= 0 && this._ltIndex < this._lt.length){
209-
208+
if (this._lt.length && this._ltIndex >= 0 && this._ltIndex < this._lt.length){
209+
210210
i++;
211211
this._token = this._lt[this._ltIndex++];
212212
info = tokenInfo[this._token.type];
213-
213+
214214
//obey channels logic
215215
while((info.channel !== undefined && channel !== info.channel) &&
216216
this._ltIndex < this._lt.length){
217217
this._token = this._lt[this._ltIndex++];
218218
info = tokenInfo[this._token.type];
219219
i++;
220220
}
221-
221+
222222
//here be dragons
223223
if ((info.channel === undefined || channel === info.channel) &&
224224
this._ltIndex <= this._lt.length){
225225
this._ltIndexCache.push(i);
226226
return this._token.type;
227227
}
228228
}
229-
229+
230230
//call token retriever method
231231
token = this._getToken();
232232

233233
//if it should be hidden, don't save a token
234234
if (token.type > -1 && !tokenInfo[token.type].hide){
235-
235+
236236
//apply token channel
237237
token.channel = tokenInfo[token.type].channel;
238-
238+
239239
//save for later
240240
this._token = token;
241241
this._lt.push(token);
242242

243243
//save space that will be moved (must be done before array is truncated)
244-
this._ltIndexCache.push(this._lt.length - this._ltIndex + i);
245-
244+
this._ltIndexCache.push(this._lt.length - this._ltIndex + i);
245+
246246
//keep the buffer under 5 items
247247
if (this._lt.length > 5){
248-
this._lt.shift();
248+
this._lt.shift();
249249
}
250-
250+
251251
//also keep the shift buffer under 5 items
252252
if (this._ltIndexCache.length > 5){
253253
this._ltIndexCache.shift();
254254
}
255-
255+
256256
//update lookahead index
257257
this._ltIndex = this._lt.length;
258258
}
259-
259+
260260
/*
261261
* Skip to the next token if:
262262
* 1. The token type is marked as hidden.
263263
* 2. The token type has a channel specified and it isn't the current channel.
264264
*/
265265
info = tokenInfo[token.type];
266-
if (info &&
267-
(info.hide ||
266+
if (info &&
267+
(info.hide ||
268268
(info.channel !== undefined && channel !== info.channel))){
269269
return this.get(channel);
270270
} else {
271271
//return just the type
272272
return token.type;
273273
}
274274
},
275-
275+
276276
/**
277277
* Looks ahead a certain number of tokens and returns the token type at
278278
* that position. This will throw an error if you lookahead past the
@@ -291,34 +291,34 @@ TokenStreamBase.prototype = {
291291
if (index > 5){
292292
throw new Error("Too much lookahead.");
293293
}
294-
294+
295295
//get all those tokens
296296
while(total){
297-
tt = this.get();
298-
total--;
297+
tt = this.get();
298+
total--;
299299
}
300-
300+
301301
//unget all those tokens
302302
while(total < index){
303303
this.unget();
304304
total++;
305305
}
306306
} else if (index < 0){
307-
307+
308308
if(this._lt[this._ltIndex+index]){
309309
tt = this._lt[this._ltIndex+index].type;
310310
} else {
311311
throw new Error("Too much lookbehind.");
312312
}
313-
313+
314314
} else {
315315
tt = this._token.type;
316316
}
317-
317+
318318
return tt;
319-
319+
320320
},
321-
321+
322322
/**
323323
* Looks ahead a certain number of tokens and returns the token at
324324
* that position. This will throw an error if you lookahead past the
@@ -328,26 +328,26 @@ TokenStreamBase.prototype = {
328328
* current token, 1 for the next, -1 for the previous, etc.
329329
* @return {Object} The token of the token in the given position.
330330
* @method LA
331-
*/
331+
*/
332332
LT: function(index){
333-
333+
334334
//lookahead first to prime the token buffer
335335
this.LA(index);
336-
336+
337337
//now find the token, subtract one because _ltIndex is already at the next index
338-
return this._lt[this._ltIndex+index-1];
338+
return this._lt[this._ltIndex+index-1];
339339
},
340-
340+
341341
/**
342-
* Returns the token type for the next token in the stream without
342+
* Returns the token type for the next token in the stream without
343343
* consuming it.
344344
* @return {int} The token type of the next token in the stream.
345345
* @method peek
346346
*/
347347
peek: function(){
348348
return this.LA(1);
349349
},
350-
350+
351351
/**
352352
* Returns the actual token object for the last consumed token.
353353
* @return {Token} The token object for the last consumed token.
@@ -356,7 +356,7 @@ TokenStreamBase.prototype = {
356356
token: function(){
357357
return this._token;
358358
},
359-
359+
360360
/**
361361
* Returns the name of the token for the given token type.
362362
* @param {int} tokenType The type of token to get the name of.
@@ -371,22 +371,22 @@ TokenStreamBase.prototype = {
371371
return this._tokenData[tokenType].name;
372372
}
373373
},
374-
374+
375375
/**
376376
* Returns the token type value for the given token name.
377377
* @param {String} tokenName The name of the token whose value should be returned.
378378
* @return {int} The token type value for the given token name or -1
379379
* for an unknown token.
380380
* @method tokenName
381-
*/
381+
*/
382382
tokenType: function(tokenName){
383383
return this._tokenData[tokenName] || -1;
384384
},
385-
385+
386386
/**
387387
* Returns the last consumed token to the token stream.
388388
* @method unget
389-
*/
389+
*/
390390
unget: function(){
391391
//if (this._ltIndex > -1){
392392
if (this._ltIndexCache.length){

0 commit comments

Comments
 (0)