Subject: Re: bug#78884: 30.1; peg-parse does not treat its arguments as sequence

From: Stefan Monnier <[email-masked]>
Date: Tue, 24 Jun 2025 14:12:36 -0400

Tim Landscheidt [2025-06-24 00:12:11] wrote:

> The docstring for Emacs 30.1's peg-parse reads:
>
> | (peg-parse &rest PEXS)
>
> | Match PEXS at point.
> | PEXS is a sequence of PEG expressions, implicitly combined with ‘and’.
> | Returns STACK if the match succeed and signals an error on failure,
> | moving point along the way.
>
> However, it will fail with (for example) "Wrong type
> argument: listp" when called as such:
>
> | ELISP> (with-temp-buffer
> |          (insert "ABCDEF")
> |          (goto-char (point-min))
> |          (peg-parse
> |           (bob)
> |           "ABC"))
> | *** Eval error ***  Wrong type argument: listp, "ABC"
> | ELISP>
>
> An explicit sequence with "and" works:
>
> | ELISP> (with-temp-buffer
> |          (insert "ABCDEF")
> |          (goto-char (point-min))
> |          (peg-parse
> |           (and
> |            (bob)
> |            "ABC")))
> | t
>
> | ELISP>

Can you check that the quick-fix below fixes things on your side (and
not just for your example)?

        Stefan

diff --git a/lisp/progmodes/peg.el b/lisp/progmodes/peg.el
index 7827990af35..b5ffff31362 100644
--- a/lisp/progmodes/peg.el
+++ b/lisp/progmodes/peg.el
@@ -320,8 +320,9 @@ peg-parse
 moving point along the way."
   (if (and (consp (car pexs))
            (symbolp (caar pexs))
-           (not (ignore-errors
-                  (not (eq 'call (car (peg-normalize (car pexs))))))))
+           (not (or (get (peg--rule-id (caar pexs)) 'peg--rule-definition)
+                    (ignore-errors
+                      (not (eq 'call (car (peg-normalize (car pexs)))))))))
       ;; The first of `pexs' has not been defined as a rule, so assume
       ;; that none of them have been and they should be fed to
       ;; `with-peg-rules'