Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ltx_diagnostics

Pure diagnostic infrastructure for the LTX toolchain. This crate defines no domain errors — it only provides the building blocks other crates plug into to report, render, and serialize diagnostics.

Responsibilities

  • source file management (LtxSourceMap, LtxSourceFile)
  • byte-range span utilities (LtxSpan, LtxFileId)
  • severity classification (LtxSeverity: Error / Warning / Hint)
  • miette integration and rendering
  • batch diagnostic reporting (LtxDiagnosticSink)
  • the LtxDiagnosticSource helper trait that every crate’s error enum implements
  • the ErrorCode registry metadata struct

Key types

TypeRole
LtxDiagnosticWraps Arc<dyn LtxDiagnosticSource> + Arc<LtxSourceMap> so any phase error can be rendered.
LtxDiagnosticSinkAccumulates diagnostics across phases for batch reporting (never panics).
LtxSourceMap / LtxSourceFileSource-text registry; byte-offset → line:column resolution.
LtxSpan / LtxFileIdByte-range location in a specific file.
LtxSeverityError / Warning / Hint classification.
ErrorCodeRegistry entry describing one diagnostic code (code, description, severity, phase).
LtxDiagnosticSourceTrait implemented by every phase-owned error; exposes its primary span.

Error ownership

Domain errors live in the crates that produce them, not here:

CrateError enumCodes
ltx_lexerLexerErrorLTX::LEXER::E001E011
ltx_parserParserErrorLTX::PARSER::E001E006
ltx_configConfigErrorLTX::CONFIG::E001E008
ltx_compilerCompilerErrorLTX::COMPILER::E001E004, W001

Each of those crates exports a pub const ALL_CODES: &[ErrorCode] registry that the CLI aggregates for ltx code.

Rendering

  • render_pretty(diagnostic) / render_pretty_into(...) — miette graphical output
  • render_json_into(sink, writer) — JSON-serializable diagnostics for tooling

Usage

#![allow(unused)]
fn main() {
use ltx_diagnostics::{LtxSourceMap, LtxDiagnosticSink, LtxDiagnostic, LtxDiagnosticSource};

let mut source_map = LtxSourceMap::new();
let file_id = source_map.add_file("main.tex")?;
// ... produce an error implementing LtxDiagnosticSource ...
let diagnostic = LtxDiagnostic::new(error, source_map.into());
}

Design constraints (see AGENT.md)

  • Never define domain errors here.
  • Never depend on lexer / parser / config / compiler crates (keeps the graph acyclic).