String Literal Interpolation #46

Merged
kayomn merged 6 commits from kym-string-interpolation into main 2023-11-08 00:32:49 +01:00
1 changed files with 18 additions and 0 deletions
Showing only changes of commit 63792ea983 - Show all commits

View File

@ -31,6 +31,7 @@ pub const Token = union(enum) {
number: []const coral.io.Byte,
string: []const coral.io.Byte,
template_string: []const coral.io.Byte,
keyword_nil,
keyword_false,
@ -81,6 +82,7 @@ pub const Token = union(enum) {
.number => |literal| literal,
.string => |literal| literal,
.template_string => |literal| literal,
.keyword_const => "const",
.keyword_nil => "nil",
@ -305,6 +307,22 @@ pub const Stream = struct {
return;
},
'`' => {
cursor += 1;
const begin = cursor;
while (cursor < self.source.len) switch (self.source[cursor]) {
'`' => break,
else => cursor += 1,
};
self.token = .{.template_string = self.source[begin .. cursor]};
cursor += 1;
return;
},
'"' => {
cursor += 1;