unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#54195: master 15a76160bb: Don't throw errors while propertizing in sgml-mode
       [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
  2022-03-01 15:15     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-02-28 14:44 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 54195

>     * 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






^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#54195: master 15a76160bb: Don't throw errors while propertizing in sgml-mode
  2022-02-28 14:44   ` bug#54195: master 15a76160bb: Don't throw errors while propertizing in sgml-mode Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-03-01 15:15     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2022-03-01 15:15 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 54195

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> 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`.

I assumed that people didn't normally get any erroring-out here because
these functions are normally called from font-locking, which catches
most errors.  When electric-pair-mode is used, the syntax functions are
called via a different code path that doesn't catch errors, so I thought
it'd make most sense to not call `error' from the code at all.

But yes, the parsing won't be correct.

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-01 15:15 UTC | newest]

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

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).