1 Commits

Author SHA1 Message Date
Gašper Dobrovoljc
b325647ad9 Limited comment length to 10 characters 2025-06-03 22:20:10 +02:00
3 changed files with 9 additions and 19 deletions

View File

@@ -1,4 +1,2 @@
fun putint(n)
fun main() =
putint(__LINE__)
//1234567890
//12345678901

View File

@@ -148,11 +148,7 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
/**
* Simbol {@code )}.
*/
RPAREN,
/**
* Simbol {@code __LINE__}.
*/
LINE
RPAREN;
}
@Override

View File

@@ -246,8 +246,14 @@ public class LexAn implements AutoCloseable {
buffToken = new Token(start, Token.Symbol.DIV, "/");
return;
}
nextChar();
int length = 0;
while (buffChar != '\n' && buffChar != -1) {
length++;
if (length > 10) {
throw new Report.Error(currentLocation(), "Comments can only be 10 characters long");
}
nextChar();
}
@@ -319,7 +325,6 @@ public class LexAn implements AutoCloseable {
case "let" -> Token.Symbol.LET;
case "in" -> Token.Symbol.IN;
case "end" -> Token.Symbol.END;
case "__LINE__" -> Token.Symbol.LINE;
default -> null;
};
}
@@ -452,15 +457,6 @@ public class LexAn implements AutoCloseable {
symbol = Token.Symbol.IDENTIFIER;
}
if (symbol == Token.Symbol.LINE) {
buffToken = new Token(
new Report.Location(startLocation, endLocation),
Token.Symbol.INTCONST,
Integer.toString(startLocation.begLine())
);
return;
}
buffToken = new Token(
new Report.Location(startLocation, endLocation),
symbol,