validateToken(type: TOKEN_TYPES, symbol: string, shouldMatch: boolean) {
let isTrue = false;
if (shouldMatch) {
if (
this.tokenizer.getCurrentToken() === symbol &&
this.tokenizer.tokenType() === type
) {
isTrue = true;
}
} else {
if (
this.tokenizer.tokenType() !== type ||
this.tokenizer.getCurrentToken() !== symbol
) {
isTrue = true;
}
}
return isTrue;
}
By combining the functionality of the assertToken and assertNotToken methods into a single function called validateToken, we have achieved code consolidation and reusability.