unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#74018: 31.0.50; Issue with define-peg-ruleset?
@ 2024-10-25 20:30 Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-25 21:01 ` Andrea Corallo
  2024-10-26  6:16 ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-25 20:30 UTC (permalink / raw)
  To: 74018; +Cc: monnier

[-- Attachment #1: Type: text/plain, Size: 769 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: peg.patch --]
[-- Type: text/x-diff, Size: 1485 bytes --]

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
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-10-29  2:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-25 20:30 bug#74018: 31.0.50; Issue with define-peg-ruleset? Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-25 21:01 ` Andrea Corallo
2024-10-26  6:16 ` Eli Zaretskii
2024-10-26 14:24   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-26 15:47     ` Eli Zaretskii
2024-10-28 22:54       ` Stefan Kangas
2024-10-29  2:15         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).