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: Sat, 02 Oct 2021 10:45:32 -0400 Message-ID: References: <875yvtbbn3.fsf@ericabrahamsen.net> <83wno8u3uz.fsf@gnu.org> <87v93s9q4n.fsf@ericabrahamsen.net> <875yvafjr9.fsf@ericabrahamsen.net> <878rzdreem.fsf@alphapapa.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="6146"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel To: Adam Porter Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Oct 02 16:47:07 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 1mWgI5-0001QR-RH for ged-emacs-devel@m.gmane-mx.org; Sat, 02 Oct 2021 16:47:06 +0200 Original-Received: from localhost ([::1]:51862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWgI4-0000WT-Nk for ged-emacs-devel@m.gmane-mx.org; Sat, 02 Oct 2021 10:47:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWgGn-0007ii-T2 for emacs-devel@gnu.org; Sat, 02 Oct 2021 10:45:46 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:57172) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWgGk-000742-Hn for emacs-devel@gnu.org; Sat, 02 Oct 2021 10:45:44 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 46F548067B; Sat, 2 Oct 2021 10:45:39 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 93CA980580; Sat, 2 Oct 2021 10:45:33 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1633185933; bh=6ScpGiBVTSC6D9hY3FIKN5Ex5T/XpOpDVb/80WxPfhw=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=R17NU+bAG1JQ6X3gUbPmJJxDXkgqv7Q3l4GHmS4af+SK9KTKqBMWg38lB7813d9wa XpnJ9VVYORgrzxIJESq8Phi61vAXUTSDACr387Rk20YGrWUZfjpcAscCSSpxd3mouU Mn+d9cpSQXPA+KZOevp+SeYkSvWpbcSg5Xv8qr9w9mhSFDuIxM5g7eHYO6Bdf6gX9s AqDkMvTUJpSeAFo5mFuNzFW3HYmJWWShJV/HIMiw2NTVmRbuvut7IQL9bW0KMSw+Hm A7aH4wr9bDc9eFZchLdc0+DaG1FEXmPHQpSFPR5lGxorVVeo2SEazOK9T28o4tI5o6 doGprJFI7n/VQ== Original-Received: from pastel (unknown [45.72.241.23]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 645B112033B; Sat, 2 Oct 2021 10:45:33 -0400 (EDT) In-Reply-To: (Adam Porter's message of "Sat, 2 Oct 2021 02:32:22 -0500") 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:276066 Archived-At: >> E.g. we could have a PEX of the form (re FORM) where FORM can be any >> ELisp expression that returns a regular expression. Then `org-ql.el` >> could do >> >> (let ((predicate-re (regexp-opt predicate-names))) >> (peg-parse >> ((query (+ term >> (opt (+ (syntax-class whitespace) (any))))) >> [...] >> (predicate (re predicate-re)) >> [...]))) > > That would be helpful, yes. Thanks, I'll think about what can be done here. >> PS: BTW, regarding your comment: >> >> ;; Sort the keywords longest-first to work around what seems to be an >> ;; obscure bug in `peg': when one keyword is a substring of another, >> ;; and the shorter one is listed first, the shorter one fails to match. >> >> The behavior you describe indeed seems like a bug, but maybe what you >> see is slightly different (and not a bug): if you have a PEX like >> (and (or "foo" "foobar") "X") >> the "foo" will match when faced with "foobarX" and the parser won't >> backtrack to try and match the "foobar" when the "X" fails to match. > > Hmm, thanks. I think an example of the problem is that a predicate in > org-ql might have a shorter alias, e.g. "heading" is has the alias > "h", and predicates are followed by arguments, like "heading:foo", so > IIRC, without sorting them there, "heading:foo" would work, while > "h:foo" wouldn't. Odd. If you have (or "h" "header") in the grammar then I'd expect "h:foo" to be recognized but "heading:foo" to be rejected (IOW, that would be a bug in the grammar rather than in `peg.el`). But you describe the exact opposite for which I don't have an explanation. So maybe it's a bug in `peg.el`. Could you try and distill it into a bug report? Stefan