[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Simplify the tree-sitter parser creation API
From: |
Daniel Martín |
Subject: |
Simplify the tree-sitter parser creation API |
Date: |
Sun, 15 May 2022 16:39:36 +0200 |
Currently, there are three functions to create a tree-sitter parser:
- treesit-get-parser-create
- treesit-get-parser
- treesit-parser-create
I think this set of similarly named functions can be reduced, so that
developers don't need to remember a lot of APIs. How I understand the
problem of creating a tree-sitter parser is that we need three things
from the developer:
- A programming language (a symbol).
- A buffer (optional, default to the current buffer).
- Whether to create or reuse an existing parser for that language.
I think it would be simpler to have just one parser creation API like
(treesit-make-parser LANGUAGE &optional BUFFER ALWAYS-NEW)
There are similar API patterns like this one already in Emacs. With
this proposed API, the common case, which is to create a parser for the
current buffer, and to try to reuse one if it already exists, is very
simple from the POV of an ELisp developer integrating with tree-sitter:
(treesit-make-parser 'c)
Any thoughts?
- Simplify the tree-sitter parser creation API,
Daniel Martín <=