// 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" "git.labunix.xyz/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...)}) }