From: phs <phs@lsv.fr>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: Michael Heerdegen <michael_heerdegen@web.de>,
Stefan Monnier <monnier@iro.umontreal.ca>,
emacs-devel@gnu.org
Subject: Re: More re odditie [Was: regular expressions that match nothing]
Date: Thu, 16 May 2019 12:59:19 +0200 [thread overview]
Message-ID: <4f88e61c-77d0-96fd-9deb-c35686757c99@lsv.fr> (raw)
In-Reply-To: <ABAFE6B8-9CAE-4CEA-A516-6A636CAA1132@acm.org>
[-- Attachment #1: Type: text/plain, Size: 1205 bytes --]
Hi Mattias,
On 2019/05/16 11:29, Mattias Engdegård wrote:
> 16 maj 2019 kl. 08.57 skrev phs <phs@lsv.fr>:
> Actually this one is documented:
>
> For historical compatibility, special characters are treated as ordinary
> ones if they are in contexts where their special meanings make no sense.
> For example, `*foo' treats `*' as ordinary since there is no preceding
> expression on which the `*' can act.
I missed that. Thanks for pointing it out.
> and in any case the 'correct' behaviour would be to signal a syntax error, not repeat the empty string.
I'd rather read `*' as meaning "repeat the empty string", as with
`\(\)*', but this is a matter of taste, and historical compatibility is
very important.
BTW, can your scans of regexps tell if this compatibility is relied on a
lot? It would be safe to replace `*' and `+' with `\*' and `\+' where
this happens. I've just grep'ed quickly through the code and only
noticed a risky use of "+" (and "[..]") in the definition of `term-word'
in term.el
> Thanks for reporting it, and you are right, that's a (known) bug in rx.
When rx is fixed, I suggest we add the following extra tests (see patch)
--phs
[-- Attachment #2: more-rx-tests.patch --]
[-- Type: text/plain, Size: 875 bytes --]
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el
index 4a5919edf0..373bc9b2e3 100644
--- a/test/lisp/emacs-lisp/rx-tests.el
+++ b/test/lisp/emacs-lisp/rx-tests.el
@@ -109,5 +109,16 @@
(match-string 0 s))
"a"))))
+(ert-deftest rx-kleene-empty-string ()
+ ;; Test whether the repetition of empty string --that matches everywhere-- is handled correctly
+ (should (string-match (rx (zero-or-more "")) "foo"))
+ (should (string-match (rx (one-or-more "")) "foo")))
+
+(ert-deftest rx-kleene-unmatchable ()
+ ;; Test whether the repetition of regexp-unmatchable is handled correctly
+ (should (string-match (rx (zero-or-more (or))) "foo"))
+ (should-not (string-match (rx (or)) "foo"))
+ (should-not (string-match (rx (one-or-more (or))) "+")))
+
(provide 'rx-tests)
;; rx-tests.el ends here.
next prev parent reply other threads:[~2019-05-16 10:59 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 7:25 regular expressions that match nothing philippe schnoebelen
2019-05-14 10:14 ` Mattias Engdegård
2019-05-14 19:41 ` Stefan Monnier
2019-05-15 16:21 ` Mattias Engdegård
2019-05-15 19:41 ` Alan Mackenzie
2019-05-16 10:54 ` Mattias Engdegård
2019-05-16 23:18 ` Phil Sainty
2019-05-17 9:43 ` Alan Mackenzie
2019-05-17 10:17 ` Mattias Engdegård
2019-05-17 12:53 ` Stefan Monnier
2019-05-15 20:17 ` Michael Heerdegen
2019-05-15 21:06 ` Stefan Monnier
2019-05-15 21:07 ` Mattias Engdegård
2019-05-15 21:38 ` Michael Heerdegen
2019-05-16 6:57 ` More re odditie [Was: regular expressions that match nothing] phs
2019-05-16 9:29 ` Mattias Engdegård
2019-05-16 10:59 ` phs [this message]
2019-05-16 12:31 ` Stefan Monnier
2019-05-16 18:35 ` Michael Heerdegen
2019-05-16 20:31 ` Mattias Engdegård
2019-05-16 21:01 ` Global and local definitions of non-functions/variable (was: More re odditie [Was: regular expressions that match nothing]) Stefan Monnier
2019-05-20 16:26 ` Bootstrap/autoload policy (was Re: regular expressions that match nothing) Mattias Engdegård
2019-05-22 14:02 ` Stefan Monnier
2019-05-22 14:07 ` Mattias Engdegård
2019-05-22 14:24 ` Stefan Monnier
2019-05-22 15:06 ` Mattias Engdegård
2019-05-22 15:53 ` Stefan Monnier
2019-05-22 16:40 ` Mattias Engdegård
2019-05-22 19:08 ` Stefan Monnier
2019-05-26 12:05 ` Basil L. Contovounesios
2019-05-16 18:12 ` regular expressions that match nothing Eric Abrahamsen
2019-05-19 4:30 ` 回复: " net june
2019-05-19 5:00 ` HaiJun Zhang
2019-05-19 7:32 ` Mattias Engdegård
2019-05-20 7:56 ` philippe schnoebelen
2019-05-20 23:19 ` Richard Stallman
2019-05-19 14:12 ` 回复: " Drew Adams
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f88e61c-77d0-96fd-9deb-c35686757c99@lsv.fr \
--to=phs@lsv.fr \
--cc=emacs-devel@gnu.org \
--cc=mattiase@acm.org \
--cc=michael_heerdegen@web.de \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.