]> git.eshelyaron.com Git - emacs.git/commitdiff
(peg-parse): Fix bug#78884
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 24 Jun 2025 22:24:01 +0000 (18:24 -0400)
committerEshel Yaron <me@eshelyaron.com>
Wed, 23 Jul 2025 20:06:47 +0000 (22:06 +0200)
* lisp/progmodes/peg.el (peg-parse): Be more careful when
testing if a symbol is the name of an existing rule.  Improve docstring.

test/lisp/progmodes/peg-tests.el (peg-tests--peg-parse): New test.

(cherry picked from commit 68100ca656ad76e937622a1a74b6ca185bc82e07)

lisp/progmodes/peg.el
test/lisp/progmodes/peg-tests.el

index d8dbf72987936992d0b2f7cf25aae6fdfc7d6644..965af44bb86c0058b0649165d8e6b3924a0e7dd9 100644 (file)
@@ -317,11 +317,15 @@ EXPS is a list of rules/expressions that failed.")
   "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."
+moving point along the way.
+For backward compatibility (and convenience) PEXS can also be a list of
+RULES in which case we run the first such rule.  In case of ambiguity,
+prefix PEXS with \"\" so it doesn't look like a list of rules."
   (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'
index 9d5e09ec8aedef0cddea37c2ca05c675b3dd8355..df761a42c14ac1e80fdfaa8b8a105fcbe25dd7e5 100644 (file)
@@ -396,5 +396,12 @@ resp. succeeded instead of signaling an error."
 ;; (peg-ex-last-digit2 (make-string 500000 ?-))
 ;; (peg-ex-last-digit2 (make-string 500000 ?5))
 
+(ert-deftest peg-tests--peg-parse ()
+  (with-temp-buffer
+    (insert "abc")
+    (goto-char (point-min))
+    (peg-parse (bob) "ab")
+    (should (looking-at "c"))))
+
 (provide 'peg-tests)
 ;;; peg-tests.el ends here