guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#54674] [PATCH] services: configuration: Use *unspecified* instead o


From: Maxime Devos
Subject: [bug#54674] [PATCH] services: configuration: Use *unspecified* instead of 'disabled.
Date: Mon, 04 Apr 2022 13:25:11 +0200
User-agent: Evolution 3.38.3-1

Attila Lendvai schreef op ma 04-04-2022 om 07:46 [+0000]:
> in this change i try to introduce a codepath for a canonical form for
> DEFINE-CONFIGURATION fields, but it won't work this way, because this
> way the SYNTAX-CASE forms will only match when *every* field is of
> the specified shape.

See attachement for poposed solution. (Not done: *unspecified* instead
of the symbol 'disabled' as default).

Greetings,
Maxime.
diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm
index 0de350a4df..06bb73c9fa 100644
--- a/gnu/services/configuration.scm
+++ b/gnu/services/configuration.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2021 Andrew Tropin <andrew@trop.in>
+;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -162,9 +163,21 @@ does not have a default value" field kind)))
 (define-syntax-rule (define-maybe/no-serialization stem)
   (define-maybe stem (no-serialization)))
 
+(define (analyse-field-type+def s)
+  (syntax-case s ()
+    ((field-type def ...)
+     (identifier? #'field-type)
+     (values #'(field-type def ...)))
+    (field-type
+     (identifier? #'field-type)
+     (values #'(field-type)))))
+
 (define (define-configuration-helper serialize? serializer-prefix syn)
   (syntax-case syn ()
-    ((_ stem (field (field-type def ...) doc custom-serializer ...) ...)
+    ((_ stem (field field-type+def doc custom-serializer ...) ...)
+     ;; TODO: fix indentation, maybe with-syntax*?
+     (with-syntax ((((field-type def ...) ...)
+                    (map analyse-field-type+def #'(field-type+def ...))))
      (with-syntax (((field-getter ...)
                     (map (lambda (field)
                            (id #'stem #'stem #'- field))
@@ -233,7 +246,7 @@ does not have a default value" field kind)))
             (let ((conf (#,(id #'stem #'% #'stem) arg (... ...))))
               (validate-configuration conf
                                       #,(id #'stem #'stem #'-fields))
-              conf)))))))
+              conf))))))))
 
 (define no-serialization         ;syntactic keyword for 'define-configuration'
   '(no serialization))
@@ -241,26 +254,26 @@ does not have a default value" field kind)))
 (define-syntax define-configuration
   (lambda (s)
     (syntax-case s (no-serialization prefix)
-      ((_ stem (field (field-type def ...) doc custom-serializer ...) ...
+      ((_ stem (field field-type+def doc custom-serializer ...) ...
           (no-serialization))
        (define-configuration-helper
-         #f #f #'(_ stem (field (field-type def ...) doc custom-serializer ...)
+         #f #f #'(_ stem (field field-type+def doc custom-serializer ...)
                  ...)))
-      ((_ stem  (field (field-type def ...) doc custom-serializer ...) ...
+      ((_ stem  (field field-type+def doc custom-serializer ...) ...
           (prefix serializer-prefix))
        (define-configuration-helper
-         #t #'serializer-prefix #'(_ stem (field (field-type def ...)
+         #t #'serializer-prefix #'(_ stem (field field-type+def
                                                  doc custom-serializer ...)
                  ...)))
-      ((_ stem (field (field-type def ...) doc custom-serializer ...) ...)
+      ((_ stem (field field-type+def doc custom-serializer ...) ...)
        (define-configuration-helper
-         #t #f #'(_ stem (field (field-type def ...) doc custom-serializer ...)
+         #t #f #'(_ stem (field field-type+def doc custom-serializer ...)
                  ...))))))
 
 (define-syntax-rule (define-configuration/no-serialization
-                      stem (field (field-type def ...)
+                      stem (field field-type+def
                                   doc custom-serializer ...) ...)
-  (define-configuration stem (field (field-type def ...)
+  (define-configuration stem (field field-type+def
                                     doc custom-serializer ...) ...
     (no-serialization)))
 

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]