From b9d3b8537418985a99dc8e6a513f8dd28d262339 Mon Sep 17 00:00:00 2001 From: Stefan Monnier 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 `. `define-peg-ruleset` instead defines it PEG rules with name `peg-rule `, so that they can be made visible by `with-peg-rules` simply by adding local aliases from `peg-rule ` to `peg-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