From 42b02c47be9b285099203e44a2570636d4ca6f03 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Fri, 11 Sep 2026 14:47:10 +0200 Subject: krino: foundation — sexp reader, config language, init/new/check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/config/diag.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 internal/config/diag.go (limited to 'internal/config/diag.go') 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...)}) +} -- cgit v1.3