From bba969922fb7dc8a80ef52285cafbc625f964335 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 31 May 2019 22:39:53 -0300 Subject: [PATCH] add reading of keywords on doIdentifier --- src/scanner.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/scanner.zig b/src/scanner.zig index 020cd53..f2073d1 100644 --- a/src/scanner.zig +++ b/src/scanner.zig @@ -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.