forked from luna/jorts
scanner: add identifiers
This commit is contained in:
parent
566d8313f3
commit
d62c58a195
1 changed files with 9 additions and 0 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue