From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74018: 31.0.50; Issue with define-peg-ruleset? Date: Fri, 25 Oct 2024 16:30:30 -0400 Message-ID: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1156"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca To: 74018@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 25 22:31:56 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t4QyR-00007J-IM for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 25 Oct 2024 22:31:56 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t4Qy6-0001rr-6s; Fri, 25 Oct 2024 16:31:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t4Qy2-0001rT-Rr for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2024 16:31:31 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t4Qy2-0004iq-JQ for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2024 16:31:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=UqAFm6hjrNXOrQe1/+JwqRilGo8/Y206v+fdxFwSf/8=; b=eIcBt59Ga+Uxfhx9PWKsk1mBCVMCMteMkITxRdLu8rmF2Fl9QOWTslAmAsxq6zrtv92HICPsMYSbCxLBm0VtXPS1gylfxbZY1wjmiv3gJun7Geo0YCNf/nUrfigu8BrKBH8ut95iytTBEumLwYHKGXy20kBo07TXsdQrGxz4QgW78SpKDFHbm9cdYocPcDGigkb/5W+JaM3uhC8c6trOYHsurw1b/GhNW8lymq8jsstCvMp9ztxvQq4e/KMVp51BAMrxGktTSudOih6yPwgu0o/WGgkJPPMcKhucRFId9EQ9GJxWoV3bgzLvVn17wCZSjZiOf03p+l5xmE0NR9oTEQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t4QyY-0007TO-8t; Fri, 25 Oct 2024 16:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Fri, 25 Oct 2024 20:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74018 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: monnier@iro.umontreal.ca Original-Received: via spool by submit@debbugs.gnu.org id=B.172988827528657 (code B ref -1); Fri, 25 Oct 2024 20:32:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Oct 2024 20:31:15 +0000 Original-Received: from localhost ([127.0.0.1]:39584 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t4Qxm-0007S9-SL for submit@debbugs.gnu.org; Fri, 25 Oct 2024 16:31:15 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:41912) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t4Qxk-0007Rv-Js for submit@debbugs.gnu.org; Fri, 25 Oct 2024 16:31:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t4QxB-0001p8-OC for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2024 16:30:38 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t4Qx9-0004ai-32 for bug-gnu-emacs@gnu.org; Fri, 25 Oct 2024 16:30:37 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 5869D100180; Fri, 25 Oct 2024 16:30:32 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1729888231; bh=PeMsA3z+40m5WYFZgyOjG0MOQt377bi0ShK1a8QinZ4=; h=From:To:Subject:Date:From; b=cvu9ryp68BCaT/KVz/2BEXU5DG2IqOggWkx3/Q734rPzJwPl+9mo+hkWRGbJYotO2 NMGMHtH7O/b/oAAD2DtkNK6hfhxRMI8mEUv+03rK16p1COSMCR3iFc6G510+UF7wq0 x7EuPeJa3CiBwVkKgR3TwfTPXBurGQSfO56yJDUcy7VG7zz/M0uqCCig1t15tWUG1p JBCy+uhk97BwaSggB7Kh22Kqz3+S9TUcluXFUzj9Kuc08Bt3c3ZV440D4Om65ynWmw dYSAiypz2y0H+vzfb5h5lb+AWw9L3++di/VffVZvqDYiBCDs5bDhpoyeDJtkDZc7m7 t6ogavfSeEGgg== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 9CAB7100043; Fri, 25 Oct 2024 16:30:31 -0400 (EDT) Original-Received: from pastel (69-196-161-60.dsl.teksavvy.com [69.196.161.60]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 7865612090E; Fri, 25 Oct 2024 16:30:31 -0400 (EDT) Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:294237 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=peg.patch 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 --=-=-=--