emacs-devel
[Top][All Lists]
Advanced

[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 03:53:36 +0900 (JST)

Thanks drew,

> Why?  Is the reason just because "many programming
> languages" have a raw-string data type?  Why would
> that, by itself, be a good reason for Emacs Lisp
> to have such a data type?

> I'm guessing you have some other reasons.  What?

As my understanding, raw-string is not a data type, but a
notation that does not interpret escape sequences as written by
the user.

Please see backslash info[^1].  This is a reason to support raw string.

    Note that ‘\’ also has special meaning in the read syntax of Lisp
    strings (see String Type), and must be quoted with ‘\’. For
    example, the regular expression that matches the ‘\’ character is
    ‘\\’. To write a Lisp string that contains the characters ‘\\’,
    Lisp syntax requires you to quote each ‘\’ with another
    ‘\’. Therefore, the read syntax for a regular expression matching
    ‘\’ is "\\\\".

If we have a raw-string notation, we can write string as is
without any escape.

See this testcase,

    (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"))))

First one is normal Emacs-lisp, if you want to match `\`, you
should write `\\\\` as info say.  Second one uses raw-string
notaion I introduce, if you want to match `\`, you can write just `\`.

[^1]: 
https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Special.html#Regexp-Special

reply via email to

[Prev in Thread] Current Thread [Next in Thread]