aboutsummaryrefslogtreecommitdiff
path: root/internal/config/diag.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-11 14:47:10 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-11 15:01:57 +0200
commit42b02c47be9b285099203e44a2570636d4ca6f03 (patch)
tree82bcb9e19bd886f36e1ca7b2d94a204c988f1fd1 /internal/config/diag.go
downloadkrino-42b02c47be9b285099203e44a2570636d4ca6f03.tar.gz
krino-42b02c47be9b285099203e44a2570636d4ca6f03.zip
krino: foundation — sexp reader, config language, init/new/check
Diffstat (limited to 'internal/config/diag.go')
-rw-r--r--internal/config/diag.go41
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...)})
+}