Adapter from Grip's byte-offset ParseError to the pure
termcolor-diagnostics model.
Byte offsets from a parser are not yet useful source diagnostics; they need line, span, and rendering context without making Grip depend on a terminal stack.
This project is maintained by its author with AI-assisted development tools. Changes are reviewed, tested, and remain the maintainer's responsibility.
require grip-diagnostics from git
"https://github.com/jonaprieto/lean-grip-diagnostics.git" @ "v0.2.5"import Grip
import GripDiagnostics
import TermColor.Diagnostics
open Grip GripDiagnostics TermColor TermColor.Diagnostics
def source : Source := Source.fromBytes "config.toml" "timeout = 2x".toUTF8
def error : ParseError := { pos := 11, line := 1, col := 12, expected := ["a duration"] }
def text : Text :=
(diagnostic source error).withCode "GRIP001" |>.withHelp "try timeout = 2m"
|> fun d => render #[source] d
#eval Text.render RenderTarget.plain textThe adapter preserves source bytes and maps a parser failure to a clamped primary point label. Rendering supports plain text, ANSI targets, width-aware context, tabs, Unicode, and optional OSC-8 locations. Terminal IO remains optional.
lake build GripDiagnostics GripDiagnostics.Properties tests demo readme
lake exe tests
lake exe demogrip supplies parsing;
termcolor-diagnostics supplies the
renderer. lean-calc-chat uses the adapter in a
terminal application.
Apache-2.0.