package diagnostics
import "github.com/azin-lang/Azin/internal/diagnostics"
Package diagnostics provides structures and engines to record, format, and report compiler errors, warnings, and informational notes.
Index
- Constants
- type Diagnostic
- type DiagnosticKind
-
type Engine
- func New(file *source.File) *Engine
- func (e *Engine) Diagnostics() []Diagnostic
- func (e *Engine) Err() error
- func (e *Engine) Error() string
- func (e *Engine) HasErrors() bool
- func (e *Engine) Report(kind DiagnosticKind, pos token.Position, length uint32, format string, ...)
- func (e *Engine) ReportError(pos token.Position, length uint32, format string, args ...any)
- func (e *Engine) ReportNote(pos token.Position, length uint32, format string, args ...any)
- func (e *Engine) ReportWarning(pos token.Position, length uint32, format string, args ...any)
Constants
const ( Note = iota Warning Error )
Types
type Diagnostic
type Diagnostic struct { Kind DiagnosticKind // kind Message string // diagnostic message Position token.Position // position at which the diagnostic was emited Length uint32 // length of the offending }
A Diagnostic represents a single compiler message at a specific location.
func (Diagnostic) Error
func (d Diagnostic) Error() string
type DiagnosticKind
type DiagnosticKind uint8
DiagnosticKind is the severity level of a diagnostic.
func (DiagnosticKind) String
func (k DiagnosticKind) String() string
type Engine
type Engine struct { // contains filtered or unexported fields }
Engine collects diagnostics for a source file.
func New
func New(file *source.File) *Engine
New returns a new Engine for the given file.
func (*Engine) Diagnostics
func (e *Engine) Diagnostics() []Diagnostic
Diagnostics returns all recorded diagnostics.
func (*Engine) Err
func (e *Engine) Err() error
Err returns the engine as an error if it contains errors, or nil otherwise.
func (*Engine) Error
func (e *Engine) Error() string
Formats all diagnostics into a readable string.
func (*Engine) HasErrors
func (e *Engine) HasErrors() bool
HasErrors reports whether any errors have been recorded.
func (*Engine) Report
func (e *Engine) Report(kind DiagnosticKind, pos token.Position, length uint32, format string, args ...any)
Report adds a diagnostic to the engine.
func (*Engine) ReportError
func (e *Engine) ReportError(pos token.Position, length uint32, format string, args ...any)
ReportError logs an error-level diagnostic.
func (*Engine) ReportNote
func (e *Engine) ReportNote(pos token.Position, length uint32, format string, args ...any)
ReportNote logs a note-level diagnostic.
func (*Engine) ReportWarning
func (e *Engine) ReportWarning(pos token.Position, length uint32, format string, args ...any)
ReportWarning logs a warning-level diagnostic.