single line comments.
This commit is contained in:
parent
3235cbab7b
commit
ceb0d5aaba
2 changed files with 18 additions and 2 deletions
|
@ -50,7 +50,12 @@ public class Lexer {
|
|||
} else if (c == '*') {
|
||||
this.handleSimple(TokenType.MULT, line, column);
|
||||
} else if (c == '/') {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
let x = 1;
|
||||
if (x) {
|
||||
x = 99;
|
||||
// x = 99;
|
||||
} else {
|
||||
x = 12;
|
||||
}
|
||||
// comment
|
||||
exit(x);
|
||||
// comment
|
Loading…
Reference in a new issue