From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.devel Subject: Re: Make peg.el a built-in library? Date: Sun, 19 Sep 2021 08:25:57 -0700 Message-ID: <87zgs8ege2.fsf@ericabrahamsen.net> 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="12372"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: monnier@iro.umontreal.ca Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Sep 19 17:27:20 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 1mRyit-0002zi-Av for ged-emacs-devel@m.gmane-mx.org; Sun, 19 Sep 2021 17:27:19 +0200 Original-Received: from localhost ([::1]:35086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRyis-0005fI-A0 for ged-emacs-devel@m.gmane-mx.org; Sun, 19 Sep 2021 11:27:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRyho-0004aJ-3n for emacs-devel@gnu.org; Sun, 19 Sep 2021 11:26:12 -0400 Original-Received: from mail.ericabrahamsen.net ([52.70.2.18]:44604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRyhk-0001XM-LA for emacs-devel@gnu.org; Sun, 19 Sep 2021 11:26:11 -0400 Original-Received: from localhost (c-71-197-232-156.hsd1.wa.comcast.net [71.197.232.156]) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id E96AFFA09E; Sun, 19 Sep 2021 15:25:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericabrahamsen.net; s=mail; t=1632065159; bh=eB3MuKpKiutXkF7X55xTkmUz2AGGeoHa7HgLH4mTDPk=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=evXNaa/7jM6JmOeFwcHpkVIfPoo+jwX5Zfg+VyLWE14HMmG3DEbdYbgyJujAQXS1S SoXjmkIWDa8RYvVjPaxHpJmi8pnF65uPXbJASMkvXp8u3xreQ8mBy4o636c/O6aJb2 lcu0T3hB+x0V9Qv5czcHO89FvpWNvHtlZ5T2aiqk= 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=52.70.2.18; envelope-from=eric@ericabrahamsen.net; helo=mail.ericabrahamsen.net X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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:275058 Archived-At: Bumping this up in case it slid off radars: I'd like to at least push the documentation patch to peg.el... On 09/08/21 21:36 PM, Eric Abrahamsen wrote: > On 08/26/21 08:34 AM, Eric Abrahamsen wrote: >> Eli Zaretskii writes: >> >>>> From: Eric Abrahamsen >>>> Date: Wed, 25 Aug 2021 11:52:00 -0700 >>>> Cc: Stefan Monnier >>>> >>>> In my on-again-off-again quest to not have to write text parsers myself, >>>> I was pointed towards the PEG library (in ELPA), which does pretty much >>>> exactly what I want (Parsing Expression Grammars). >>>> >>>> Would the maintainers consider moving this into Emacs proper? I ask >>>> mostly because this would be very useful to have in Gnus, both to >>>> replace the home-made parser in gnus-search.el, and I would hope to >>>> parse eg IMAP server responses more fully and reliably. >>> >>> Fine with me, but please update the (outdated) Wiki page to say where >>> the latest peg.el is, when it is imported. >> >> Will do. Stefan also asked me to make sure the library actually does >> what I expect it to do, before making this move, so I'll write the code >> first. > > Okay, I wrote some code: the "use-peg-in-gnus-search.diff" attachment is > the result of that. It works really well! A net removal of ~100 LOC > (obviously we're still in deficit with the addition of peg.el), it > already fixes some wrong behavior of the old parser, and it's much > easier to reason about and add new behavior to. It's the shiny > declarative future I was looking forward to. > > 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. > > 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-parse' could be a function, or maybe it also could also just check > if its argument is a symbol. > > I hope someone will have some thoughts on this! > > Eric