From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Naoya Yamashita Newsgroups: gmane.emacs.devel Subject: Re: [External] : [PATCH] Interpret #r"..." as a raw string Date: Sat, 27 Feb 2021 05:23:17 +0900 (JST) Message-ID: <20210227.052317.1484421240960012901.conao3@gmail.com> References: <20210227.035336.1133463788176884588.conao3@gmail.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20868"; mail-complaints-to="usenet@ciao.gmane.io" Cc: drew.adams@oracle.com, emacs-devel@gnu.org To: monnier@iro.umontreal.ca Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Feb 26 21:24: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 1lFjek-0005HT-4l for ged-emacs-devel@m.gmane-mx.org; Fri, 26 Feb 2021 21:24:10 +0100 Original-Received: from localhost ([::1]:42794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lFjei-0005JY-SG for ged-emacs-devel@m.gmane-mx.org; Fri, 26 Feb 2021 15:24:08 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFjeC-0004sM-3j for emacs-devel@gnu.org; Fri, 26 Feb 2021 15:23:36 -0500 Original-Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:44136) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lFje8-0001Iv-Ut for emacs-devel@gnu.org; Fri, 26 Feb 2021 15:23:35 -0500 Original-Received: by mail-pf1-x430.google.com with SMTP id t29so6995944pfg.11 for ; Fri, 26 Feb 2021 12:23:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-transfer-encoding; bh=l4kJo6kvzjqZ46OHlrhUjYSe3+DhQswp62x/Pjje48E=; b=MsNnfSzKsb/hnLPPLD/ppCGRcgThrl1CTXc/dVVkfM+IQ2kyC7PfGFh2y0YuCgXZCo iPl4SW5Ykm5YVjVWq5z0/JgKKE+u1grZI9lKO7jce89ZX+ZRY+dyBeKibufjJc2PFs9c S60V0Zn2sk13elxSUTZA+hJFDE2HpnDnfosyil/pN7AABxuK7wSTZYMtjsoDni4pHw+L XVsrjx8opABEsSXoPDLA2dg6+4nCzmLLIJEt2T5SpAipdb4jRzsNwWvo+UC3JJrJP8Uu 0/mDdXee6vxKOV8Wgu8XvIbfMtCPFn/qkfEX3Lr1HoxWpehf121bRiIKru8ysV98rKcl T5jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:mime-version:content-transfer-encoding; bh=l4kJo6kvzjqZ46OHlrhUjYSe3+DhQswp62x/Pjje48E=; b=oITnIL9V6DKBhMq0z8VJ8Gq0t05mN3UUYMO9RkLK5COGLqJV2a3jyj4pSQN1YFaxnx KypPBRirtNjhoeEC+6Prh2zsfAccq5KC29wnLVQyN+jONnl4eukW+IwHFhyq3zlvvrPN mCsYcU/EUSZpQd83O9Lpr9+wgJy/tJU+hVUeOfYT7GkT5gNtAyGBSuZTf8Sl20uMcLkp iuNFtMJ68PArR75QfXzJ8cXcmVzG+gQM8/5cc20pLp+S2fyZUoMvQAVC8bdSPXs1xiWF 0wi0FFmPSOdXD//PtYj7JSdlQGF646gDUF+mXHg2pHwHI7s0AeYsjTsnR6QMZupff3J1 3KIg== X-Gm-Message-State: AOAM530N8jE4D7MwDJ0fP+OG47WIMV+YCKeM7UsvGdLJis527cRT2T52 IaoPCrydmTnxfnWQW70aQ/A= X-Google-Smtp-Source: ABdhPJwMFRz2j0LYEhMNVzqb3pT/ipfvWl2XWvE99YOMp5hawaGFm48y4jMXMbItRpeal9w9LXPX6g== X-Received: by 2002:a05:6a00:7c9:b029:1ee:5346:8f04 with SMTP id n9-20020a056a0007c9b02901ee53468f04mr511769pfu.69.1614371010621; Fri, 26 Feb 2021 12:23:30 -0800 (PST) Original-Received: from localhost (p210141-ipngn200407niho.hiroshima.ocn.ne.jp. [118.4.79.141]) by smtp.gmail.com with ESMTPSA id cv3sm6080182pjb.9.2021.02.26.12.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Feb 2021 12:23:30 -0800 (PST) In-Reply-To: X-Mailer: Mew version 6.8 on Emacs 27.1 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=conao3@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:265699 Archived-At: Thanks Stefan, >> (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". ] I think it has no bug, all test I introduce is passed by my patched Emacs. the raw-string regexp equivalent to "(\\(def\\\\macro\\) \\([^ ]+\\)" is #r"(\(def\\macro\) \([^ ]+\) Yes, I agree, but notice the double backslash between "def" and "macro". I have question on it. You 'see' double backslash between "def" and "macro" but actually one backslash is placed between "def" and "macro" If I wrote test string with raw-string notation, it shold be below. (should (equal (let ((str #r"(def\macro leaf () nil)")) (string-match #r"(\(def\macro\) \([^ ]+\)" str) (list (match-string 1 str) (match-string 2 str))) '(#r"def\macro" "leaf"))) Wow, this is easy to understand. We can now write the matching string as a literal as is! > 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). As my understanding, macro is not useful to allow raw-string notion. We need reader-macro instead? But we don't have a reader-macro in Elisp. I think it is better by introducing reader-macro and making the reader user-extensible, it would be a straightforward way to define this raw-string notation in user-space, but the job was too big, so I added just this process to the reader. > IOW, I think regexps are a poor motivation to introduce raw strings. Thanks, but many language support this sort of notation to easy write string literal without thinking any escape. I want to still want to use also in Elisp.