[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [elpa] externals/xr e77aa97: Postfix ops are literal after ^ but not
From: |
Mattias Engdegård |
Subject: |
Re: [elpa] externals/xr e77aa97: Postfix ops are literal after ^ but not after \(?:^\) |
Date: |
Tue, 19 Feb 2019 22:05:52 +0100 |
19 feb. 2019 kl. 21.29 skrev Stefan Monnier <address@hidden>:
>
>> Postfix ops are literal after ^ but not after \(?:^\)
>
> BTW, some of those details of the syntax of regexps are really
> undesirable. Would it be possible for xr to flag them somehow to try
> and discourage their use?
>
> Of course, even better would be to flag such uses not only in xr but
> more generally. I'm thinking for example of a regexp that starts with
> a postfix operator or that backslash-escapes a non-special character.
The xr machinery could probably be reused for that sort of linting, yes, but
whether it's a good place depends on how we want to use it. It could be used in
static linting of regexps in elisp string literals, but with false positives
and negatives. Putting it in regex-emacs.c would allow for exact detection but
only of those actually used during execution.
By the way, the reason for fixing this rather minor bug in xr, apart from
general perfectionism, was a bug in rx: bol and eol are unconditionally
translated to ^ and $ no matter where they occur. For example:
(rx "a" bol "b" eol "c")
=>
"a^b$c" (which means literally "a^b$c")
(rx (zero-or-more bol))
=>
"^*" (which means literally "^*")
rx should bracket the ^$ stuff and generate something like
"a\\(?:^\\)b\\(?:$\\)c" and "\\(?:^\\)*".