unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Alan Mackenzie <acm@muc.de>
Cc: 43558@debbugs.gnu.org, "Mattias Engdegård" <mattiase@acm.org>
Subject: bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped.
Date: Thu, 24 Sep 2020 18:43:04 -0400	[thread overview]
Message-ID: <jwv3636n7b9.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20200924185031.GB4714@ACM> (Alan Mackenzie's message of "Thu, 24 Sep 2020 18:50:31 +0000")

>> > As already said, this is a(n ugly) workaround.  syntax.c should handle
>> > comments in all their generality.  With a bit of consideration, the
>> > method to do this is clear:
>> In my world, it's quite normal for a specific language's lexical rules
>> not to line up 100% with syntax tables (whether for strings, comments,
>> younameit).  I don't see anything very special here.
> Normally when there's a mismatch, it's because a character is
> syntactically ambiguous.  There's nothing syntax.c can do about this.

Oh, no, there are many more situations than just "a character is
syntactically ambiguous" (or alternatively you could argue that all
cases are "a character is syntactically ambiguous", including your cases
of escaped newline and escaped */).

>> A `syntax-propertize` rule for "\*/" should be very easy to implement
>> and fairly cheap since the regexp is simple and will almost never match.
> Well, the rule would actually be for escaped newlines,

It doesn't have to be if you set `comment-end-can-be-escaped` to non-nil,
in which case you only need to tweak the \*/ case, AFAICT.

> but this would be quite expensive (compared with a syntax.c solution)
> since every comment near a change region would need scanning at
> each change.

I don't know what you mean by scanning, but yes you'd need to search for
all "\\\\\n" or "\\\\\\*/" (depending on how you set
`comment-end-can-be-escaped) and mark the second char accordingly.
Seems pretty cheap in either case.

> I've hacked up a working, but as yet unsatisfactory, change to syntax.c.
> It is surely better, where possible, to fix bugs at their point of
> causation rather than by workarounds elsewhere.

I don't think it's a bug in `syntax.c`.  `syntax.c` is not defined to
support the syntax of C, it's only defined to handle a particular set of
comment and string styles, which correspond to a common subset of what
is in use in most languages, but IME most languages need some extra
tweaks handled via the `syntax-table` text property.  It's only
a question of time until we add a `syntax-propertize-function` for Elisp
mode to properly handle some corner cases, for example.

>> I do think it would be good to handle this without `syntax-table`
>> text-property hacks, but I think that should come with an overhaul of
>> syntax.c based on a major-mode provided DFA (or something like that) so
>> it can accommodate all the various oddball cases without even the need
>> to introduce the notion of escaping comment markers.
> That sounds almost more like a rewrite than an overhaul.

Tomato tomahto.

> We would need to make sure that this wouldn't run more slowly than the
> current syntax.c/Lisp combination.

I don't think that would be required, as long as it runs fast enough.
In any case, the resulting performance is probably not the main worry
(I suspect it will/would be easy to make it fast enough).


        Stefan






  reply	other threads:[~2020-09-24 22:43 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22  9:35 bug#43558: [PATCH]: Fix (forward-comment 1) when end delimiter is escaped Alan Mackenzie
2020-09-22 14:09 ` Stefan Monnier
2020-09-22 19:41   ` Alan Mackenzie
     [not found] ` <handler.43558.B.160076736116422.ack@debbugs.gnu.org>
2020-09-23  8:57   ` Alan Mackenzie
2020-09-23  9:01 ` Mattias Engdegård
2020-09-23 14:48   ` Alan Mackenzie
2020-09-23 18:44     ` Stefan Monnier
2020-09-23 19:44       ` Alan Mackenzie
2020-09-23 20:02         ` Stefan Monnier
2020-09-24 10:20       ` Alan Mackenzie
2020-09-24 16:56         ` Stefan Monnier
2020-09-24 18:50           ` Alan Mackenzie
2020-09-24 22:43             ` Stefan Monnier [this message]
2020-11-19 21:18           ` Alan Mackenzie
2020-11-19 22:47             ` Stefan Monnier
2020-11-22 13:12               ` Alan Mackenzie
2020-11-22 15:20                 ` Stefan Monnier
2020-11-22 17:08                   ` Alan Mackenzie
2020-11-22 17:46                     ` Dmitry Gutov
2020-11-22 18:19                       ` Alan Mackenzie
2020-11-22 20:39                         ` Dmitry Gutov
2020-11-22 21:13                           ` Alan Mackenzie
2020-11-22 21:34                             ` Dmitry Gutov
2020-11-22 22:01                               ` Alan Mackenzie
2020-11-22 23:00                                 ` Stefan Monnier
2021-05-13 10:38                                   ` Lars Ingebrigtsen
2021-05-13 14:51                                     ` Alan Mackenzie
2021-05-16 13:53                                       ` Lars Ingebrigtsen
2022-04-28 11:17                                       ` Lars Ingebrigtsen
2022-04-28 18:52                                         ` Alan Mackenzie
2020-11-22 23:10                     ` Stefan Monnier
2020-11-22 15:35                 ` Eli Zaretskii
2020-11-22 17:03                   ` Alan Mackenzie
2020-09-24 18:52     ` Michael Welsh Duggan
2020-09-24 19:57       ` Alan Mackenzie
2020-09-24 20:27         ` Michael Welsh Duggan

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=jwv3636n7b9.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=43558@debbugs.gnu.org \
    --cc=acm@muc.de \
    --cc=mattiase@acm.org \
    /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).