diff options
Diffstat (limited to 'internal/config/diag.go')
| -rw-r--r-- | internal/config/diag.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/config/diag.go b/internal/config/diag.go new file mode 100644 index 0000000..5cee428 --- /dev/null +++ b/internal/config/diag.go @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +// Package config reads krino's configuration: the main file krino.conf and +// one file per directory under dirs/. It checks everything it reads and +// reports every problem with its position. +package config + +import ( + "fmt" + + "krino/internal/sexp" +) + +// Diag is one problem in a config file. +type Diag struct { + File string + Pos sexp.Pos + Msg string +} + +func (d *Diag) Error() string { + if d.Pos.Line == 0 { + return fmt.Sprintf("%s: %s", d.File, d.Msg) + } + return fmt.Sprintf("%s:%d:%d: %s", d.File, d.Pos.Line, d.Pos.Col, d.Msg) +} + +// diags collects the problems found in one file. +type diags struct { + file string + list []*Diag +} + +// at records a problem at n's position; a nil n means the whole file. +func (d *diags) at(n *sexp.Node, format string, args ...any) { + var pos sexp.Pos + if n != nil { + pos = n.Pos + } + d.list = append(d.list, &Diag{File: d.file, Pos: pos, Msg: fmt.Sprintf(format, args...)}) +} |
