Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Proposal]: Structured diagnostics #7

@LukeSkyw

Description

@LukeSkyw

Currently the parser provides an array of Diagnostic object to give feedback on the potential errors of a parse. Diagnostic is defined this way:

pub const Diagnostic = struct {
    /// line/col position where error occurred.
    coord: types.Coordinate,
    /// Message reported by the parser.
    message: []const u8,
};

This object is designed to communicate directly with a human (it provides a ready made message).

jam being a library to be used by apps or other libraries, may I suggest to amend this design so that Diagnostic provides more information that can be used by a machine to then communicate to a human.

A simple example would be translation. Instead of relying on the content of the string, the Diagnostic object would keep raw information on the error type and the token so that an application might generate the error message itself.

Another use case is implementing a REPL using jam. Like node, the REPL might want to keep receiving input on hitting return if it detects that the javascript entered is "unterminated". The REPL would use the error type and the Token from Diagnostic to identify an UnexpectedToken and the Token being EOF.

pub const Diagnostic = struct {
    /// line/col position where error occurred.
    coord: types.Coordinate,
    /// The error raised
    parserError: ParserError,
    /// The failing token
    token: Token,

    /// Default message
    get_message(diagnostic: Diagnostic) []const u8 { ... }, // we could keep this for convenience
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions