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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 74018 in the body.
You can then email your comments to 74018 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#74018; Package emacs. (Fri, 25 Oct 2024 20:32:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Fri, 25 Oct 2024 20:32:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

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 1 (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
 

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74018; Package emacs. (Fri, 25 Oct 2024 21:03:14 GMT) Full text and rfc822 format available.

Message #8 received at 74018 <at> debbugs.gnu.org (full text, mbox):

From: Andrea Corallo <acorallo <at> gnu.org>
To: 74018 <at> debbugs.gnu.org
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#74018: 31.0.50; Issue with define-peg-ruleset?
Date: Fri, 25 Oct 2024 17:01:18 -0400
Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:

> 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?

No objections on my side.

Thanks

  Andrea
  




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74018; Package emacs. (Sat, 26 Oct 2024 06:20:01 GMT) Full text and rfc822 format available.

Message #11 received at 74018 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>,
 Stefan Kangas <stefankangas <at> gmail.com>, Andrea Corallo <acorallo <at> gnu.org>
Cc: 74018 <at> debbugs.gnu.org
Subject: Re: bug#74018: 31.0.50; Issue with define-peg-ruleset?
Date: Sat, 26 Oct 2024 09:16:07 +0300
> Cc: monnier <at> iro.umontreal.ca
> Date: Fri, 25 Oct 2024 16:30:30 -0400
> From:  Stefan Monnier via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> Version: 31.0.50
           ^^^^^^^
Given what you say below, this is inaccurate.

> 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?

I know nothing about peg.el, and you haven't explained the root cause
for the bug for me to understand why it "makes `define-peg-ruleset'
basically unusable", so let's hear from Stefan and Andrea first.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74018; Package emacs. (Sat, 26 Oct 2024 14:26:02 GMT) Full text and rfc822 format available.

Message #14 received at 74018 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Andrea Corallo <acorallo <at> gnu.org>, Stefan Kangas <stefankangas <at> gmail.com>,
 74018 <at> debbugs.gnu.org
Subject: Re: bug#74018: 31.0.50; Issue with define-peg-ruleset?
Date: Sat, 26 Oct 2024 10:24:33 -0400
[Message part 1 (text/plain, inline)]
>> Version: 31.0.50
>            ^^^^^^^
> Given what you say below, this is inaccurate.

Indeed, sorry, I forgot to erase that info.

>> 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?
>
> I know nothing about peg.el, and you haven't explained the root cause
> for the bug for me to understand why it "makes `define-peg-ruleset'
> basically unusable", so let's hear from Stefan and Andrea first.

Here's a more complete description.


        Stefan
[0001-with-peg-rules-Fix-references-to-rulesets-bug-74018.patch (text/x-diff, inline)]
From b9d3b8537418985a99dc8e6a513f8dd28d262339 Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier <at> iro.umontreal.ca>
Date: Sat, 26 Oct 2024 10:23:01 -0400
Subject: [PATCH] (with-peg-rules): Fix references to rulesets (bug#74018)

PEG rules get "compiled" to functions with name `peg-rule <RULE>`.
`define-peg-ruleset` instead defines it PEG rules with name
`peg-rule <RULESET> <RULE>`, so that they can be made visible
by `with-peg-rules` simply by adding local aliases from
`peg-rule <RULE>` to `peg-rule <RULESET> <RULE>`.

Apparently when I added `define-peg-ruleset` I somehow failed to
install some of the corresponding code in `with-peg-rules`, so
the aliases were not installed, making it "impossible" to use
rulesets.
[ I still have no idea how this happened and/or where
  the missing code went, so I recreated it.  ]

* lisp/progmodes/peg.el (with-peg-rules): Install the aliases
for the rulesets.
---
 lisp/progmodes/peg.el | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/peg.el b/lisp/progmodes/peg.el
index 96334162195..0e6ba9318e3 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 +433,8 @@ with-peg-rules
                               (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 +446,15 @@ with-peg-rules
         ,@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
 
-- 
2.39.5


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74018; Package emacs. (Sat, 26 Oct 2024 15:49:01 GMT) Full text and rfc822 format available.

Message #17 received at 74018 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: acorallo <at> gnu.org, stefankangas <at> gmail.com, 74018 <at> debbugs.gnu.org
Subject: Re: bug#74018: 31.0.50; Issue with define-peg-ruleset?
Date: Sat, 26 Oct 2024 18:47:57 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: Stefan Kangas <stefankangas <at> gmail.com>,  Andrea Corallo
>  <acorallo <at> gnu.org>,  74018 <at> debbugs.gnu.org
> Date: Sat, 26 Oct 2024 10:24:33 -0400
> 
> >> 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?
> >
> > I know nothing about peg.el, and you haven't explained the root cause
> > for the bug for me to understand why it "makes `define-peg-ruleset'
> > basically unusable", so let's hear from Stefan and Andrea first.
> 
> Here's a more complete description.

Thanks.  Andrea already agreed with installing this on the release
branch.  I hope Stefan Kangas will respond soon.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74018; Package emacs. (Mon, 28 Oct 2024 22:57:02 GMT) Full text and rfc822 format available.

Message #20 received at 74018 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: acorallo <at> gnu.org, 74018 <at> debbugs.gnu.org
Subject: Re: bug#74018: 31.0.50; Issue with define-peg-ruleset?
Date: Mon, 28 Oct 2024 15:54:53 -0700
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
>> Cc: Stefan Kangas <stefankangas <at> gmail.com>,  Andrea Corallo
>>  <acorallo <at> gnu.org>,  74018 <at> debbugs.gnu.org
>> Date: Sat, 26 Oct 2024 10:24:33 -0400
>>
>> >> 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?
>> >
>> > I know nothing about peg.el, and you haven't explained the root cause
>> > for the bug for me to understand why it "makes `define-peg-ruleset'
>> > basically unusable", so let's hear from Stefan and Andrea first.
>>
>> Here's a more complete description.
>
> Thanks.  Andrea already agreed with installing this on the release
> branch.  I hope Stefan Kangas will respond soon.

No objections from me either, please go ahead.




Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Tue, 29 Oct 2024 02:16:02 GMT) Full text and rfc822 format available.

Notification sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
bug acknowledged by developer. (Tue, 29 Oct 2024 02:16:02 GMT) Full text and rfc822 format available.

Message #25 received at 74018-done <at> debbugs.gnu.org (full text, mbox):

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





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 26 Nov 2024 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 206 days ago.

Previous Next


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