From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2222 invoked from network); 1 Nov 2023 02:05:37 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 1 Nov 2023 02:05:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Obqq2U2VqzwOYhO5WBBAtMwbbpI7HT/XPMKZ83cJnMU=; b=TVQQ/UlWurnC0XdaS8eENQVLH2 THSkbIxCHbefY3Gc6YgZcN3Qlp14TPhYp6ubkST72iC5Xi4qBJ1aFTfb2oDeYGZkXqoZZlRlFb0mz xYy7RjUB22vA04/HIUvFRJCWfWzAqpJM9OKH1M0ecsPklj896B86OFGHBSRC2mny+wTPOGRPg0xoG nBjP/6ZGtRn5eWTj9LuhKwa6RgELWVQ/TCIJ+LMKoIrS9O2FwMNwshA2pw/xdrgkTs1fCpE/xoS8a H6mCWANA5TJdGVgJhHUjNT2xOm/lLX6lvEzT3amZafewlb+kwOWDGLDREIwPtm6WDOEmWY3TWMAiz oa4nedZw==; Received: by zero.zsh.org with local id 1qy0bw-000MZs-Lt; Wed, 01 Nov 2023 02:05:36 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1qy0bM-000MHT-Ra; Wed, 01 Nov 2023 02:05:00 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1qy0bL-0008JY-0s; Wed, 01 Nov 2023 03:04:59 +0100 cc: Zsh workers In-reply-to: From: Oliver Kiddle References: <72311-1698710659.978677@cDMN.pAu_.Ex7V> To: Bart Schaefer Subject: Re: PATCH: pcre callouts MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31960.1698804298.1@hydra> Date: Wed, 01 Nov 2023 03:04:58 +0100 Message-ID: <31963-1698804298.865464@oYlZ.u4GW.p43I> X-Seq: 52263 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Bart Schaefer wrote: > You could actually use ${.pcre._} I suppose. I'm undecided on whether > that's better. That still needs braces which makes it harder to embed in a callout. Perhaps callouts are unlikely to be used other than with functions. If so, it might just as well be .pcre.subject. > > and should it perhaps start and end a new scope > > to make that local? > > We do have a precedent for that now with ${|...} creating a scope. The patch below tries this approach along with your suggestion of using PM_HIDE for $_. The shell's $_ is not a feature I use much so I may not be the best person to decide on whether it can be used here. > > This won't do anything for numeric callouts. They look mostly useful for > > debugging. They could perhaps call a standard function passing the > > number and string as parameters. > > What's an example of using a number callout outside of zsh? I'm not finding a whole lot of uses but it isn't entirely easy to search for. It's fairly common for projects to include the pcre sources directly within their own source tree so source code searches are just finding copies of the pcre test code. Some Windows scripting language called AutoHotKey uses them and has a pcre_callout function which you need to define. I found one other use which also looked like a language and also used a function. > I see you're calling parse_string() here: > > > + if (!block->callout_number && > > + ((prog = parse_string((char *) block->callout_string, 0)))) > > How are you solving the problem of finding the end of the callout? That's pcre's problem as it parses the regular expressions. It has always needed to parse callouts but without the patch, they are ignored. You can't really use the feature without using shell quoting for the whole regex. The [[ str =~ regex ]] form can be used without quoting to a limited extent but that appears to be looking for the matching ")" so seems sane enough. Oliver diff --git a/Src/Modules/pcre.c b/Src/Modules/pcre.c index e321f18a4..173ab4a69 100644 --- a/Src/Modules/pcre.c +++ b/Src/Modules/pcre.c @@ -138,11 +138,20 @@ pcre_callout(pcre2_callout_block_8 *block, void *) ((prog = parse_string((char *) block->callout_string, 0)))) { int ef = errflag, lv = lastval; + Param pm; + char *subject = metafy((char *) block->subject, + block->subject_length, META_DUP); - setsparam(".pcre.subject", - metafy((char *) block->subject, block->subject_length, META_DUP)); + startparamscope(); + if ((pm = createparam("_", PM_LOCAL|PM_HIDE|PM_UNSET))) { + pm->level = locallevel; + setsparam("_", ztrdup(subject)); + } + setsparam(".pcre.subject", subject); + setiparam(".pcre.pos", block->current_position + 1); execode(prog, 1, 0, "pcre"); ret = lastval | errflag; + endparamscope(); /* Restore any user interrupt error status */ errflag = ef | (errflag & ERRFLAG_INT);