unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: "Simen Heggestøyl" <simenheg@runbox.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
	53203@debbugs.gnu.org, Colin <my.old.email.sucked@gmail.com>
Subject: bug#53203: Comment with lots of color codes crashes or hangs emacs in scss-mode
Date: Sat, 14 May 2022 14:38:21 +0200	[thread overview]
Message-ID: <87czggl26a.fsf@gnus.org> (raw)
In-Reply-To: <87mtfks8r2.fsf@runbox.com> ("Simen Heggestøyl"'s message of "Sat, 14 May 2022 12:34:25 +0200")

OK, I think I understand most of the regexp now, but it's a strange mix
of strictness and sloppiness.

    (,(concat
       "^[ \t]*\\("
       (if (not sassy)
           ;; We don't allow / as first char, so as not to
           ;; take a comment as the beginning of a selector.
           "[^@/:{}() \t\n][^:{}()]*"
         ;; Same as for non-sassy except we do want to allow { and }
         ;; chars in selectors in the case of #{$foo}
         ;; variable interpolation!
         (concat "\\(?:" scss--hash-re
                 "\\|[^@/:{}() \t\n#]\\)"
                 "[^:{}()#]*\\(?:" scss--hash-re "[^:{}()#]*\\)*"))
       ;; Even though pseudo-elements should be prefixed by ::, a
       ;; single colon is accepted for backward compatibility.
       "\\(?:\\(:" (regexp-opt (append css-pseudo-class-ids
                                       css-pseudo-element-ids)
                               t)
       "\\|::" (regexp-opt css-pseudo-element-ids t) "\\)"
       "\\(?:([^)]+)\\)?"

First we work really hard to see whether we have something that looks
like a selector, i.e. a line that starts with,

p
p::after
p:active

or in the scss case

p#{foo}:active


and then we allow any kind of junk for the rest of the line, like

p.a *[line noise]* p.b {
}

with this bit:

     (if (not sassy)
           "[^:{}()\n]*"
         (concat "[^:{}()\n#]*\\(?:" scss--hash-re "[^:{}()\n#]*\\)*"))
       "\\)*"
       "\\)\\(?:\n[ \t]*\\)*{")
     (1 'css-selector keep))


Anyway, I still don't grok this bit:

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

That is, we're matching an scss/css selector first, and then...
possibly another one?  Which we're doing later, anyway.

So just getting rid of that bit seems to lead to the same highlighting
(and gets rid of the original reported problem).  But like I said, I
don't understand quite what it's trying to do there.  Can anybody come
up with an scss example this breaks?

diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 1139fd1976..fd47a7b83b 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -953,14 +953,13 @@ css--font-lock-keywords
          ;; chars in selectors in the case of #{$foo}
          ;; variable interpolation!
          (concat "\\(?:" scss--hash-re
-                 "\\|[^@/:{}() \t\n#]\\)"
-                 "[^:{}()#]*\\(?:" scss--hash-re "[^:{}()#]*\\)*"))
+                 "\\|[^@/:{}() \t\n][^:{}()]\\)*"))
        ;; Even though pseudo-elements should be prefixed by ::, a
        ;; single colon is accepted for backward compatibility.
        "\\(?:\\(:" (regexp-opt (append css-pseudo-class-ids
                                        css-pseudo-element-ids)
                                t)
-       "\\|::" (regexp-opt css-pseudo-element-ids t) "\\)"
+       "\\|::" (regexp-opt css-pseudo-element-ids t) "\\)?"
        "\\(?:([^)]+)\\)?"
        (if (not sassy)
            "[^:{}()\n]*"



-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no






  parent reply	other threads:[~2022-05-14 12:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-12  7:20 bug#53203: Comment with lots of color codes crashes or hangs emacs in scss-mode Colin
2022-01-12 13:16 ` Eli Zaretskii
2022-01-13  7:00   ` Lars Ingebrigtsen
2022-01-13  8:58     ` Eli Zaretskii
2022-05-14 10:34     ` Simen Heggestøyl
2022-05-14 12:02       ` Lars Ingebrigtsen
2022-05-14 12:38       ` Lars Ingebrigtsen [this message]
2022-05-14 13:30         ` Lars Ingebrigtsen
2022-05-14 15:33           ` Lars Ingebrigtsen
2022-05-15 10:45             ` Simen Heggestøyl
2022-05-15 12:14               ` Lars Ingebrigtsen
2022-05-15 14:46                 ` Simen Heggestøyl

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87czggl26a.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=53203@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=my.old.email.sucked@gmail.com \
    --cc=simenheg@runbox.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).