Subject: bug#69714: [PATCH] Improve ert-font-lock assertion parser

From: Mattias Engdegård <[email-masked]>
Date: Sat, 30 Mar 2024 13:52:05 +0100

Vladimir, thank you for your patch. However, this regexp:

> (defconst ert-font-lock--face-symbol-re
>   (rx (one-or-more (or alphanumeric "-" "_" ".")))
>   "A face symbol matching regex.")
> 
> (defconst ert-font-lock--face-symbol-list-re
>   (rx "("
>       (* whitespace)
>       (one-or-more
>        (seq (regexp ert-font-lock--face-symbol-re)
>             (* whitespace)))
>       ")")
>   "A face symbol list matching regex.")

is rather inefficient. (Relint complained about it, which is why I am here).

The problem is that

      (one-or-more
       (seq (one-or-more (or alphanumeric "-" "_" "."))
            (* whitespace)))

can match a string that consists of alphanumeric characters, say, in many different ways because of the nested `one-or-more`; the (* whitespace) can match the empty string anywhere.
Try, for instance:

  (string-match ert-font-lock--face-symbol-list-re
                (concat "(" (make-string 20 ?a)))

which should return nil as it doesn't match.
Now try raising the number from 20 to 25, then 30.

If you want the regexp to match a list of one or more symbols, what about this:

  (rx "("
      (* whitespace)
      (regexp ert-font-lock--face-symbol-re)
      (* (+ whitespace)
         (regexp ert-font-lock--face-symbol-re))
      ")")