[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: |
Tue, 5 Sep 2023 21:07:58 -0700 |
> On Aug 30, 2023, at 4:28 AM, Augustin Chéneau (BTuin) <btuin@mailo.com> wrote:
>
> Le 30/08/2023 à 09:03, Yuan Fu a écrit :
>>> On Aug 29, 2023, at 2:26 PM, Augustin Chéneau (BTuin) <btuin@mailo.com>
>>> wrote:
>>>
>>> Hello,
>>>
>>> I have a few questions about tree-sitter.
>>>
>>> I'm currently developing a grammar for GNU Bison alongside a tree-sitter
>>> major mode, it's a work in progress. The grammar is here:
>>> <https://gitlab.com/btuin2/tree-sitter-bison>, still incomplete but so
>>> far able to parse simple files, and the major mode prototype is
>>> attached to this message.
>>>
>>> So, the questions:
>>>
>>> 1. Is there a way to reload a grammar?
>>>
>>> Emacs is pretty nice as a playground for testing grammars, but once a
>>> grammar is loaded, it won't be loaded again until Emacs restarts (as far
>>> as I know).
>>> Is it possible to reload a grammar after modifying it?
>> No, and it’s probably not easy to implement either, since unloading the
>> grammar would require Emacs to purge/invalid all the node/query/parsers
>> using that grammar.
>>> 2. How to mix multiple languages?
>>>
>>> It would be very useful for Bison since its mixed with C or other languages.
>>> According to the documentation I need to use the function
>>> `treesit-range-rules` to set the variable `treesit-range-settings`, but
>>> it seems to have no effect. The language in the selected nodes doesn't
>>> change (as attested by `(treesit-language-at (point))`).
>>>
>>> I did it that way (extracted from the attachment):
>>>
>>> (setq-local treesit-range-settings
>>> (treesit-range-rules
>>> :embed 'c
>>> :host 'bison
>>> '((undelimited_code_block) @capture)))
>>>
>>> Am I missing something?
>> The ranges are set correctly, actually. But the C parse sees all those
>> blocks stitched together as a whole, rather than individual blocks, and the
>> code it sees is obviously not syntactically correct.
>> We should really work on supporting isolated ranges, there has been multiple
>> requests for it. I’ll try to work on that.
>>> 3. Is it possible to trigger a hook when a node is modified?
>>>
>>> Since Bison supports multiple languages (C, C++, Java and D), I'd like
>>> to watch the declaration "%language LANGUAGE" to change the embedded
>>> language when needed.
>>> Is there a way to do that?
>> treesit-parser-add-notifier might be what you want.
>> Yuan
>
> I see. Thank you for your answers and for your great work on tree-sitter!
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
bison-ts-mode.el
Description: Binary data
- Re: Questions about tree-sitter, Madhu, 2023/09/01
- Re: Questions about tree-sitter,
Yuan Fu <=
- Re: Questions about tree-sitter, BTuin, 2023/09/08
- Re: Questions about tree-sitter, Yuan Fu, 2023/09/08
- 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