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 == '*') {
|
} else if (c == '*') {
|
||||||
this.handleSimple(TokenType.MULT, line, column);
|
this.handleSimple(TokenType.MULT, line, column);
|
||||||
} else if (c == '/') {
|
} 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 == '%') {
|
} else if (c == '%') {
|
||||||
this.handleSimple(TokenType.MOD, line, column);
|
this.handleSimple(TokenType.MOD, line, column);
|
||||||
} else if (c == '^') {
|
} else if (c == '^') {
|
||||||
|
@ -107,6 +112,15 @@ public class Lexer {
|
||||||
this.appendToken(new Token(tokenType, line, column));
|
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) {
|
private void appendToken(@NotNull final Token token) {
|
||||||
this.tokens = this.tokens.append(token);
|
this.tokens = this.tokens.append(token);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
let x = 1;
|
let x = 1;
|
||||||
if (x) {
|
if (x) {
|
||||||
x = 99;
|
// x = 99;
|
||||||
} else {
|
} else {
|
||||||
x = 12;
|
x = 12;
|
||||||
}
|
}
|
||||||
|
// comment
|
||||||
exit(x);
|
exit(x);
|
||||||
|
// comment
|
Loading…
Reference in a new issue