nfl/diagnostics

Shared diagnostic type and error-raising helpers used across the reader, expander, lowerer, and backend, so all NFL-level errors carry a Span and format consistently regardless of which pass raised them.

Types

CompilerError = object of CatchableError
  diagnostic*: Diagnostic
Raised by the expander, lowerer, or backend for a form that reads fine but is invalid once macro-expanded (e.g. wrong arity, a circular import, an unresolvable reference).
Diagnostic = object
  severity*: DiagnosticSeverity
  span*: Span
  message*: string
A single reported problem: severity, source location, and message.
DiagnosticSeverity = enum
  dsError
ReaderError = object of CatchableError
  diagnostic*: Diagnostic
  incomplete*: bool ## True when the error is purely "ran out of input while inside an
                    ## open form" (unterminated list/vector/string/escaped symbol/block
                    ## comment/pragma, or EOF while `readForm` still expects a form) —
                    ## as opposed to a form that is syntactically finished but wrong. The
                    ## REPL (`repl.nim`) uses this to distinguish "keep reading more
                    ## lines" from "this input is actually broken."
Raised by reader.nim for a syntactically malformed source form.

Procs

proc `$`(diagnostic: Diagnostic): string {....raises: [], tags: [], forbids: [].}
Formats as file:line:col: message, using <input> for the file when span.file is empty (e.g. REPL input not backed by a real file).
proc error(span: Span; message: string): Diagnostic {....raises: [], tags: [],
    forbids: [].}
Builds a dsError-severity diagnostic at span.
proc raiseCompilerError(span: Span; message: string) {.noreturn,
    ...raises: [CompilerError], tags: [], forbids: [].}
Raises a CompilerError at span.
proc raiseReaderError(span: Span; message: string; incomplete = false) {.
    noreturn, ...raises: [ReaderError], tags: [], forbids: [].}
Raises a ReaderError at span. Set incomplete when the failure is only "ran out of input", not a malformed form (see ReaderError).