1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-01 08:17:38 +00:00

Add treesit-language-abi-version

Also rename treesit-language-version to treesit-library-abi-version,
because the old name is somewhat misleading.

* doc/lispref/parsing.texi (Language Grammar): Update.
* src/treesit.c (Ftreesit_library_abi_version): Rename.
(Ftreesit_language_abi_version): New function.
This commit is contained in:
Yuan Fu 2022-12-30 02:54:13 -08:00
parent 312f82d36f
commit 0237c5927e
No known key found for this signature in database
GPG Key ID: 56E19BC57664A442
2 changed files with 34 additions and 5 deletions

View File

@ -141,7 +141,7 @@ for a language that considers itself too ``cool'' to abide by
conventions.
@cindex language grammar version, compatibility
@defun treesit-language-version &optional min-compatible
@defun treesit-library-abi-version &optional min-compatible
This function returns the version of the language grammar
Application Binary Interface (@acronym{ABI}) supported by the
tree-sitter library. By default, it returns the latest ABI version
@ -153,6 +153,12 @@ the tree-sitter library, otherwise the library will be unable to load
them.
@end defun
@defun treesit-language-abi-version language
This function returns the language grammar @acronym{ABI} version of
language grammar for @var{language} loaded by Emacs. If
@var{language} is unavailable, this function returns @code{nil}.
@end defun
@heading Concrete syntax tree
@cindex syntax tree, concrete

View File

@ -662,9 +662,8 @@ If DETAIL is non-nil, return (t . nil) when LANGUAGE is available,
}
}
DEFUN ("treesit-language-version",
Ftreesit_language_version,
Streesit_language_version,
DEFUN ("treesit-library-abi-version", Ftreesit_library_abi_version,
Streesit_library_abi_version,
0, 1, 0,
doc: /* Return the language ABI version of the tree-sitter library.
@ -680,6 +679,29 @@ is non-nil, return the oldest compatible ABI version. */)
return make_fixnum (TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION);
}
DEFUN ("treesit-language-version", Ftreesit_language_abi_version,
Streesit_language_abi_version,
0, 1, 0,
doc: /* Return the language ABI version of the tree-sitter LANGUAGE.
Return nil if LANGUAGE is not available. */)
(Lisp_Object language)
{
if (NILP (Ftreesit_langauge_available_p (language, Qnil)))
return Qnil;
else
{
Lisp_Object signal_symbol = Qnil;
Lisp_Object signal_data = Qnil;
TSLanguage *ts_language = treesit_load_language (language,
&signal_symbol,
&signal_data);
if (ts_language == NULL)
return Qnil;
uint32_t version = ts_language_version (ts_language);
return make_fixnum((ptrdiff_t) version);
}
}
/*** Parsing functions */
static void
@ -3345,7 +3367,8 @@ then in the system default locations for dynamic libraries, in that order. */);
Vtreesit_extra_load_path = Qnil;
defsubr (&Streesit_language_available_p);
defsubr (&Streesit_language_version);
defsubr (&Streesit_library_abi_version);
defsubr (&Streesit_language_abi_version);
defsubr (&Streesit_parser_p);
defsubr (&Streesit_node_p);