jonaprieto/lean-grip-diagnostics

Rich source-annotated diagnostics for Grip parser failures

★ 1Forks 0LeanGitHub ↗Compare

Project website ↗

ai-assisteddiagnosticserror-reportinggripleanlean4parserparser-combinatorssource-annotationstermcolorterminal

README

lean-grip-diagnostics

CI Release Lean 4 Docs License

Adapter from Grip's byte-offset ParseError to the pure termcolor-diagnostics model.

Problem

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.

Development

This project is maintained by its author with AI-assisted development tools. Changes are reviewed, tested, and remain the maintainer's responsibility.

Install

require grip-diagnostics from git
  "https://github.com/jonaprieto/lean-grip-diagnostics.git" @ "v0.2.5"

Quick start

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 text

The 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.

Build

lake build GripDiagnostics GripDiagnostics.Properties tests demo readme
lake exe tests
lake exe demo

Related projects

grip supplies parsing; termcolor-diagnostics supplies the renderer. lean-calc-chat uses the adapter in a terminal application.

License

Apache-2.0.

Contributors

jonaprieto

Issues