pub const Diagnostics = struct line_number: u64 = 1line_start_cursor: usize = @as(usize, @bitCast(@as(isize, -1)))total_bytes_before_current_input: u64 = 0cursor_pointer: *const usize = undefinedpub fn getLine(self: *const @This()) u64Starts at 1.
pub fn getColumn(self: *const @This()) u64Starts at 1.
pub fn getByteOffset(self: *const @This()) u64Starts at 0. Measures the byte offset since the start of the input.
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564pub const Diagnostics = struct {
line_number: u64 = 1,
line_start_cursor: usize = @as(usize, @bitCast(@as(isize, -1))), // Start just "before" the input buffer to get a 1-based column for line 1.
total_bytes_before_current_input: u64 = 0,
cursor_pointer: *const usize = undefined,
/// Starts at 1.
pub fn getLine(self: *const @This()) u64 {
return self.line_number;
}
/// Starts at 1.
pub fn getColumn(self: *const @This()) u64 {
return self.cursor_pointer.* -% self.line_start_cursor;
}
/// Starts at 0. Measures the byte offset since the start of the input.
pub fn getByteOffset(self: *const @This()) u64 {
return self.total_bytes_before_current_input + self.cursor_pointer.*;
}
}
To enable diagnostics, declare
var diagnostics = Diagnostics{};then callsource.enableDiagnostics(&diagnostics);wheresourceis either astd.json.Readeror astd.json.Scannerthat has just been initialized. At any time, notably just after an error, callgetLine(),getColumn(), and/orgetByteOffset()to get meaningful information from this.