From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: Make peg.el a built-in library? Date: Tue, 08 Nov 2022 08:47:44 +0000 Message-ID: <87edud25ov.fsf@localhost> References: <875yvtbbn3.fsf@ericabrahamsen.net> <877d07a16u.fsf@localhost> <87tu3asg2r.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="17852"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, Stefan Monnier To: Eric Abrahamsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 08 09:48:03 2022 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 1osKH4-0004KK-W6 for ged-emacs-devel@m.gmane-mx.org; Tue, 08 Nov 2022 09:48:03 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osKGP-0000r2-4B; Tue, 08 Nov 2022 03:47:21 -0500 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 1osKGN-0000pD-49 for emacs-devel@gnu.org; Tue, 08 Nov 2022 03:47:19 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osKGK-0006uu-S0 for emacs-devel@gnu.org; Tue, 08 Nov 2022 03:47:18 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 5B73E240101 for ; Tue, 8 Nov 2022 09:47:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1667897232; bh=Srx6aoD+VVF/d0VznmFic1PHejzcI0i/fex1WeFnWEk=; h=From:To:Cc:Subject:Date:From; b=bJqFvaDKsijfmDNIm9x5w9E4vb9u/U7OPxU298RPHZ3UJLIH44SOPJ7VoQnTALNY9 2V/tuTO23oKvacewgaSA7LUr3JLbjGKTBQnBso8cKCHze4TthOJ1oeqMjFXnLX9xBE 69yqzJQ/YPBfgYwsT26Io/e/UZ1jCHalUDMhZyIzyuMy4gaOeNMWjPJzs9XYFKoD+9 xlevDvMEmUrTrG4/YRqQLHOq/YqmWlCGjtP5m2LwcGrYZGmmhg71oAThnDVYjwVYNM dErl8kATgUQdKRcg8qBzprxpR4HPBIv5aj+9Ap+GahECJ8dwt26+biIjrQJlxNjjaE fzQrWYlc5QHGQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4N61tf5SH5z9rxB; Tue, 8 Nov 2022 09:47:06 +0100 (CET) In-Reply-To: <87tu3asg2r.fsf@ericabrahamsen.net> Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299322 Archived-At: Eric Abrahamsen writes: >> Is there any progress merging peg.el to Emacs? >> I do not see any obvious blockers in the discussion, but the merge never >> happened? > > I will say that I tried to use PEG to resolve some gruesome text-parsing > issues in EBDB very recently, and failed to make it work in the hour or > two I'd allotted to the problem. The file-comment docs are pretty good, > but I think they would need to be expanded in a few crucial ways, > particularly to help those who don't necessarily know how PEGs work. > > Specifically, it is not obvious (to me) the ways in which PEGs (or maybe > just peg.el) are not fully declarative. It doesn't backtrack, and I > suspect it won't ever backtrack or isn't even supposed to, which means > users should be made explicitly aware of the ways in which their rules > can fail, and the ways in which declaration order matter. The comment > for the `or' construct reads: > > Prioritized Choice > > And that's about the only hint you get. As the comment in peg.el states, the definitions are adapted from the original PEG paper. There is even a link to paper and also to presentation explaining how peg works. I strongly advice you to read that. Prioritized Choice is explained there. > I was trying to parse a > multiword name like > > Eric Edwin Abrahamsen > > into the structure > > (("Eric" "Edwin") "Abrahamsen") > > using rules like > > (plain-name (substring (+ [word])) (* [space])) > (full-name (list (+ plain-name) plain-name) > `(names -- (list (butlast names) (car (last names))))) > > Which always fails to match because (+ plain-name) is greedy and eats up > all the words. It doesn't ever try leaving out the last word in an > attempt to make the rule match. One way is (with-peg-rules ((name (substring (+ [word])) (* [blank])) (given-name name (not (eol))) (last-name name (and (eol))) (full-name (list (+ given-name) last-name) `(names -- (list (butlast names) (car (last names)))))) (peg-run (peg full-name))) A simple-minded non-greedy version would be ambiguous. You must necessarily indicate end of input. A more appropriate non-ambiguous non-greedy statement would involve or (which you admittedly did not understand): (with-peg-rules ((name (substring (+ [word])) (* [blank])) (given-name name) (last-name name (and (eol))) (full-name (list (+ (or last-name given-name)) (and (eol))) `(names -- (list (butlast names) (car (last names)))))) ;;;;;;;;;;;;;;;;;;;;;^^ (peg-run (peg full-name))) > I'm happy to write the docs (should it have its own info manual > section?), if we really think there are no other necessary > fixes/improvements. I find PEG to be a nice addition when regexps do not cut the necessary parsing, while using Bovine or tree-sitter is an overkill. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at