Coverage report: /home/ellis/comp/core/lib/obj/config.lisp

KindCoveredAll%
expression523 21.7
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; obj/config.lisp --- Configuration flavors
2
 
3
 ;;
4
 
5
 ;;; Commentary:
6
 ;; The goal of this package is to make it easy to map an object in
7
 ;; memory to a 'user config interface' - which could be a
8
 ;; configuration file, a datagram, CLI flags, etc.
9
 ;;
10
 ;; This package only provides the config protocol, for other packages to
11
 ;; consume.
12
 
13
 ;;; Usage: 
14
 #|
15
 |#
16
 ;;; Code:
17
 (in-package :obj/config)
18
 
19
 (defclass config () ()
20
   (:documentation "Base class for configurable objects."))
21
 (defgeneric make-config (obj &rest args &key &allow-other-keys)
22
   (:documentation "Make a new configuration.")
23
   (:method ((self t) &key ast)
24
     (typecase ast
25
       (list (make-config (car ast) :path (cadr ast)))
26
       (atom (make-config ast)))))
27
 
28
 (defgeneric find-config (obj &rest args &key &allow-other-keys)
29
   (:documentation "Find an existing configuration."))
30
 (defgeneric config-find (obj key &key &allow-other-keys)
31
   (:documentation "Find KEY in configuration OBJ."))
32
 (defgeneric config-get (obj key)
33
   (:documentation "Get value of KEY in configuration OBJ."))
34
 (defgeneric (setf config-get) (obj key val))
35
 (defgeneric configure (obj &rest args &key &allow-other-keys)
36
   (:documentation "Configure an object with supplied args."))
37
 
38
 (defmacro defconfig (name direct-superclasses direct-slots &rest options)
39
   "DEFCLASS sugar for CONFIG objects."
40
   `(eval-always
41
      (defclass ,name ,(append direct-superclasses '(obj/config::config))
42
        ,direct-slots
43
        ,@options)))
44
 
45
 ;;; TODO 2024-10-27: Simple Config AST
46
 (defmacro define-simple-config (name prototype &body accessors)
47
   "Define a SIMPLE-CONFIG consisting of a MAKE-* function, a predicate, a type
48
 definition, and an optional list of accessors.")