scanner: add whitespace handling
This commit is contained in:
parent
2c7cf356b3
commit
f4f1fe1fbc
1 changed files with 23 additions and 2 deletions
|
@ -68,9 +68,30 @@ pub const Scanner = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scanToken(self: *Scanner) !tokens.Token {
|
fn peek(self: *Scanner) u8 {
|
||||||
self.start = self.current;
|
if (self.isAtEnd()) return 0;
|
||||||
|
return self.source[self.current];
|
||||||
|
}
|
||||||
|
|
||||||
|
fn skipWhitespace(self: *Scanner) void {
|
||||||
|
while (true) {
|
||||||
|
var c = self.peek();
|
||||||
|
switch (c) {
|
||||||
|
' ', '\r', '\t' => blk: {
|
||||||
|
_ = self.advance();
|
||||||
|
},
|
||||||
|
'\n' => blk: {
|
||||||
|
self.line += 1;
|
||||||
|
_ = self.advance();
|
||||||
|
},
|
||||||
|
else => return,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scanToken(self: *Scanner) !tokens.Token {
|
||||||
|
self.skipWhitespace();
|
||||||
|
self.start = self.current;
|
||||||
if (self.isAtEnd()) return self.makeToken(TokenType.EOF);
|
if (self.isAtEnd()) return self.makeToken(TokenType.EOF);
|
||||||
|
|
||||||
var c = self.advance();
|
var c = self.advance();
|
||||||
|
|
Loading…
Reference in a new issue