lexer: count lines
This commit is contained in:
parent
4c84ad0ea0
commit
166e9a5b8e
@ -4932,6 +4932,7 @@ pub const Builder = struct {
|
||||
unreachable;
|
||||
}
|
||||
},
|
||||
.bool => return .zero_extend,
|
||||
else => |t| @panic(@tagName(t)),
|
||||
},
|
||||
.pointer => {
|
||||
@ -11303,8 +11304,16 @@ pub const Builder = struct {
|
||||
},
|
||||
.character_literal => blk: {
|
||||
const ch_literal = unit.getExpectedTokenBytes(node.token, .character_literal);
|
||||
assert(ch_literal.len == 3);
|
||||
const character = ch_literal[1];
|
||||
const character = switch (ch_literal.len) {
|
||||
3 => ch_literal[1],
|
||||
// This has a escape character
|
||||
4 => switch (ch_literal[2]) {
|
||||
'n' => '\n',
|
||||
else => unreachable,
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
|
||||
break :blk .{
|
||||
.value = .{
|
||||
.@"comptime" = .{
|
||||
|
@ -132,7 +132,7 @@ pub fn analyze(allocator: *MyAllocator, text: []const u8, token_buffer: *Token.B
|
||||
},
|
||||
'\'' => blk: {
|
||||
index += 1;
|
||||
index += @intFromBool(text[index] == '\'');
|
||||
index += @intFromBool(text[index] == '\\');
|
||||
index += 1;
|
||||
const is_end_char_literal = text[index] == '\'';
|
||||
index += @intFromBool(is_end_char_literal);
|
||||
|
11
src/main.nat
11
src/main.nat
@ -9,8 +9,15 @@ const ArgumentProcessingError = error{
|
||||
no_arguments,
|
||||
};
|
||||
|
||||
const lex = fn () void {
|
||||
const lex = fn (arena: &Arena, bytes: []const u8) void {
|
||||
var line_count: u32 = 0;
|
||||
for (bytes) |b| {
|
||||
line_count += #cast(b == '\n');
|
||||
}
|
||||
|
||||
print("Line count: ");
|
||||
std.print_usize(line_count);
|
||||
print("\n");
|
||||
}
|
||||
|
||||
const get_argument = fn (real_argument: []const u8, wanted_argument: []const u8, command_arguments: []const [&:0]const u8, i_ptr: &usize) ?[]const u8 {
|
||||
@ -80,6 +87,8 @@ const command_exe = fn (arena: &Arena, command_arguments: []const [&:0]const u8)
|
||||
file_descriptor.read_all(file_buffer);
|
||||
print("File:\n");
|
||||
print(file_buffer);
|
||||
|
||||
lex(arena, file_buffer);
|
||||
}
|
||||
|
||||
const main = fn() *!void {
|
||||
|
Loading…
x
Reference in New Issue
Block a user