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: [External] : [PATCH] Interpret #r"..." as a raw string Date: Fri, 26 Feb 2021 14:48:02 -0500 Message-ID: References: <20210227.031857.1351840144740816188.conao3@gmail.com> <20210227.035336.1133463788176884588.conao3@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25199"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: drew.adams@oracle.com, emacs-devel@gnu.org To: Naoya Yamashita Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Feb 26 20:49:12 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 1lFj6t-0006SR-QA for ged-emacs-devel@m.gmane-mx.org; Fri, 26 Feb 2021 20:49:11 +0100 Original-Received: from localhost ([::1]:42124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lFj6s-0007kO-Sd for ged-emacs-devel@m.gmane-mx.org; Fri, 26 Feb 2021 14:49:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFj5t-00074B-QP for emacs-devel@gnu.org; Fri, 26 Feb 2021 14:48:09 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:25852) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFj5r-0002Gg-MB for emacs-devel@gnu.org; Fri, 26 Feb 2021 14:48:09 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id CA37480159; Fri, 26 Feb 2021 14:48:05 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D0E0180229; Fri, 26 Feb 2021 14:48:03 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1614368883; bh=BvjKes0RWrLd9DG/cfLq1zmWex6btlqWiNhVMo65IFc=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=O5Ps4nW/e+l11ZjLfaCc7TtKL2+7NPFRBbHCl+1R+hJST9qFsVVY1CxPC0yKA8xum t5tQxZ2xK/O8Rj/olyp5whkWWNVlo7aTDtTLE2BYL0Gh9SJ1OsUIuS4TLyFqDqhEv0 LF6YR4ph1YTMlqpTJ3M30jd/+x8Y5lp/mASC+ke/rN0q6jN/m1NoJoKIHkC/ZVT/Np LYt7p58wDK7O0gGQeNTWY1Tstfom5BTfl7v35v/Tzk9uvzATZfjhy7h+BQRpDeYB9R kgjBBxm8ZzGN9x3urT/EwySQVsSfnnUTvMKLemgJZIhHIXpT+YdGsdPP6ty9KFm+FC h1rXKecwQuQ0Q== Original-Received: from alfajor (unknown [216.154.41.47]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 18B6C12022D; Fri, 26 Feb 2021 14:48:03 -0500 (EST) In-Reply-To: <20210227.035336.1133463788176884588.conao3@gmail.com> (Naoya Yamashita's message of "Sat, 27 Feb 2021 03:53:36 +0900 (JST)") 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:265693 Archived-At: > (ert-deftest lread-raw-string-usage-2 () > (should (equal > (let ((str "(def\\macro leaf () nil)")) > (string-match "(\\(def\\\\macro\\) \\([^ ]+\\)" str) > (list (match-string 1 str) (match-string 2 str))) > '("def\\macro" "leaf"))) > > (should (equal > (let ((str "(def\\macro leaf () nil)")) > (string-match #r"(\(def\macro\) \([^ ]+\)" str) > (list (match-string 1 str) (match-string 2 str))) > '("def\\macro" "leaf")))) [ Note the above has a bug: the raw-string regexp equivalent to "(\\(def\\\\macro\\) \\([^ ]+\\)" is #r"(\(def\\macro\) \([^ ]+\)" notice the double backslash between "def" and "macro". ] For regexps, this has been discussed to death already, but a better option is arguably to introduce a macro that converts from the non-backslashed regexp style to the backslashed regexp style. That would require even fewer backslashes in most cases (tho not in this example because of the presence of a literal \ in the regexp). (should (equal (let ((str "(def\\macro leaf () nil)")) (string-match (re "\\((def\\\\macro) ([^ ]+)" str) (list (match-string 1 str) (match-string 2 str))) '("def\\macro" "leaf")))) IOW, I think regexps are a poor motivation to introduce raw strings. Stefan