emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More Tree Sitter Questions / Problems.


From: Yuan Fu
Subject: Re: More Tree Sitter Questions / Problems.
Date: Wed, 14 Dec 2022 15:48:10 -0800


> On Dec 14, 2022, at 3:22 PM, Perry Smith <pedz@easesoftware.com> wrote:
> 
> 
> 
>> On Dec 14, 2022, at 15:15, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> 
>>> foodog = 12 + 4 *
>>>    18 * 99 + 8
>> 
>> [ Trying to provide some SMIE perspective:  ]
>> 
>> In the context of sh-mode, I've had requests to provide that kind of
>> "AST-oblivious" indentation.  The result is controlled by
>> `sh-indent-after-continuation`.
>> 
>>> variable = 12 + 4 *
>>>                18 * 99 + 8
>> 
>> That's my favorite, yes.
> 
> You might be misunderstanding my concern (but I do appreciate all of your 
> examples and thoughts).
> 
> My concern is if Tree Sitter modes deviate too much from the old way, they 
> may not catch on.  Perhaps I should not worry about that.  The old modes are 
> not going anywhere so people can keep which ever they prefer.  But, that is 
> where my worry is coming from.
> 
> On a slightly different topic but only slightly, I discovered that my first 
> draft also does this:
> 
> if 12 * 18 +
>    45 - 19
>      frog = 12
> end
> 
> Rather than this:
> 
> if 12 * 18 +
>    45 - 19
>   frog = 12
> end
> 
> I can change the code but I mention it because I bet others will be making 
> the same mistake.
> 
> “frog” (in the first example) is indented to the bol of parent.  The parent 
> is “then” (not if) and the “then” is on the 2nd line, not the first.  So 
> instead of indenting two spaces from the bol of the “if", it is indented two 
> spaces from the bol of the “then” which is the 45.

Yes, we’ve seen the same problem in other languages, like in bug#59686.

> 
> All this to say that now that I”m getting deeper into this, I plan to rethink 
> things.  “Parent”, “grand parent”, “first-sibling”, etc are likely not going 
> to be good for anchor points because simply adding paren’s makes a node on 
> level deeper.  

Where exactly would you insert the parenthesizes? Because if you add them 
around frog = 12, ie, the following:

if 12 * 18 +
   45 - 19
  (frog = 12)
end

then we are now indenting the (frog = 12), not frog = 12, so we are still in 
the same level, and using grand-parent-bol would still work. And there is no 
need for searching for the “if” node.

> I think what will be better in the case of the “if” will be to be anchor to 
> closest “if”.
> 
> I’m also coming to the conclusion that “parent-bol” would be better if it was 
> (bol (parent)) so that (bol (grand-parent)) and (bol (ancestor “if”)), etc 
> could be easily done.

That’ll depend on how many combinations we end up needing. If we really only 
need (bol (parent)) and (bol (grand-parent)), simply adding them as parent-bol 
and grandparent-bol is better (for code complexity, for understanding, for 
documentation, etc).

Yuan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]