Subject: bug#53203: Comment with lots of color codes crashes or hangs emacs in scss-mode

From: Simen Heggestøyl <[email-masked]>
Date: Sat, 14 May 2022 12:34:25 +0200

Lars Ingebrigtsen <[email-masked]> writes:

> But then we get:
>
>        "\\(?:([^)]+)\\)?"
>        (if (not sassy)
>            "[^:{}()\n]*"
>          (concat "[^:{}()\n#]*\\(?:" scss--hash-re "[^:{}()\n#]*\\)*"))
>        "\\)*"
>
> Which is a whole lot of backtracking, presumably exacerbated by the
> previous ids bit of the regexp.

By the ancient scientific method of commenting out code, it seems to me
that the culprit is rather the last group of the regexp starting on
line 955:

  (concat "\\(?:" scss--hash-re
          "\\|[^@/:{}() \t\n#]\\)"
          "[^:{}()#]*\\(?:" scss--hash-re "[^:{}()#]*\\)*"))

That is, this part:

  \\(?:" scss--hash-re "[^:{}()#]*\\)*

Though I'm rather clueless on how proceed debugging/optimizing it. 😕

> But I've repressed all I once knew about the scss language -- what is
> it really trying to match here?  Anybody?

It's supposed to match selectors like the one on line 39 in
test/manual/indent/scss-mode.scss:

  p.#{$name} var