This commit is contained in:
Gašper Dobrovoljc
2025-03-08 19:36:20 +01:00
parent 56facf7372
commit 5ed3016bfd
3 changed files with 35 additions and 7 deletions

View File

@@ -240,13 +240,14 @@ public class LexAn implements AutoCloseable {
return;
case '/':
start = currentLocation();
nextChar();
if (buffChar != '/') {
buffToken = new Token(currentLocation(), Token.Symbol.DIV, null);
buffToken = new Token(start, Token.Symbol.DIV, null);
return;
}
while (buffChar != '\n') {
while (buffChar != '\n' && buffChar != -1) {
nextChar();
}
@@ -399,10 +400,24 @@ public class LexAn implements AutoCloseable {
nextChar();
while (buffChar != '"') {
if (buffChar == -1) {
if (buffChar == '\n' || buffChar == -1) {
throw new Report.Error(currentLocation(), "Unterminated string.");
}
if (!isChar()) {
if (buffChar == '\\') {
lexeme.append((char) buffChar);
nextChar();
if (buffChar == 'n' || buffChar == '\\' || buffChar == '"') {
} else if (isHex()) {
nextChar();
lexeme.append((char) buffChar);
if (!isHex()) {
throw new Report.Error(currentLocation(), "Invalid ascii code '" + (char) buffChar + "'.");
}
} else {
throw new Report.Error(currentLocation(), "Invalid escaped character '" + (char) buffChar + "'.");
}
} else if (!isChar()) {
throw new Report.Error(currentLocation(), "Invalid character '" + (char) buffChar + "'.");
}