feat: add --literal cli option to disable file name parsing for line numbers

This commit is contained in:
CJ van den Berg 2024-11-20 21:33:18 +01:00
parent 53843797f0
commit 47dd41bdf6
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -64,6 +64,7 @@ pub fn main() anyerror!void {
.no_syntax = "Disable syntax highlighting", .no_syntax = "Disable syntax highlighting",
.syntax_report_timing = "Report syntax highlighting time", .syntax_report_timing = "Report syntax highlighting time",
.exec = "Execute a command on startup", .exec = "Execute a command on startup",
.literal = "Disable :LINE and +LINE syntax",
.version = "Show build version and exit", .version = "Show build version and exit",
}; };
@ -74,6 +75,7 @@ pub fn main() anyerror!void {
.trace_level = 't', .trace_level = 't',
.language = 'l', .language = 'l',
.exec = 'e', .exec = 'e',
.literal = 'L',
.version = 'v', .version = 'v',
}; };
@ -92,6 +94,7 @@ pub fn main() anyerror!void {
no_syntax: bool, no_syntax: bool,
syntax_report_timing: bool, syntax_report_timing: bool,
exec: ?[]const u8, exec: ?[]const u8,
literal: bool,
version: bool, version: bool,
}; };
@ -211,7 +214,7 @@ pub fn main() anyerror!void {
for (positional_args.items) |arg| { for (positional_args.items) |arg| {
if (arg.len == 0) continue; if (arg.len == 0) continue;
if (arg[0] == '+') { if (!args.literal and arg[0] == '+') {
const line = try std.fmt.parseInt(usize, arg[1..], 10); const line = try std.fmt.parseInt(usize, arg[1..], 10);
if (prev) |p| { if (prev) |p| {
p.line = line; p.line = line;
@ -228,18 +231,22 @@ pub fn main() anyerror!void {
curr.line = line; curr.line = line;
line_next = null; line_next = null;
} }
var it = std.mem.splitScalar(u8, arg, ':'); if (!args.literal) {
curr.file = it.first(); var it = std.mem.splitScalar(u8, arg, ':');
if (it.next()) |line_| curr.file = it.first();
curr.line = std.fmt.parseInt(usize, line_, 10) catch blk: { if (it.next()) |line_|
curr.file = arg; curr.line = std.fmt.parseInt(usize, line_, 10) catch blk: {
break :blk null; curr.file = arg;
}; break :blk null;
if (curr.line) |_| { };
if (it.next()) |col_| if (curr.line) |_| {
curr.column = std.fmt.parseInt(usize, col_, 10) catch null; if (it.next()) |col_|
if (it.next()) |col_| curr.column = std.fmt.parseInt(usize, col_, 10) catch null;
curr.end_column = std.fmt.parseInt(usize, col_, 10) catch null; if (it.next()) |col_|
curr.end_column = std.fmt.parseInt(usize, col_, 10) catch null;
}
} else {
curr.file = arg;
} }
} }