From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Make peg.el a built-in library? Date: Thu, 30 Sep 2021 15:44:28 -0400 Message-ID: References: <875yvtbbn3.fsf@ericabrahamsen.net> <83wno8u3uz.fsf@gnu.org> <87v93s9q4n.fsf@ericabrahamsen.net> <875yvafjr9.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27363"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Eli Zaretskii , emacs-devel@gnu.org To: Eric Abrahamsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Sep 30 21:46:33 2021 Return-path: Envelope-to: ged-emacs-devel@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 1mW20n-0006tZ-NO for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Sep 2021 21:46:33 +0200 Original-Received: from localhost ([::1]:56068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mW20m-0006rP-Mx for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Sep 2021 15:46:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mW1z0-0005PF-RB for emacs-devel@gnu.org; Thu, 30 Sep 2021 15:44:42 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:58465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mW1yx-0005kS-Qz; Thu, 30 Sep 2021 15:44:41 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C56581002E3; Thu, 30 Sep 2021 15:44:36 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 3203610018B; Thu, 30 Sep 2021 15:44:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1633031075; bh=7MwvnmTLvtkrkvuPoq87jVbEpssrXEW8kmHrNKjHrWc=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=nUHXohLcrjoVq9crrN3SoOToymAcW+LEhFkBZ7MdTuY+RWQIfEc0EIIgoFkfBzK4p yJBCqh7z3TrmGoNfqGD9TwPOQiEFYa1JU/mPPs8GaecL7o9FcKtohZDKE856IeLcWq M09C8A6ssaapyn9FKZGoI3idJxbFGDRTGYzVqhSa1k+VFHedtwEKOQVr/Yl8MoXnJV TJDUuerSM3PtCfBLxzgQOWoWYHe3BQclHA9lHA4OfEj0wPTi75O9jkX60qOnbXWmKR zJTarNxBOgy9dffo9hTt1NbSoQYtAgRGZlp1P5mMTmqc4f2DWJcC1D/htl389SPxMJ eCbden4FrHPiw== Original-Received: from ceviche (unknown [45.72.241.23]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 03CEB1200D7; Thu, 30 Sep 2021 15:44:34 -0400 (EDT) In-Reply-To: <875yvafjr9.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Wed, 08 Sep 2021 21:36:10 -0700") 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:275925 Archived-At: > Whether or not PEG gets added to core I'd like to propose some patches. > The "peg-doc-patches.diff" attachment adds some documentation to the > Commentary section, including an example grammar based on a > much-simplified version of what gnus-search does. Looks great, thanks. > The peg-allow-symbols patch is more tentative. The issue is that _all_ > of the entry-points to peg code are macros, meaning you can't build your > grammar up in a variable, and then pass that variable to any of > `peg-run', `peg-parse', `with-peg-rules', etc. Nobody will evaluate the > variable; you have to literally write the rules inside the > `with-peg-rules' form. It seems like a fairly plausible use-case to > store the rules in a variable or an option, even if you're not doing > run-time manipulation of them. The only solution, as Adam found with > org-ql, is to `eval' one of the macros. > > This doesn't seem necessary! The patch has `with-peg-rules' check if the > rules are a symbol, and take the `symbol-value' if so. But I wonder if > it wouldn't be nicer to break some of the code out: `peg-normalize' > seems to be the entry-point for "compile this grammar", and that could > be modified to work the way that some languages provide for pre-compiled > regexps: a way to let the developer build and compile the grammar at > load-time or launch-time, then feed the stored compiled version to > parsing routines. `peg` is the macro that's supposed to be this compilation step: you pass it a PEX and you receive a value in return. It's a bit like `lambda`. You can then use this value (a "peg matcher") to parse something by passing it to `peg-run`. So you can do (let ((parser (peg PEX))) ... (peg-run parser ...) ...) What might still be missing, tho is a way to invoke this `parser` from within a PEX. So we might want to add a new PEX form that would be akin to `funcall`. We could name it `call`: (let* ((parser (peg PEX)) ... (with-peg-rules ((foo ...) (bar ... (call parser) ...) (baz ...)) ...)) so (peg-parse (call FORM)) would end up equivalent to (peg-run FORM ...). WDYT? Stefan