lang::parser::diagnostic
lang/src/parser/diagnostic.mo
Rust-mirroring parse error diagnostic rendering for the self-hosted
parser. Mirrors rust/core/src/diag.rs's render_diagnostic format —
error: <message> at L:C\n --> path:L:C\n<context lines> — using
lang/parser/core.mo's ParseError (which carries the input
remaining at the point of failure) and
lang/parser/position.mo's location_of_remaining to recover a
real line:column. No ANSI color codes (mirrors the Rust renderer's
use_colors: false path) — this is a CLI-and-log-friendly plain
rendering, not a byte-for-byte reproduction of every diag.rs
feature (sub-diagnostics, suggestions, colorized spans): just the
core "where did this fail and what does the surrounding source look
like" diagnostic, which is what a parse failure actually needs.
pub def parse_error_location (source : String) (err : ParseError) : LocationWHERE a parse failure was detected, as a point.
render_parse_error above folds exactly this into a rendered string,
which is right for a terminal and wrong for an editor: a language server
needs the position as DATA, and by the time a caller holds the rendered
message the Location is gone. Same location_of_remaining call, and
the same caveat -- source must be the full text err's remaining came
from, or the position is silently nonsense.
A Location is a point, so a caller turning this into a range
synthesizes the end; using the same point twice is correct and honest,
marking the spot rather than inventing an extent.