emacs-devel
[Top][All Lists]
Advanced

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

Re: Tree-sitter api


From: Tuấn-Anh Nguyễn
Subject: Re: Tree-sitter api
Date: Fri, 17 Sep 2021 20:03:56 +0700

On Fri, Sep 17, 2021 at 7:23 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> For a major mode to use TS, the major mode's code needs to know;
> - The name of the language's grammar file.
>   This can usually/often be guessed from the language's name and is
>   a trivial piece of information.
> - The names of the various nodes that will appear in the AST.
>   Those are specific to the particular grammar being used, and the best
>   place to find them is in the source code of the grammar, tho you can
>   also just find them by experimentation.

There are also field names, which make it easier to refer to specific child
nodes within a parent node. For example, within a `function_definition` node,
the `identifier` node that is the function name has the field name `name`.

Node names (types in tree-sitter's terms) and field names can both be extracted
from the shared library. We should provide functions for that, e.g.
`tree-sitter-node-types`, `tree-sitter-field-names`.

The interesting non-trivial parts of a definition would be the relationships
between the node types. For example, a `function_definition` can be inside a
`class_definition`, or a `module`, but not a `boolean_expression`. In principle,
these can be included in the shared library as well. AFAICT, the `tree-sitter`
authors would be open to adding that feature.

-- 
Tuấn-Anh Nguyễn
Software Engineer



reply via email to

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