[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Questions about tree-sitter
From: |
Yuan Fu |
Subject: |
Re: Questions about tree-sitter |
Date: |
Fri, 8 Sep 2023 09:43:34 -0700 |
> On Sep 8, 2023, at 4:53 AM, Augustin Chéneau (BTuin) <btuin@mailo.com> wrote:
>
> Le 06/09/2023 à 06:07, Yuan Fu a écrit :
>> I added local parser support to master. If everything goes right, you just
>> need to add a :local t flag in treesit-range-rules. Check out the modified
>> bision-ts-mode.el that I hacked up for an example. BTW, it’s vital that you
>> define treesit-language-at-point-function for a multi-language mode.
>> Yuan
>
> Thanks a lot!
>
> I did some tests and it's working pretty well.
Awesome!
> Do you think it's a good idea to add a prefix to bison feature names in
> font-lock settings to avoid conflicts with C names (as I did)?
I should add some way to distinguish between languages in feature name list.
The tricky part is to make it backward compatible and not too confusing and
still convenient to use.
> I have a few issues though:
>
> - I first defined `treesit-language-at-point-function` using
> `treesit-node-at`. However, `treesit-node-at` itself uses
> `treesit-language-at-point-function` which causes an infinite recursion.
> So I instead used `treesit-local-parsers-at` to check if a local parser is
> used. Is it a good solution?
No no, you should use the host langauge’s parser (bison) and see if point is in
an undelimited_code_block, and return c or bison accordingly. I’m highlight
this in the docstring, thanks.
For now, you can use something like
(mapcar (lambda (rule)
(list (nth 0 rule)
(nth 1 rule)
(intern (format "js-%s" (nth 2 rule)))
(nth 3 rule)))
js--treesit-font-lock-settings)
to add prefix to c-ts-mode’s font-lock rules’ features.
>
> - When I try to indent C code by using c-ts-mode indent rules, I get the
> following error:
>
> Debugger entered--Lisp error: (wrong-type-argument treesit-node-p
> #<treesit-parser for c>)
> treesit-node-parser(#<treesit-parser for c>)
> treesit--indent-1()
> treesit-indent-region(1075 1176)
> indent-region(1075 1176)
> indent-for-tab-command(nil)
> funcall-interactively(indent-for-tab-command nil)
> call-interactively(indent-for-tab-command nil nil)
> command-execute(indent-for-tab-command)
>
> There seems to be a mistake in `treesit--indent-1` in the `cond` at the line
> `(local-parsers (car local-parsers))`, since a parser is returned while it
> should be a node.
Thanks, I fixed that on master. And c-ts-mode’s feature list is a separate
variable now.
Yuan
- Re: Questions about tree-sitter, Madhu, 2023/09/01
- Re: Questions about tree-sitter, Yuan Fu, 2023/09/06
- Re: Questions about tree-sitter, BTuin, 2023/09/08
- Re: Questions about tree-sitter,
Yuan Fu <=
- Re: Questions about tree-sitter, BTuin, 2023/09/09
- Re: Questions about tree-sitter, Yuan Fu, 2023/09/11
- Re: Questions about tree-sitter, BTuin, 2023/09/13
- Re: Questions about tree-sitter, Yuan Fu, 2023/09/14
- Re: Questions about tree-sitter, BTuin, 2023/09/18
- Re: Questions about tree-sitter, Yuan Fu, 2023/09/19
- Re: Questions about tree-sitter, Lynn Winebarger, 2023/09/06