Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Retooled scanToken() method
private void scanToken(char character) {
if (singleCharacterToken(character) != null) {
addToken(singleCharacterToken(character));
return;
}
if (isComparisonOperator(character)) {
addComparisonOperatorTokenFor(character);
return;
}
if (character == '/') {
if (!isAComment()) {
addToken(SLASH);
}
return;
}
switch (character) {
case ' ': //God, I hate this about Java
case '\r':
case '\t':
// Ignore whitespace.
return;
case '\n':
line++;
return;
}
if (character == '"') {
addStringToken();
return;
}
if (isDigit(character)) {
addNumberToken();
return;
}
if (isAlpha(character)) {
addIdentifierToken();
return;
}
Lox.error(line, "Unexpected character.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment