From b3909efb3a6bf76870b686b5062f9a4282fbdd66 Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Thu, 24 Jul 2025 20:38:56 +0200 Subject: `let x = 1` -> `x := 1` --- src/Lexer.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Lexer.zig') diff --git a/src/Lexer.zig b/src/Lexer.zig index 4665379..4b664fe 100644 --- a/src/Lexer.zig +++ b/src/Lexer.zig @@ -13,6 +13,7 @@ pub const Token = struct { plus, minus, equal, + colon, invalid, eof, identifier, @@ -22,7 +23,6 @@ pub const Token = struct { right_angle_equal, // Keywords - let, @"if", @"else", @"while", @@ -34,6 +34,7 @@ pub const Location = struct { end: usize, pub fn combine(a: Location, b: Location) Location { + if (a.start == b.start and a.end == b.end) return a; std.debug.assert(a.end <= b.start); return .{ .start = @min(a.start, b.start), .end = @max(a.end, b.end) }; } @@ -83,6 +84,7 @@ fn getNext(self: *Self) Token { '+' => self.create(.plus), '-' => self.create(.minus), '=' => self.create(.equal), + ':' => self.create(.colon), '<' => if (self.eatIfEqual('=')) self.create(.left_angle_equal) else @@ -135,7 +137,7 @@ fn identifierOrKeyword(self: *Self) Token { } const value = self.source[self.start..self.pos]; return self.create(switch (std.meta.stringToEnum(Token.Type, value) orelse .invalid) { - .let, .@"if", .@"else", .@"while" => |t| t, + .@"if", .@"else", .@"while" => |t| t, else => .identifier, }); } -- cgit v1.2.3