better error reporting

This commit is contained in:
2026-08-27 15:41:42 +02:00
parent 319d5e9cff
commit 9f2dd563f0
+4 -2
View File
@@ -124,7 +124,8 @@
(lines (if (file-exists? file) (file->lines file) '())) (lines (if (file-exists? file) (file->lines file) '()))
(re-section #px"^\\[([a-zA-Z0-9_.-]+)\\]$") (re-section #px"^\\[([a-zA-Z0-9_.-]+)\\]$")
(re-keyval #px"^([a-zA-Z0-9_.-]+)[=](.*)$") (re-keyval #px"^([a-zA-Z0-9_.-]+)[=](.*)$")
(re-comment #px"^[;](.*)$")) (re-comment #px"^[;](.*)$")
(line-nr 0))
(letrec ((f (lambda (sections section lines) (letrec ((f (lambda (sections section lines)
(if (null? lines) (if (null? lines)
(append sections (list section)) (append sections (list section))
@@ -133,6 +134,7 @@
(m-comment (regexp-match re-comment line)) (m-comment (regexp-match re-comment line))
(m-keyval (regexp-match re-keyval line)) (m-keyval (regexp-match re-keyval line))
(m-section (regexp-match re-section line))) (m-section (regexp-match re-section line)))
(set! line-nr (+ 1 line-nr))
(if empty (if empty
(f sections (append section (list (list 'empty))) (cdr lines)) (f sections (append section (list (list 'empty))) (cdr lines))
(if m-comment (if m-comment
@@ -146,7 +148,7 @@
(interpret (string-trim (caddr m-keyval)))))) (cdr lines)) (interpret (string-trim (caddr m-keyval)))))) (cdr lines))
(if m-section (if m-section
(f (append sections (list section)) (list (string->symbol (string-trim (cadr m-section)))) (cdr lines)) (f (append sections (list section)) (list (string->symbol (string-trim (cadr m-section)))) (cdr lines))
(error "Unknown INI line")))))))))) (error (format "Unknown INI line\n~a: ~a\n" line-nr line)))))))))))
(mcons 'ini (f '() (list 'nil) lines))))) (mcons 'ini (f '() (list 'nil) lines)))))
(define (ini-get ini section key def-val) (define (ini-get ini section key def-val)