[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [External] : [PATCH] Interpret #r"..." as a raw string
From: |
Naoya Yamashita |
Subject: |
Re: [External] : [PATCH] Interpret #r"..." as a raw string |
Date: |
Sat, 27 Feb 2021 05:23:17 +0900 (JST) |
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.
- [PATCH] Interpret #r"..." as a raw string, Naoya Yamashita, 2021/02/26
- RE: [External] : [PATCH] Interpret #r"..." as a raw string, Drew Adams, 2021/02/26
- Re: [External] : [PATCH] Interpret #r"..." as a raw string, Naoya Yamashita, 2021/02/26
- RE: [External] : [PATCH] Interpret #r"..." as a raw string, Drew Adams, 2021/02/26
- Re: [External] : [PATCH] Interpret #r"..." as a raw string, Stefan Monnier, 2021/02/26
- Re: [External] : [PATCH] Interpret #r"..." as a raw string,
Naoya Yamashita <=
- Re: [External] : [PATCH] Interpret #r"..." as a raw string, Andreas Schwab, 2021/02/26
- Re: [External] : [PATCH] Interpret #r"..." as a raw string, Naoya Yamashita, 2021/02/26
- Re: [External] : [PATCH] Interpret #r"..." as a raw string, Andreas Schwab, 2021/02/26
- Re: [External] : [PATCH] Interpret #r"..." as a raw string, Naoya Yamashita, 2021/02/26
- Re: [External] : [PATCH] Interpret #r"..." as a raw string, Andreas Schwab, 2021/02/26
- Re: [External] : [PATCH] Interpret #r"..." as a raw string, Eli Zaretskii, 2021/02/26
- Re: [External] : [PATCH] Interpret #r"..." as a raw string, Naoya Yamashita, 2021/02/26
Re: [PATCH] Interpret #r"..." as a raw string, Andreas Schwab, 2021/02/26
Re: [PATCH] Interpret #r"..." as a raw string, Eli Zaretskii, 2021/02/26