Symbols without aliases should be used for lookahead

This commit is contained in:
Daumantas Kavolis 2023-06-15 15:55:32 +03:00
parent 7267384970
commit 1f52f2f1dc
9 changed files with 115 additions and 7 deletions

View file

@ -288,6 +288,14 @@ extern "C" {
#[doc = " Get the node's language."]
pub fn ts_node_language(arg1: TSNode) -> *const TSLanguage;
}
extern "C" {
#[doc = " Get the node's type as it appears in the grammar ignoring aliases as a\n null-terminated string."]
pub fn ts_node_grammar_type(arg1: TSNode) -> *const ::std::os::raw::c_char;
}
extern "C" {
#[doc = " Get the node's type as a numerical id as it appears in the grammar ignoring\n aliases. This should be used in `ts_language_next_state` instead of\n `ts_node_symbol`."]
pub fn ts_node_grammar_symbol(arg1: TSNode) -> TSSymbol;
}
extern "C" {
#[doc = " Get the node's start byte."]
pub fn ts_node_start_byte(arg1: TSNode) -> u32;
@ -340,6 +348,10 @@ extern "C" {
#[doc = " Get this node's parse state."]
pub fn ts_node_parse_state(arg1: TSNode) -> TSStateId;
}
extern "C" {
#[doc = " Get the parse state after this node."]
pub fn ts_node_next_parse_state(arg1: TSNode) -> TSStateId;
}
extern "C" {
#[doc = " Get the node's immediate parent."]
pub fn ts_node_parent(arg1: TSNode) -> TSNode;
@ -681,7 +693,7 @@ extern "C" {
pub fn ts_language_version(arg1: *const TSLanguage) -> u32;
}
extern "C" {
#[doc = " Get the next parse state. Combine this with lookahead iterators to generate\n completion suggestions or valid symbols in error nodes."]
#[doc = " Get the next parse state. Combine this with lookahead iterators to generate\n completion suggestions or valid symbols in error nodes. Use\n `ts_node_grammar_symbol` for valid symbols."]
pub fn ts_language_next_state(
arg1: *const TSLanguage,
arg2: TSStateId,

View file

@ -349,6 +349,11 @@ impl Language {
/// Get the next parse state. Combine this with [lookahead_iterator] to
/// generate completion suggestions or valid symbols in error nodes.
///
/// Example:
/// ```
/// let state = language.next_state(node.parse_state(), node.grammar_id());
/// ```
#[doc(alias = "ts_language_next_state")]
pub fn next_state(&self, state: u16, id: u16) -> u16 {
unsafe { ffi::ts_language_next_state(self.0, state, id) }
@ -872,6 +877,13 @@ impl<'tree> Node<'tree> {
unsafe { ffi::ts_node_symbol(self.0) }
}
/// Get the node's type as a numerical id as it appears in the grammar
/// ignoring aliases.
#[doc(alias = "ts_node_grammar_symbol")]
pub fn grammar_id(&self) -> u16 {
unsafe { ffi::ts_node_grammar_symbol(self.0) }
}
/// Get this node's type as a string.
#[doc(alias = "ts_node_type")]
pub fn kind(&self) -> &'static str {
@ -880,6 +892,15 @@ impl<'tree> Node<'tree> {
.unwrap()
}
/// Get this node's symbol name as it appears in the grammar ignoring
/// aliases as a string.
#[doc(alias = "ts_node_grammar_type")]
pub fn grammar_name(&self) -> &'static str {
unsafe { CStr::from_ptr(ffi::ts_node_grammar_type(self.0)) }
.to_str()
.unwrap()
}
/// Get the [Language] that was used to parse this node's syntax tree.
#[doc(alias = "ts_node_language")]
pub fn language(&self) -> Language {
@ -931,6 +952,12 @@ impl<'tree> Node<'tree> {
unsafe { ffi::ts_node_parse_state(self.0) }
}
/// Get the parse state after this node.
#[doc(alias = "ts_node_next_parse_state")]
pub fn next_parse_state(&self) -> u16 {
unsafe { ffi::ts_node_next_parse_state(self.0) }
}
/// Check if this node is *missing*.
///
/// Missing nodes are inserted by the parser in order to recover from certain kinds of