add reading of keywords on doIdentifier
This commit is contained in:
parent
9d4c1249b4
commit
bba969922f
1 changed files with 14 additions and 1 deletions
|
@ -231,7 +231,20 @@ pub const Scanner = struct {
|
|||
_ = self.advance();
|
||||
}
|
||||
|
||||
try self.addSimpleToken(.IDENTIFIER);
|
||||
// after reading the identifier, we check
|
||||
// if it is any of our keywords, if it is, then we add
|
||||
// the specificed keyword type. if not, just .IDENTIFIER
|
||||
var text = self.source[self.start..self.current];
|
||||
var type_opt = self.keywords.get(text);
|
||||
var toktype: TokenType = undefined;
|
||||
|
||||
if (type_opt) |kv| {
|
||||
toktype = @intToEnum(TokenType, kv.value);
|
||||
} else {
|
||||
toktype = TokenType.IDENTIFIER;
|
||||
}
|
||||
|
||||
try self.addSimpleToken(toktype);
|
||||
}
|
||||
|
||||
/// Scan through our tokens and add them to the Scanner's token list.
|
||||
|
|
Loading…
Reference in a new issue