diff --git a/src/main/java/ch/fritteli/gombaila/domain/lexer/Lexer.java b/src/main/java/ch/fritteli/gombaila/domain/lexer/Lexer.java index 30eb652..8538bdc 100644 --- a/src/main/java/ch/fritteli/gombaila/domain/lexer/Lexer.java +++ b/src/main/java/ch/fritteli/gombaila/domain/lexer/Lexer.java @@ -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); } diff --git a/src/main/resources/gombaila/simple.gb b/src/main/resources/gombaila/simple.gb index 13a65c2..22df3fd 100644 --- a/src/main/resources/gombaila/simple.gb +++ b/src/main/resources/gombaila/simple.gb @@ -1,7 +1,9 @@ let x = 1; if (x) { - x = 99; +// x = 99; } else { x = 12; } +// comment exit(x); +// comment \ No newline at end of file