From 55bda0a968609a21ce1fb5ed4dcc2d04766807c0 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Tue, 29 Oct 2024 16:31:50 -0400 Subject: [PATCH] build: regenerate `bindings.rs` & add `Language::name` --- lib/binding_rust/bindings.rs | 4 ++++ lib/binding_rust/lib.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/binding_rust/bindings.rs b/lib/binding_rust/bindings.rs index 24095fa0..2c0af264 100644 --- a/lib/binding_rust/bindings.rs +++ b/lib/binding_rust/bindings.rs @@ -760,6 +760,10 @@ extern "C" { symbol: TSSymbol, ) -> TSStateId; } +extern "C" { + #[doc = " Get the name of this language. This returns `NULL` in older parsers."] + pub fn ts_language_name(self_: *const TSLanguage) -> *const ::core::ffi::c_char; +} extern "C" { #[doc = " Create a new lookahead iterator for the given language and parse state.\n\n This returns `NULL` if state is invalid for the language.\n\n Repeatedly using [`ts_lookahead_iterator_next`] and\n [`ts_lookahead_iterator_current_symbol`] will generate valid symbols in the\n given parse state. Newly created lookahead iterators will contain the `ERROR`\n symbol.\n\n Lookahead iterators can be useful to generate suggestions and improve syntax\n error diagnostics. To get symbols valid in an ERROR node, use the lookahead\n iterator on its first leaf node state. For `MISSING` nodes, a lookahead\n iterator created on the previous non-extra leaf node may be appropriate."] pub fn ts_lookahead_iterator_new( diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 9b6852fe..207e848a 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -301,6 +301,14 @@ impl Language { Self(unsafe { builder.into_raw()().cast() }) } + /// Get the name of this language. This returns `None` in older parsers. + #[doc(alias = "ts_language_version")] + #[must_use] + pub fn name(&self) -> Option<&'static str> { + let ptr = unsafe { ffi::ts_language_name(self.0) }; + (!ptr.is_null()).then(|| unsafe { CStr::from_ptr(ptr) }.to_str().unwrap()) + } + /// Get the ABI version number that indicates which version of the /// Tree-sitter CLI that was used to generate this [`Language`]. #[doc(alias = "ts_language_version")]