GNU bug report logs - #74018
31.0.50; Issue with define-peg-ruleset?

Previous Next

Package: emacs;

Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>

Date: Fri, 25 Oct 2024 20:32:02 UTC

Severity: normal

Found in version 31.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#74018: closed (31.0.50; Issue with define-peg-ruleset?)
Date: Tue, 29 Oct 2024 02:16:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Mon, 28 Oct 2024 22:15:43 -0400
with message-id <jwvmsink62z.fsf-monnier+emacs <at> gnu.org>
and subject line Re: bug#74018: 31.0.50; Issue with define-peg-ruleset?
has caused the debbugs.gnu.org bug report #74018,
regarding 31.0.50; Issue with define-peg-ruleset?
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
74018: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=74018
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; Issue with define-peg-ruleset?
Date: Fri, 25 Oct 2024 16:30:30 -0400
[Message part 3 (text/plain, inline)]
Package: Emacs
Version: 31.0.50


Augusto pointed out a bug in `peg.el` when you have code like:

    (define-peg-ruleset myrules
      (sign  () (or "+" "-" ""))
      (digit () [0-9])
      (nat   () digit (* digit))
      (int   () sign digit (* digit))
      (float () int "." nat))

    (with-peg-rules
        (myrules
         (complex float "+i" float))
      (peg-parse nat "," nat "," complex) )

where the macroexpanded code is wrong and leads to errors like:

    Debugger entered--Lisp error: (void-function peg-rule\ nat)

I was about to install the bugfix below to `master` but noticed that it
probably belongs to `emacs-30` instead since the bug makes
`define-peg-ruleset` basically unusable and PEG is new in Emacs-30.

Any objection?


        Stefan
[peg.patch (text/x-diff, inline)]
diff --git a/lisp/progmodes/peg.el b/lisp/progmodes/peg.el
index 96334162195..b18d68c69c5 100644
--- a/lisp/progmodes/peg.el
+++ b/lisp/progmodes/peg.el
@@ -412,6 +412,7 @@ define-peg-ruleset
              (full-rname (format "%s %s" name rname)))
         (push `(define-peg-rule ,full-rname . ,(cdr rule)) defs)
         (push `(,(peg--rule-id rname) #',(peg--rule-id full-rname)) aliases)))
+    (require 'cl-lib)
     `(cl-flet ,aliases
        ,@defs
        (eval-and-compile (put ',name 'peg--rules ',aliases)))))
@@ -432,7 +432,8 @@
                               (progn (push rule rulesets) nil)
                             (cons (car rule) (peg-normalize `(and . ,(cdr rule))))))
                         rules)))
-        (ctx (assq :peg-rules macroexpand-all-environment)))
+         (ctx (assq :peg-rules macroexpand-all-environment))
+         (body
     (macroexpand-all
      `(cl-labels
           ,(mapcar (lambda (rule)
@@ -444,6 +445,15 @@
         ,@body)
      `((:peg-rules ,@(append rules (cdr ctx)))
        ,@macroexpand-all-environment))))
+    (if (null rulesets)
+        body
+      `(cl-flet ,(mapcan (lambda (ruleset)
+                           (let ((aliases (get ruleset 'peg--rules)))
+                             (unless aliases
+                               (message "Unknown PEG ruleset: %S" ruleset))
+                             (copy-sequence aliases)))
+                         rulesets)
+         ,body))))
 
 ;;;;; Old entry points
 
[Message part 5 (message/rfc822, inline)]
From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 74018-done <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>, acorallo <at> gnu.org
Subject: Re: bug#74018: 31.0.50; Issue with define-peg-ruleset?
Date: Mon, 28 Oct 2024 22:15:43 -0400
> No objections from me either, please go ahead.

Pushed to `emacs-30`, thanks,


        Stefan



This bug report was last modified 207 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.