Skip to content

Commit

Permalink
fix(lexer): fix unexpected token error message, convert codepoint to …
Browse files Browse the repository at this point in the history
…char, add missing @Formatter things
  • Loading branch information
yusshu committed Nov 13, 2023
1 parent 33a4bc7 commit 4f07d21
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/team/unnamed/molang/lexer/MolangLexerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ public void close() throws IOException {
String word = builder.toString();
TokenKind kind;
switch (word.toLowerCase()) {
//@formatter:off
case "break": kind = TokenKind.BREAK; break;
case "continue": kind = TokenKind.CONTINUE; break;
case "return": kind = TokenKind.RETURN; break;
case "true": kind = TokenKind.TRUE; break;
case "false": kind = TokenKind.FALSE; break;
default: kind = TokenKind.IDENTIFIER; break;
//@formatter:on
}

return new Token(
Expand Down Expand Up @@ -245,6 +247,7 @@ public void close() throws IOException {
}
break;
}
//@formatter:off
case '/': tokenKind = TokenKind.SLASH; break;
case '*': tokenKind = TokenKind.STAR; break;
case '+': tokenKind = TokenKind.PLUS; break;
Expand All @@ -258,10 +261,11 @@ public void close() throws IOException {
case '[': tokenKind = TokenKind.LBRACKET; break;
case ']': tokenKind = TokenKind.RBRACKET; break;
case ';': tokenKind = TokenKind.SEMICOLON; break;
//@formatter:on
default: {
// "c" is something we don't know about!
tokenKind = TokenKind.ERROR;
value = "Unexpected token '" + c + "': invalid token";
value = "Unexpected token '" + ((char) c) + "': invalid token";
break;
}
}
Expand Down

0 comments on commit 4f07d21

Please sign in to comment.