add multiline comment support

This commit is contained in:
Luna 2019-06-04 17:40:13 -03:00
parent 1e47b29685
commit 8a9522d954

View file

@ -153,7 +153,7 @@ pub const Scanner = struct {
} }
fn peekNext(self: *Scanner) u8 { 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]; return self.source[self.current];
} }
@ -246,14 +246,27 @@ pub const Scanner = struct {
'>' => self.makeMatchToken('=', .GreaterEqual, .Greater), '>' => self.makeMatchToken('=', .GreaterEqual, .Greater),
'/' => blk: { '/' => blk: {
if (self.peekNext() == '/') { var next = self.peekNext();
switch (next) {
'/' => blk2: {
while (self.peek() != '\n' and !self.isAtEnd()) { while (self.peek() != '\n' and !self.isAtEnd()) {
_ = self.advance(); _ = self.advance();
} }
break :blk null; return null;
} else { },
break :blk self.makeToken(.Slash);
'*' => blk2: {
while (self.peek() != '*' or self.peekNext() != '/') {
_ = self.advance();
}
// consume the ending slash
_ = self.advance();
return null;
},
else => break :blk self.makeToken(.Slash),
} }
}, },