From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Danny McClanahan Newsgroups: gmane.emacs.devel Subject: Re: rosie/libpexl library for regex pattern composition Date: Mon, 29 Jul 2024 13:58:13 +0000 Message-ID: References: <8734nudmeh.fsf@gmail.com> <864j8a0xa2.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6167"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Helmut Eller , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jul 29 16:26:11 2024 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 1sYRKD-0001L4-U3 for ged-emacs-devel@m.gmane-mx.org; Mon, 29 Jul 2024 16:26:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sYRJc-00030d-7R; Mon, 29 Jul 2024 10:25:32 -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 1sYQtP-0001TK-8D for emacs-devel@gnu.org; Mon, 29 Jul 2024 09:58:27 -0400 Original-Received: from mail-40136.proton.ch ([185.70.40.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sYQtM-000099-HL; Mon, 29 Jul 2024 09:58:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hypnicjerk.ai; s=protonmail2; t=1722261497; x=1722520697; bh=B9hvS00paVKgJ2wes0P/Iap2zXkeOVNndSLXAiZjPUg=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=irp8BSYL9GUqZEb03K87tk9q4ALKp1v0cwoQ+NKDCIL6ZVV8UNGPMn6a/4ivlA12k I0WcX4niJT5G/0DkMJhxIf/bFp8hWEiGxSUdvdCuuoLywYm/tZNne1/S6FCzGjLwbE jYFGrkEi3ozolVcSD3vK6G1OxFmxsjZUmskfHs0O1tRxlylvqAuKfm1PiGNlIDd8Qo mK+9odqrnb64XNSVPLTKf7e86ncfpoPMgu3H+b7ZP934HJvR/m5ZkvC6Fk7bWgCfYN uQZY9k6mj5Q2RKWU8meuV7upr9jQceeaE/1H+xYBtGMbIp+kgo/m+k2YYLaxPr4JGF xSJpww9IBejVQ== In-Reply-To: <864j8a0xa2.fsf@gnu.org> Feedback-ID: 27837847:user:proton X-Pm-Message-ID: 58c030a8f9f177853a64ec0d0e00654146a813e5 Received-SPF: pass client-ip=185.70.40.136; envelope-from=dmcc2@hypnicjerk.ai; helo=mail-40136.proton.ch X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 29 Jul 2024 10:25:29 -0400 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:322197 Archived-At: > From: Helmut Eller > Cc: "emacs-devel@gnu.org" > Date: Sun, 28 Jul 2024 09:08:06 +0200 > > AFAIU, Rosie is based on parsing expression grammars, i.e. it's not a regular language and it's in a different complexity class. That's true! However, the PEXL project (essentially Rosie v2) is actually l= ooking to move past the PEG formalism for being insufficiently expressive a= s well as presenting some implementation issues, particularly with respect = to performance (see brief description at https://gitlab.com/pexlang/libpexl= #libpexl-is-a-work-in-progress-library-for-text-matching-and-simple-parsing= ). > On Sunday, July 28th, 2024 at 03:51, Eli Zaretskii wrote: > > Tree-sitter accesses buffer text one character at a time, for which an > API is very simple, and we already have such an API modules could use: > char-after. But I very much doubt that libraries like Rosie could do > well with such APIs for its needs. One of the improvements PEXL has over Rosie v1 is the `find` VM instruction= (described in the above-linked README), which uses SIMD to search many byt= es ahead at once instead of iterating char-by-char. This functionality some= thing I am also hoping to demonstrate with my regex-emacs v2 engine, althou= gh I am working on a char-by-char NFA first. IIUC, regex engines tend to em= ploy SIMD searching as a "prefilter" (see discussion in https://github.com/= BurntSushi/rebar/blob/master/README.md) before employing the char-by-char m= atchers, which may be easier to separate out into some explicit multi-phase= search API if needed. This is mostly to say that both regex engines using automata as well as Ros= ie could likely be made to work with a char-by-char API alone, although it = would obviously hamper some optimization opportunities. It may be an easier= way to prototype new matching engines than building them within Emacs. > The alternative is to give modules > direct access to the entire buffer text, which IMO is unthinkable. I had not considered the possibility of exposing a module API for extensibl= e parsing engines as opposed to building it directly into Emacs like the cu= rrent regex-emacs engine, but I definitely appreciate the idea of decouplin= g from a specific framework, especially with an eye to reducing the mainten= ance burden. From my current understanding, the benefits of building Rosie/= PEXL directly into Emacs would be: (1) could take advantage of e.g. SIMD search by directly accessing the gap = buffer memory, (2) since it would be reliably available to all Emacs users, could form a c= omposeable elisp search API. My impression from prior discussion on this list was that one long-term des= ire for Emacs lisp was a lisp-level API to explicitly represent and compose= search patterns, vs e.g. the implicit caching performed for matchers from = regex-emacs.c (currently represented to elisp developers as lisp strings). = If that is a goal, it seems difficult to realize that without building the = matching logic and the pattern compiler into Emacs itself (please correct m= e if I'm wrong about this). However, if *that* is the goal, then it also seems appropriate to prototype= such a lisp-level API first, before introducing external code like Rosie/P= EXL; at a first glance, it should be possible to do this with the current r= egex-emacs.c. Once such a layer is established, we could even imagine expos= ing a module API that allows for pluggable parsing frameworks. If Rosie/PEX= L offers significant benefits and is easy enough to integrate, we could the= n compare the pros and cons of building it in directly (and then offering a= more expressive lisp-level matching API with its power) vs exposing a modu= le API (which may be easier to maintain). We would then be comparing the maintenance burden of pluggability over the = maintenance burden of integrating Rosie/PEXL, but I believe the lisp-level = matcher API (with explicit construction over implicit caching) can be proto= typed right now without that bikeshedding, and seems to be something Emacs = desires in any case. Does that correctly outline the goals/desires for lisp-level matcher constr= uction? I like the idea of figuring out that API first, since all it needs = to start is "just" an explicit lisp object for compiled regexps, which alon= e was mentioned as a goal in prior discussions. I think in any case having = established that API surface will definitely make it easier to integrate ot= her regex/parsing frameworks, be they built into Emacs or via external modu= le. As it stands, I would like to have made this relatively straightforward= improvement to Emacs before proposing the integration of other more comple= x external dependencies. Thanks, Danny