all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Simplify the tree-sitter parser creation API
       [not found] <m1pmke7tcn.fsf.ref@yahoo.es>
@ 2022-05-15 14:39 ` Daniel Martín
  2022-05-16 20:50   ` Yuan Fu
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Martín @ 2022-05-15 14:39 UTC (permalink / raw)
  To: emacs-devel


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?



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Simplify the tree-sitter parser creation API
  2022-05-15 14:39 ` Simplify the tree-sitter parser creation API Daniel Martín
@ 2022-05-16 20:50   ` Yuan Fu
  2022-06-16 19:21     ` Yuan Fu
  0 siblings, 1 reply; 3+ messages in thread
From: Yuan Fu @ 2022-05-16 20:50 UTC (permalink / raw)
  To: Daniel Martín; +Cc: emacs-devel



> On May 15, 2022, at 7:39 AM, Daniel Martín <mardani29@yahoo.es> wrote:
> 
> 
> 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?
> 

Thanks! I think it makes sense. Though I’d keep the treesit-parser-create function because it directly corresponds to the tree-sitter C API. I can extend the C definition of treesit-parser-create to 

(treesit-parser-create LANGUAGE &optional BUFFER NO-REUSE)

Yuan




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Simplify the tree-sitter parser creation API
  2022-05-16 20:50   ` Yuan Fu
@ 2022-06-16 19:21     ` Yuan Fu
  0 siblings, 0 replies; 3+ messages in thread
From: Yuan Fu @ 2022-06-16 19:21 UTC (permalink / raw)
  To: Daniel Martín; +Cc: emacs-devel

> 
> Thanks! I think it makes sense. Though I’d keep the treesit-parser-create function because it directly corresponds to the tree-sitter C API. I can extend the C definition of treesit-parser-create to 
> 
> (treesit-parser-create LANGUAGE &optional BUFFER NO-REUSE)
> 

And done. Please also see the “main” thread for other changes ;-)

Yuan


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-16 19:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <m1pmke7tcn.fsf.ref@yahoo.es>
2022-05-15 14:39 ` Simplify the tree-sitter parser creation API Daniel Martín
2022-05-16 20:50   ` Yuan Fu
2022-06-16 19:21     ` Yuan Fu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.