scanner: add identifiers

This commit is contained in:
Luna 2019-06-01 17:15:27 -03:00
parent 566d8313f3
commit d62c58a195

View file

@ -150,12 +150,21 @@ pub const Scanner = struct {
return self.makeToken(.NUMBER);
}
fn doIdentifier(self: *Scanner) Token {
while (isAlphaNumeric(self.peek())) {
_ = self.advance();
}
return self.makeToken(.IDENTIFIER);
}
pub fn scanToken(self: *Scanner) !?Token {
self.skipWhitespace();
self.start = self.current;
if (self.isAtEnd()) return self.makeToken(TokenType.EOF);
var c = self.advance();
if (isAlpha(c)) return self.doIdentifier();
if (isDigit(c)) return self.doNumber();
var token = switch (c) {