| ... | @@ -4,12 +4,18 @@ const string = []const u8; | ... | @@ -4,12 +4,18 @@ const string = []const u8; |
| 4 | // | 4 | // |
| 5 | // | 5 | // |
| 6 | | 6 | |
| 7 | pub const Token = union(enum) { | 7 | pub const Token = struct { |
| 8 | word: string, | 8 | data: Data, |
| 9 | symbol: string, | 9 | line: usize, |
| 10 | string: string, | 10 | pos: usize, |
| 11 | | 11 | |
| 12 | pub const skippedChars = &[_]u8{ ' ', '\n', '\t', '\r' }; | 12 | pub const skippedChars = &[_]u8{ ' ', '\n', '\t', '\r' }; |
| | 13 | |
| | 14 | pub const Data = union(enum) { |
| | 15 | word: string, |
| | 16 | symbol: string, |
| | 17 | string: string, |
| | 18 | }; |
| 13 | }; | 19 | }; |
| 14 | | 20 | |
| 15 | // | 21 | // |
| ... | @@ -58,7 +64,11 @@ pub fn do(comptime input: string, comptime symbols: []const u8) []const Token { | ... | @@ -58,7 +64,11 @@ pub fn do(comptime input: string, comptime symbols: []const u8) []const Token { |
| 58 | } | 64 | } |
| 59 | if (mode == 2) { | 65 | if (mode == 2) { |
| 60 | if (c == input[start]) { | 66 | if (c == input[start]) { |
| 61 | ret = ret ++ &[_]Token{.{ .string = input[start .. i + 1] }}; | 67 | ret = ret ++ &[_]Token{.{ |
| | 68 | .data = .{ .string = input[start .. i + 1] }, |
| | 69 | .line = line, |
| | 70 | .pos = pos, |
| | 71 | }}; |
| 62 | start = i + 1; | 72 | start = i + 1; |
| 63 | end = i; | 73 | end = i; |
| 64 | mode = 0; | 74 | mode = 0; |
| ... | @@ -84,7 +94,11 @@ pub fn do(comptime input: string, comptime symbols: []const u8) []const Token { | ... | @@ -84,7 +94,11 @@ pub fn do(comptime input: string, comptime symbols: []const u8) []const Token { |
| 84 | if (shouldFlush) { | 94 | if (shouldFlush) { |
| 85 | if (mode == 0) { | 95 | if (mode == 0) { |
| 86 | if (end - start > 0) { | 96 | if (end - start > 0) { |
| 87 | ret = ret ++ &[_]Token{.{ .word = input[start..end] }}; | 97 | ret = ret ++ &[_]Token{.{ |
| | 98 | .data = .{ .word = input[start..end] }, |
| | 99 | .line = line, |
| | 100 | .pos = pos, |
| | 101 | }}; |
| 88 | start = i; | 102 | start = i; |
| 89 | end = i; | 103 | end = i; |
| 90 | } | 104 | } |
| ... | @@ -93,7 +107,11 @@ pub fn do(comptime input: string, comptime symbols: []const u8) []const Token { | ... | @@ -93,7 +107,11 @@ pub fn do(comptime input: string, comptime symbols: []const u8) []const Token { |
| 93 | end += 1; | 107 | end += 1; |
| 94 | } | 108 | } |
| 95 | if (std.mem.indexOfScalar(u8, symbols, c)) |_| { | 109 | if (std.mem.indexOfScalar(u8, symbols, c)) |_| { |
| 96 | ret = ret ++ &[_]Token{.{ .symbol = s }}; | 110 | ret = ret ++ &[_]Token{.{ |
| | 111 | .data = .{ .symbol = s }, |
| | 112 | .line = line, |
| | 113 | .pos = pos, |
| | 114 | }}; |
| 97 | start += 1; | 115 | start += 1; |
| 98 | end += 1; | 116 | end += 1; |
| 99 | } | 117 | } |