From 8a9522d954f1d14cfa63793afdb09dc1f5c80324 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 4 Jun 2019 17:40:13 -0300 Subject: [PATCH] add multiline comment support --- src/scanner.zig | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/scanner.zig b/src/scanner.zig index c4c61e7..2b7b46b 100644 --- a/src/scanner.zig +++ b/src/scanner.zig @@ -153,7 +153,7 @@ pub const Scanner = struct { } fn peekNext(self: *Scanner) u8 { - if (self.current + 1 >= self.source.len) return 0; + if (self.current > self.source.len) return 0; return self.source[self.current]; } @@ -246,14 +246,27 @@ pub const Scanner = struct { '>' => self.makeMatchToken('=', .GreaterEqual, .Greater), '/' => blk: { - if (self.peekNext() == '/') { - while (self.peek() != '\n' and !self.isAtEnd()) { - _ = self.advance(); - } + var next = self.peekNext(); + switch (next) { + '/' => blk2: { + while (self.peek() != '\n' and !self.isAtEnd()) { + _ = self.advance(); + } - break :blk null; - } else { - break :blk self.makeToken(.Slash); + return null; + }, + + '*' => blk2: { + while (self.peek() != '*' or self.peekNext() != '/') { + _ = self.advance(); + } + + // consume the ending slash + _ = self.advance(); + return null; + }, + + else => break :blk self.makeToken(.Slash), } },