unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "\( via Guix-patches" via <guix-patches@gnu.org>
To: 63135@debbugs.gnu.org
Cc: "\(" <paren@disroot.org>, Josselin Poiret <dev@jpoiret.xyz>
Subject: [bug#63135] [PATCH 2/3] records: match-record: Display more helpful field-not-found error.
Date: Thu, 27 Apr 2023 23:06:52 +0100	[thread overview]
Message-ID: <20230427220653.5228-2-paren@disroot.org> (raw)
In-Reply-To: <20230427220653.5228-1-paren@disroot.org>

* guix/records.scm (match-record): Display MATCH-RECORD as the origin of
  "unknown record type field" errors.
Show the original MATCH-RECORD form, rather than an intermediate LOOKUP-FIELD
form, within said errors.
---
 guix/records.scm | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/guix/records.scm b/guix/records.scm
index d8966998c1..4bee9d0aac 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -582,44 +582,46 @@ (define-syntax lookup-field
   (lambda (s)
     "Look up FIELD in the given list and return an expression that represents
 its offset in the record.  Raise a syntax violation when the field is not
-found."
+found, displaying it as originating in form S*."
     (syntax-case s ()
-      ((_ field offset ())
-       (syntax-violation 'lookup-field "unknown record type field"
-                         s #'field))
-      ((_ field offset (head tail ...))
+      ((_ s* field offset ())
+       (syntax-violation 'match-record
+                         "unknown record type field"
+                         #'s* #'field))
+      ((_ s* field offset (head tail ...))
        (free-identifier=? #'field #'head)
        #'offset)
-      ((_ field offset (_ tail ...))
-       #'(lookup-field field (+ 1 offset) (tail ...))))))
+      ((_ s* field offset (_ tail ...))
+       #'(lookup-field s* field (+ 1 offset) (tail ...))))))
 
 (define-syntax match-record-inner
   (lambda (s)
     (syntax-case s ()
-      ((_ record type ((field variable) rest ...) body ...)
+      ((_ s* record type ((field variable) rest ...) body ...)
        #'(let-syntax ((field-offset (syntax-rules ()
 			              ((_ f)
-                                       (lookup-field field 0 f)))))
+                                       (lookup-field s* field 0 f)))))
            (let* ((offset (type (map-fields type match-record) field-offset))
                   (variable (struct-ref record offset)))
-             (match-record-inner record type (rest ...) body ...))))
-      ((_ record type (field rest ...) body ...)
+             (match-record-inner s* record type (rest ...) body ...))))
+      ((_ s* record type (field rest ...) body ...)
        ;; Redirect to the canonical form above.
-       #'(match-record-inner record type ((field field) rest ...) body ...))
-      ((_ record type () body ...)
+       #'(match-record-inner s* record type ((field field) rest ...) body ...))
+      ((_ s* record type () body ...)
        #'(begin body ...)))))
 
 (define-syntax match-record
-  (syntax-rules ()
+  (lambda (s)
     "Bind each FIELD of a RECORD of the given TYPE to it's FIELD name.
 The order in which fields appear does not matter.  A syntax error is raised if
 an unknown field is queried.
 
 The current implementation does not support thunked and delayed fields."
     ;; TODO support thunked and delayed fields
-    ((_ record type (fields ...) body ...)
-     (if (eq? (struct-vtable record) type)
-         (match-record-inner record type (fields ...) body ...)
-         (throw 'wrong-type-arg record)))))
+    (syntax-case s ()
+      ((_ record type (fields ...) body ...)
+       #`(if (eq? (struct-vtable record) type)
+             (match-record-inner #,s record type (fields ...) body ...)
+             (throw 'wrong-type-arg record))))))
 
 ;;; records.scm ends here
-- 
2.39.2





  reply	other threads:[~2023-04-27 22:08 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27 22:04 [bug#63135] [PATCH 0/3] MATCH-RECROD improvements ( via Guix-patches via
2023-04-27 22:06 ` [bug#63135] [PATCH 1/3] records: match-record: Raise a syntax error if TYPE is nonexistent ( via Guix-patches via
2023-04-27 22:06   ` ( via Guix-patches via [this message]
2023-04-27 22:06   ` [bug#63135] [PATCH 3/3] records: match-record: Support thunked and delayed fields ( via Guix-patches via
2023-04-28 19:19 ` [bug#63135] [PATCH v2 0/5] MATCH-RECORD improvements ( via Guix-patches via
2023-04-28 19:19   ` [bug#63135] [PATCH v2 1/5] records: match-record: Raise a syntax error if TYPE is nonexistent ( via Guix-patches via
2023-05-19 15:22     ` [bug#63135] [PATCH 0/3] MATCH-RECROD improvements Ludovic Courtès
2023-04-28 19:19   ` [bug#63135] [PATCH v2 2/5] records: match-record: Display more helpful field-not-found error ( via Guix-patches via
2023-05-19 15:25     ` [bug#63135] [PATCH 0/3] MATCH-RECROD improvements Ludovic Courtès
2023-04-28 19:19   ` [bug#63135] [PATCH v2 3/5] records: match-record: Support thunked and delayed fields ( via Guix-patches via
2023-05-19 15:25     ` [bug#63135] [PATCH 0/3] MATCH-RECROD improvements Ludovic Courtès
2023-04-28 19:19   ` [bug#63135] [PATCH v2 4/5] dir-locals: Fix MATCH-RECORD indentation ( via Guix-patches via
2023-05-19 15:27     ` [bug#63135] [PATCH 0/3] MATCH-RECROD improvements Ludovic Courtès
2023-05-20 18:02       ` ( via Guix-patches via
2023-05-24 14:11         ` Ludovic Courtès
2023-05-24 15:49           ` ( via Guix-patches via
2023-05-26 16:41             ` Ludovic Courtès
2023-05-27  0:55               ` ( via Guix-patches via
2023-04-28 19:19   ` [bug#63135] [PATCH v2 5/5] records: Add MATCH-RECORD-LAMBDA ( via Guix-patches via
2023-05-19 15:28     ` [bug#63135] [PATCH 0/3] MATCH-RECROD improvements Ludovic Courtès
2023-06-04  9:47   ` bug#63135: [PATCH v2 0/5] MATCH-RECORD improvements Josselin Poiret via Guix-patches via
2023-06-04 10:48     ` [bug#63135] " Josselin Poiret via Guix-patches via
2023-06-04 19:11     ` ( via Guix-patches via

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230427220653.5228-2-paren@disroot.org \
    --to=guix-patches@gnu.org \
    --cc=63135@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=paren@disroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).