Subject: Re: bug#62238: 30.0.50; Unusual interpretation of "S-expressions" in c-ts-mode

From: Juri Linkov <[email-masked]>
Date: Sun, 19 Mar 2023 19:28:58 +0200

>> > I don't understand how you came to that conclusion.  Why would we want
>> > to use syntax tables when we have a parser at our fingertips?  And if
>> > "the Tree-sitter function is general and should work for every
>> > language", as you say (and I agree), why should we refrain from using
>> > it for C?
>>
>> Note that basing C-M-x on syntax tables (that is, traditional
>> forward-sexp) does not completely exclude the use of Tree-sitter, AFAIU.
>> Here's my thought process: To do its job, C-M-x needs to know about some
>> code structures such as symbol constituents, strings, comments, and
>> parenthetical groups.  If in some language or future version of C the
>> syntax is complex enough that getting the syntax class of a character
>> requires proper parsing, the Tree-sitter major modes can augment the
>> syntax table to make C-M-x work correctly.  See
>> c-ts-mode--syntax-propertize for an example of how Tree-sitter can
>> augment a buffer's syntax table, if needed.
>
> We have already C mode that uses syntax tables.  I think it's useful
> to try syntactic movement using results of parsing as well, and
> compare the relative merits and demerits.

After trying to tweak treesit-sexp-type-regexp a few times
I become convinced it is not up to the task of properly handling
all sexp operations.  It seems the existing functions that
implement C-M-f (forward-sexp), C-M-u (backward-up-list), etc.
should remain in place, and the role of the tree-sitter would be
only to provide syntax information for them, i.e. just to replace
syntax tables with tree-sitter wrappers.