Skip to content

Commit a092989

Browse files
committed
PR feedback to clarify code
1 parent fb61d69 commit a092989

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

libraries/rushell/src/Tokenizer.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class Tokenizer {
199199

200200
// Is it the "&&" token?
201201
if (firstChar === '&') {
202-
if (this._peek2() === '&') {
202+
if (this._peekTwice() === '&') {
203203
this._get();
204204
this._get();
205205
return new Token(TokenKind.AndIf, input.getNewRange(startIndex, this._currentIndex));
@@ -221,21 +221,33 @@ export class Tokenizer {
221221
return tokens;
222222
}
223223

224+
/**
225+
* Retrieve the next character in the input stream.
226+
* @returns a string of length 1, or undefined if the end of input is reached
227+
*/
224228
private _get(): string | undefined {
225229
if (this._currentIndex >= this.input.end) {
226230
return undefined;
227231
}
228232
return this.input.buffer[this._currentIndex++];
229233
}
230234

235+
/**
236+
* Return the next character in the input stream, but don't advance the stream pointer.
237+
* @returns a string of length 1, or undefined if the end of input is reached
238+
*/
231239
private _peek(): string | undefined {
232240
if (this._currentIndex >= this.input.end) {
233241
return undefined;
234242
}
235243
return this.input.buffer[this._currentIndex];
236244
}
237245

238-
private _peek2(): string | undefined {
246+
/**
247+
* Return the character after the next character in the input stream, but don't advance the stream pointer.
248+
* @returns a string of length 1, or undefined if the end of input is reached
249+
*/
250+
private _peekTwice(): string | undefined {
239251
if (this._currentIndex + 1 >= this.input.end) {
240252
return undefined;
241253
}

libraries/rushell/src/test/Tokenizer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ function tokenize(input: string): Token[] {
1818
function matchSnapshot(input: string): void {
1919
const tokenizer: Tokenizer = new Tokenizer(input);
2020

21-
const reportedTokens = tokenizer.getTokens().map(
21+
const reportedTokens: { kind: string, value: string }[] = tokenizer.getTokens().map(
2222
token => {
2323
return {
2424
kind: TokenKind[token.kind],
2525
value: escape(token.toString())
26-
}
26+
};
2727
}
2828
);
2929

0 commit comments

Comments
 (0)