unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Naoya Yamashita <conao3@gmail.com>
To: monnier@iro.umontreal.ca
Cc: drew.adams@oracle.com, emacs-devel@gnu.org
Subject: Re: [External] : [PATCH] Interpret #r"..." as a raw string
Date: Sat, 27 Feb 2021 05:23:17 +0900 (JST)	[thread overview]
Message-ID: <20210227.052317.1484421240960012901.conao3@gmail.com> (raw)
In-Reply-To: <jwvpn0maa6w.fsf-monnier+emacs@gnu.org>

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.



  reply	other threads:[~2021-02-26 20:23 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-26 18:18 [PATCH] Interpret #r"..." as a raw string Naoya Yamashita
2021-02-26 18:27 ` [External] : " Drew Adams
2021-02-26 18:53   ` Naoya Yamashita
2021-02-26 19:03     ` Drew Adams
2021-02-26 19:48     ` Stefan Monnier
2021-02-26 20:23       ` Naoya Yamashita [this message]
2021-02-26 20:34         ` Andreas Schwab
2021-02-26 20:39           ` Naoya Yamashita
2021-02-26 20:45             ` Andreas Schwab
2021-02-26 20:50               ` Naoya Yamashita
2021-02-26 20:54                 ` Andreas Schwab
2021-02-26 20:03     ` Eli Zaretskii
2021-02-26 20:34       ` Naoya Yamashita
2021-02-26 19:09 ` Andreas Schwab
2021-02-26 20:00 ` Eli Zaretskii
2021-02-27  0:39   ` Daniel Brooks
2021-02-27 16:14     ` Richard Stallman
2021-02-27 16:18       ` Stefan Monnier
2021-03-01  5:19         ` Richard Stallman
2021-03-02  5:45           ` Matt Armstrong
2021-03-03  5:53             ` Richard Stallman
2021-03-03  6:14               ` Daniel Brooks
2021-03-03  7:00               ` Eli Zaretskii
2021-03-04  2:47                 ` Matt Armstrong
2021-03-04 13:49                   ` Eli Zaretskii
2021-03-04 16:55                     ` Matt Armstrong
2021-03-05  5:44                       ` Richard Stallman
2021-03-05  5:39                   ` Richard Stallman
2021-03-05  8:01                     ` Eli Zaretskii
2021-03-06  5:13                       ` Richard Stallman
2021-03-06  6:04                         ` Matt Armstrong
2021-03-07  6:13                           ` Richard Stallman
2021-03-07 17:20                             ` [External] : " Drew Adams
2021-03-06  8:27                         ` Eli Zaretskii
2021-03-06  9:51                           ` Daniel Brooks
2021-03-06 10:24                             ` Eli Zaretskii
2021-03-07  6:08                           ` Richard Stallman
2021-02-27 20:41       ` Daniel Brooks
2021-02-28  6:22 ` Zhu Zihao
2021-03-01  5:26   ` Richard Stallman
2021-03-01 12:06 ` Alan Mackenzie
2021-03-01 12:13   ` Andreas Schwab
2021-03-02  5:59   ` Matt Armstrong
2021-03-02  9:56     ` Daniel Brooks
2021-03-02 10:13       ` Andreas Schwab
2021-03-02 10:55         ` Daniel Brooks
2021-03-02 11:18           ` Andreas Schwab
2021-03-02 11:26             ` Daniel Brooks
2021-03-02 11:14       ` Alan Mackenzie
2021-03-02 11:52         ` Daniel Brooks
2021-03-02 12:01     ` Dmitry Gutov
2021-03-02 14:14       ` Alan Mackenzie
2021-03-02 14:32         ` Dmitry Gutov
2021-03-02 15:06           ` Alan Mackenzie
2021-03-02 11:41 ` Aurélien Aptel
2021-03-02 13:49   ` Stefan Monnier
2021-03-02 14:46     ` Aurélien Aptel
2021-03-02 15:11       ` Stefan Monnier
2021-03-02 16:07         ` Aurélien Aptel
2021-03-03  7:31           ` Alfred M. Szmidt
2021-03-03 16:02           ` Stefan Monnier
2021-03-02 20:36     ` Daniel Brooks
2021-03-03  0:27       ` Stefan Monnier
2021-03-03  0:42         ` Daniel Brooks
2021-03-03  8:16       ` Andreas Schwab
2021-03-03  9:25         ` Daniel Brooks
2021-03-03  9:29           ` Andreas Schwab
2021-03-03 10:02             ` Daniel Brooks
2021-03-03 10:11               ` Daniel Brooks
2021-03-03 10:14                 ` Andreas Schwab
2021-03-03 11:48                   ` Daniel Brooks
2021-03-03 10:12       ` Michael Albinus
2021-03-03 10:42         ` Daniel Brooks
2021-03-03 10:49           ` Michael Albinus
2021-03-03 16:12           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210227.052317.1484421240960012901.conao3@gmail.com \
    --to=conao3@gmail.com \
    --cc=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).