From ceb0d5aaba55ad3e3ac4b8e9e3a7c9f2d4365416 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Sun, 24 Mar 2024 04:44:47 +0100 Subject: [PATCH] single line comments. --- .../ch/fritteli/gombaila/domain/lexer/Lexer.java | 16 +++++++++++++++- src/main/resources/gombaila/simple.gb | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) 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