unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 54195@debbugs.gnu.org
Subject: bug#54195: master 15a76160bb: Don't throw errors while propertizing in sgml-mode
Date: Mon, 28 Feb 2022 09:44:01 -0500	[thread overview]
Message-ID: <jwvh78jxdxe.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20220228093109.81A17C0DA33@vcs2.savannah.gnu.org> (Lars Ingebrigtsen's message of "Mon, 28 Feb 2022 04:31:09 -0500 (EST)")

>     * lisp/textmodes/sgml-mode.el (sgml-syntax-propertize): Don't
>     throw an error when propertizing (bug#54195).
> ---
>  lisp/textmodes/sgml-mode.el | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
> index 83631e6475..b49541f47d 100644
> --- a/lisp/textmodes/sgml-mode.el
> +++ b/lisp/textmodes/sgml-mode.el
> @@ -419,11 +419,11 @@ These have to be run via `sgml-syntax-propertize'"))
>  (defun sgml-syntax-propertize (start end &optional rules-function)
>    "Syntactic keywords for `sgml-mode'."
>    (setq sgml--syntax-propertize-ppss (cons start (syntax-ppss start)))
> -  (cl-assert (>= (cadr sgml--syntax-propertize-ppss) 0))
> -  (sgml-syntax-propertize-inside end)
> -  (funcall (or rules-function sgml--syntax-propertize) (point) end)
> -  ;; Catch any '>' after the last quote.
> -  (sgml--syntax-propertize-ppss end))
> +  (when (>= (cadr sgml--syntax-propertize-ppss) 0)
> +    (sgml-syntax-propertize-inside end)
> +    (funcall (or rules-function sgml--syntax-propertize) (point) end)
> +    ;; Catch any '>' after the last quote.
> +    (sgml--syntax-propertize-ppss end)))

Hmm... this isn't right.

The PPSS really shouldn't have a negative value here.  The problem is
that when we do as in the recipe (which does not require
`electric-pair-mode` to reproduce), mhtml calls `sgml-syntax-propertize`
on the `</script>` tag and the `syntax-ppss` call returns the state of
the JS parsing at the end of the JS code rather than the state of the
SGML parsing at the beginning of the tag.

IOW it's a bug in the interaction between `mhtml` and `syntax-ppss`.

To illustrate the problem in a way which doesn't signal an error, try
the following:

    "foo
    <script>
      foo()
    </script>
    "bar
    <foo "hello">

as you can see, the SGML part carefully ignores the " thingies outside
of quotes.  Now remove the closing paren in the JS code: suddenly the
SGML code is all confused because it thinks everything after the open
paren is inside of a tag (because the SGML mode gives paren syntax to <
and > (but not to parens) and uses the paren depth to decide whether
we're inside a tag or not).


        Stefan






       reply	other threads:[~2022-02-28 14:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <164604066920.6274.17125818957525062942@vcs2.savannah.gnu.org>
     [not found] ` <20220228093109.81A17C0DA33@vcs2.savannah.gnu.org>
2022-02-28 14:44   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-03-01 15:15     ` bug#54195: master 15a76160bb: Don't throw errors while propertizing in sgml-mode Lars Ingebrigtsen

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=jwvh78jxdxe.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=54195@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --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 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).