emacs-devel
[Top][All Lists]
Advanced

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

Re: Tree-sitter api


From: Theodor Thornhill
Subject: Re: Tree-sitter api
Date: Sun, 05 Sep 2021 23:15:55 +0200

Yuan Fu <casouri@gmail.com> writes:

> You can find the code at https://github.com/casouri/emacs.git, in “ts” 
> branch. As long as tree-sitter library is in the standard path, Emacs will 
> compile with tree-sitter support. Language definitions are loaded by dynamic 
> modules. You can find a script for building dynamic modules at 
> https://github.com/casouri/tree-sitter-module, you can even just grab the 
> release file. I need to add C# to the list of languages in the build script.
>
> Now you have Emacs and dynamic modules. You can also build the manual, I just 
> wrote the manual entries for tree-sitter API, its a draft but should explain 
> everything the Emacs tree-sitter API provides. To build the manual you want 
> to go to /doc/listpref, and do “make -e HTML_OPTS="--html” elisp.html”, that 
> should compile a manual in elisp.html directory. The tree-sitter part is in 
> “37 Parsing Program Source”. I attached a zip file containing the compiled 
> manual on my machine, you can just use that.
>
> I haven’t written manual for font-lock and indent support, because they are 
> not settled yet. To see how they work, you can read:
>
> 1. the source of ts-c-mode in /lisp/tree-sitter.el,
> 2. doctoring of font-lock-tree-sitter-defaults and 
> font-lock-tree-sitter-settings, and 
> 3. docstring of tree-sitter-simple-indent-rules
>
> BTW, tree-sitter-inspect-mode could be helpful.
>
>> Right now we support the rust version on melpa, but I'd rather
>> move to this core-supported package.  How far are we from including this
>> in core,
>
> Some blockers that I can think of are 1) tree-sitter lacks a way to change 
> its malloc behavior in run-time, I commented on their road-map issue, but no 
> one has replied yet, 2) font-lock and indent support hasn’t settled, 3) 
> writing, reviewing and editing the manual will take some time, 4) I need to 
> work on a better way to build and distribute language dynamic modules.
>
>> and what can I do to help?
>
> For a starter, could you perhaps have a look at the indentation system 
> (tree-sitter-simple-indent-rules and friends), and tell me if anything is 
> lacking? Too complex, not powerful enough, etc. Do you have any suggestions? 
> The same goes for font-lock.
>
> Also, I’m happy to hear your suggestions on the general tree-sitter API and 
> the manual.
>


Thank you for your thorough instructions.  I've been able to compile it
on my system, but I'm having trouble with the c-sharp module.  I get
this error:

--------------------------------------------

Cloning into 'tree-sitter-c-sharp'...
remote: Enumerating objects: 62, done.
remote: Counting objects: 100% (62/62), done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 62 (delta 17), reused 19 (delta 0), pack-reused 0
Receiving objects: 100% (62/62), 831.92 KiB | 2.12 MiB/s, done.
Resolving deltas: 100% (17/17), done.
tree-sitter-c-sharp.c:7:33: error: expected ';' after top level declarator
extern TSLanguage *tree_sitter_c-sharp(void);
                                ^
                                ;
tree-sitter-c-sharp.c:16:40: error: implicit declaration of function 'sharp' is 
invalid in C99 [-Werror,-Wimplicit-function-declaration]
  TSLanguage *language = tree_sitter_c-sharp();
                                       ^
2 errors generated.
binding.cc:2:10: fatal error: 'node.h' file not found
#include <node.h>
         ^~~~~~~~
1 error generated.

----------------------------------------------

I'm guessing this is due to the hyphen in the function name.  I remember
we had to do some shenanigans in the rust variant some time ago to
translate this properly.  In the C files we need to use underscore
rather than hyphen, yes?  If this isn't too hard to do I guess I can try
to make a PR to your project, otherwise you at least have a bugreport
here :)  I'm also looking into the code now, and it looks nice so far.
I'll come back to you when I have something more!

Theodor



reply via email to

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