single line comments.

This commit is contained in:
Manuel Friedli 2024-03-24 04:44:47 +01:00
parent 3235cbab7b
commit ceb0d5aaba
Signed by: manuel
GPG Key ID: 41D08ABA75634DA1
2 changed files with 18 additions and 2 deletions

View File

@ -50,7 +50,12 @@ public class Lexer {
} else if (c == '*') {
this.handleSimple(TokenType.MULT, line, column);
} else if (c == '/') {
this.handleSimple(TokenType.DIV, line, column);
if (this.content.peekNext().exists(n -> n == '/')) {
this.content.next();
this.handleLineComment();
} else {
this.handleSimple(TokenType.DIV, line, column);
}
} else if (c == '%') {
this.handleSimple(TokenType.MOD, line, column);
} else if (c == '^') {
@ -107,6 +112,15 @@ public class Lexer {
this.appendToken(new Token(tokenType, line, column));
}
private void handleLineComment() {
while (this.content.peekNext().exists(next -> next != '\n')) {
this.content.next();
}
if (this.content.peekNext().exists(next -> next == '\n')) {
this.content.next();
}
}
private void appendToken(@NotNull final Token token) {
this.tokens = this.tokens.append(token);
}

View File

@ -1,7 +1,9 @@
let x = 1;
if (x) {
x = 99;
// x = 99;
} else {
x = 12;
}
// comment
exit(x);
// comment