From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#36237: Support (rx (and (regexp EXPR) (regexp-quote EXPR))) Date: Wed, 19 Jun 2019 17:42:57 +0200 Message-ID: References: <87fto9yawl.fsf@gmail.com> <385FA4F7-7FB5-43A2-B571-CFBA20B24123@acm.org> <87tvcmwe6b.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="232371"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Michael Heerdegen , 36237@debbugs.gnu.org, Stefan Monnier , kevin.legouguec@gmail.com To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jun 19 17:47:01 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hdcnb-000yK5-Gi for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Jun 2019 17:46:59 +0200 Original-Received: from localhost ([::1]:39642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcna-0007Xk-Eb for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Jun 2019 11:46:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47444) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdckm-0004yl-Oy for bug-gnu-emacs@gnu.org; Wed, 19 Jun 2019 11:44:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdckk-0005kf-VA for bug-gnu-emacs@gnu.org; Wed, 19 Jun 2019 11:44:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33755) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hdckk-0005hD-0e for bug-gnu-emacs@gnu.org; Wed, 19 Jun 2019 11:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hdckj-0000NG-S0 for bug-gnu-emacs@gnu.org; Wed, 19 Jun 2019 11:44:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Jun 2019 15:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36237 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 36237-submit@debbugs.gnu.org id=B36237.15609589871355 (code B ref 36237); Wed, 19 Jun 2019 15:44:01 +0000 Original-Received: (at 36237) by debbugs.gnu.org; 19 Jun 2019 15:43:07 +0000 Original-Received: from localhost ([127.0.0.1]:47299 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hdcjr-0000Lm-88 for submit@debbugs.gnu.org; Wed, 19 Jun 2019 11:43:07 -0400 Original-Received: from mail205c50.megamailservers.eu ([91.136.10.215]:38888 helo=mail193c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hdcjo-0000Lc-7C for 36237@debbugs.gnu.org; Wed, 19 Jun 2019 11:43:05 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1560958982; bh=KmUS+Z7B7iIAseU+7W1Rn2r5W+XLorZBbRhgDkc6GC8=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=lKpGjaUHzgLTA9+iGV7gmTHBALowCkA0c37hvYUiGl7tyYYIgkqDCrhVYVxCN65uU E5ZdB0M5l8BaxLPtY3ZkD7REJMU1R6wMDdW0FpJ64K6l4Ri57ZxXToYCnlYdCSYM4X wymxcIl+dZ7MJkjkAXHaLL2WBj1dbxxCLJjmfwxw= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.1.65] (c-e636e253.032-75-73746f71.bbcust.telenor.se [83.226.54.230]) (authenticated bits=0) by mail193c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x5JFgwI5007396; Wed, 19 Jun 2019 15:42:59 +0000 In-Reply-To: <87tvcmwe6b.fsf@gmail.com> X-Mailer: Apple Mail (2.3445.104.11) X-CTCH-RefID: str=0001.0A0B0213.5D0A5806.0038, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=PM8hB8iC c=1 sm=1 tr=0 a=M+GU/qJco4WXjv8D6jB2IA==:117 a=M+GU/qJco4WXjv8D6jB2IA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=pGLkceISAAAA:8 a=Z_9CyQLO4t7mDJ5I03IA:9 a=CjuIK1q_8ugA:10 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:160852 Archived-At: 19 juni 2019 kl. 03.34 skrev Noam Postavsky : >=20 > Sure. Here's the patch with regexp-quote change to literal, and > rx--compile-to-lisp renamed. I'll wait a bit more and push this = weekend > if there are no more comments. Thank you. Some comments: -;; (rx (and line-start (eval something-else))), statically or -;; (rx-to-string '(and line-start ,something-else)), dynamically. +;; (rx (and line-start (regexp something-else))), statically or +;; (rx-to-string `(and line-start ,something-else)), dynamically. With your patch, the rx-to-string example should no longer be = recommended, but eval is still of interest for compile-time = substitution. What about: ;; (rx (and line-start (eval something-else))), statically or ;; (rx (and line-start (regexp something-else))), dynamically. (extra points if you change `and' into `seq') + (cond ((stringp form) + (rx-group-if (cadr form) rx-parent)) + (rx--compile-to-lisp + ;; Always group non string forms, since we can't be sure they "non-string forms" +(defun rx-literal (form) + "Parse and produce code from FORM, which is `(literal STRING-EXP)'." + (cond ((stringp form) + ;; This is allowed(?), but makes little sense, you could just + ;; use STRING directly. Yes, I did the same in ry. Maybe `literal' should be disallowed entirely = in rx-to-string, since it's more likely to be a misunderstanding on the = user's part. =20 +(defun rx-subforms (subforms &optional parent regexp-op) REGEXP-OP is perhaps better named SEPARATOR? + (cl-mapcan (lambda (x) + (cons regexp-op (funcall listify x))) + (cdr subregexps)))) + (t (cl-mapcan listify subregexps))))) Any reason for using cl-mapcan instead of straight mapcan? Not that it matters much. +NO-GROUP non-nil means don't put shy groups around the result. +Note that unlike for the `rx' macro, subforms `literal' and +`regexp' will not accept non-string arguments (so (literal +STRING) becomes just a more verbose version of STRING)." Try not breaking the line inside (literal STRING).