unionstd.zon.parse.Error.Note[src]

Fields

Functions

FunctionfmtMessage[src]

pub fn fmtMessage(self: Note, status: *const Status) std.fmt.Formatter(Note.formatMessage)

Parameters

self: Note
status: *const Status

Source Code

Source code
pub fn fmtMessage(self: Note, status: *const Status) std.fmt.Formatter(Note.formatMessage) {
    return .{ .data = switch (self) {
        .zoir => |note| note.msg.get(status.zoir.?),
        .type_check => |note| note.msg,
    } };
}

FunctiongetLocation[src]

pub fn getLocation(self: Note, status: *const Status) Ast.Location

Parameters

self: Note
status: *const Status

Source Code

Source code
pub fn getLocation(self: Note, status: *const Status) Ast.Location {
    const ast = status.ast.?;
    switch (self) {
        .zoir => |note| return zoirErrorLocation(ast, note.token, note.node_or_offset),
        .type_check => |note| return ast.tokenLocation(note.offset, note.token),
    }
}

Source Code

Source code
pub const Note = union(enum) {
    zoir: Zoir.CompileError.Note,
    type_check: TypeCheckFailure.Note,

    pub const Iterator = struct {
        index: usize = 0,
        err: Error,
        status: *const Status,

        pub fn next(self: *@This()) ?Note {
            switch (self.err) {
                .zoir => |err| {
                    if (self.index >= err.note_count) return null;
                    const zoir = self.status.zoir.?;
                    const note = err.getNotes(zoir)[self.index];
                    self.index += 1;
                    return .{ .zoir = note };
                },
                .type_check => |err| {
                    if (self.index >= err.getNoteCount()) return null;
                    const note = err.getNote(self.index);
                    self.index += 1;
                    return .{ .type_check = note };
                },
            }
        }
    };

    fn formatMessage(
        self: []const u8,
        comptime f: []const u8,
        options: std.fmt.FormatOptions,
        writer: anytype,
    ) !void {
        _ = f;
        _ = options;

        // Just writes the string for now, but we're keeping this behind a formatter so we have
        // the option to extend it in the future to print more advanced messages (like `Error`
        // does) without breaking the API.
        try writer.writeAll(self);
    }

    pub fn fmtMessage(self: Note, status: *const Status) std.fmt.Formatter(Note.formatMessage) {
        return .{ .data = switch (self) {
            .zoir => |note| note.msg.get(status.zoir.?),
            .type_check => |note| note.msg,
        } };
    }

    pub fn getLocation(self: Note, status: *const Status) Ast.Location {
        const ast = status.ast.?;
        switch (self) {
            .zoir => |note| return zoirErrorLocation(ast, note.token, note.node_or_offset),
            .type_check => |note| return ast.tokenLocation(note.offset, note.token),
        }
    }
}