fix(rust): minor cleanup in generate code

This commit is contained in:
Will Lillis 2025-10-14 17:52:32 -04:00
parent bdee2c2dd3
commit e344837e35
7 changed files with 12 additions and 19 deletions

View file

@ -81,7 +81,7 @@ pub enum ParseTableBuilderError {
StateCount(usize),
}
#[derive(Default, Debug, Serialize)]
#[derive(Default, Debug, Serialize, Error)]
pub struct ConflictError {
pub symbol_sequence: Vec<String>,
pub conflicting_lookahead: String,
@ -89,7 +89,7 @@ pub struct ConflictError {
pub possible_resolutions: Vec<Resolution>,
}
#[derive(Default, Debug, Serialize)]
#[derive(Default, Debug, Serialize, Error)]
pub struct Interpretation {
pub preceding_symbols: Vec<String>,
pub variable_name: String,
@ -108,7 +108,7 @@ pub enum Resolution {
AddConflict { symbols: Vec<String> },
}
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, Error)]
pub struct AmbiguousExtraError {
pub parent_symbols: Vec<String>,
}
@ -238,9 +238,6 @@ impl std::fmt::Display for AmbiguousExtraError {
}
}
impl std::error::Error for ConflictError {}
impl std::error::Error for AmbiguousExtraError {}
impl<'a> ParseTableBuilder<'a> {
fn new(
syntax_grammar: &'a SyntaxGrammar,

View file

@ -306,9 +306,7 @@ impl Minimizer<'_> {
return true;
}
for (i, action1) in actions1.iter().enumerate() {
let action2 = &actions2[i];
for (action1, action2) in actions1.iter().zip(actions2.iter()) {
// Two shift actions are equivalent if their destinations are in the same group.
if let (
ParseAction::Shift {

View file

@ -28,7 +28,7 @@ pub struct TokenConflictMap<'a> {
impl<'a> TokenConflictMap<'a> {
/// Create a token conflict map based on a lexical grammar, which describes the structure
/// each token, and a `following_token` map, which indicates which tokens may be appear
/// of each token, and a `following_token` map, which indicates which tokens may be appear
/// immediately after each other token.
///
/// This analyzes the possible kinds of overlap between each pair of tokens and stores

View file

@ -27,7 +27,7 @@ pub enum ExpandTokensError {
"The rule `{0}` matches the empty string.
Tree-sitter does not support syntactic rules that match the empty string
unless they are used only as the grammar's start rule.
"
"
)]
EmptyString(String),
#[error(transparent)]
@ -189,7 +189,7 @@ impl NfaBuilder {
}
Rule::String(s) => {
for c in s.chars().rev() {
self.push_advance(CharacterSet::empty().add_char(c), next_state_id);
self.push_advance(CharacterSet::from_char(c), next_state_id);
next_state_id = self.nfa.last_state_id();
}
Ok(!s.is_empty())

View file

@ -69,9 +69,7 @@ pub(super) fn extract_default_aliases(
SymbolType::External => &mut external_status_list[symbol.index],
SymbolType::NonTerminal => &mut non_terminal_status_list[symbol.index],
SymbolType::Terminal => &mut terminal_status_list[symbol.index],
SymbolType::End | SymbolType::EndOfNonTerminalExtra => {
panic!("Unexpected end token")
}
SymbolType::End | SymbolType::EndOfNonTerminalExtra => panic!("Unexpected end token"),
};
status.appears_unaliased = true;
}

View file

@ -153,7 +153,7 @@ pub(super) fn extract_tokens(
}
}
let mut external_tokens = Vec::new();
let mut external_tokens = Vec::with_capacity(grammar.external_tokens.len());
for external_token in grammar.external_tokens {
let rule = symbol_replacer.replace_symbols_in_rule(&external_token.rule);
if let Rule::Symbol(symbol) = rule {

View file

@ -3190,9 +3190,9 @@ impl QueryCursor {
/// The zero max start depth value can be used as a special behavior and
/// it helps to destructure a subtree by staying on a node and using
/// captures for interested parts. Note that the zero max start depth
/// only limit a search depth for a pattern's root node but other nodes
/// that are parts of the pattern may be searched at any depth what
/// defined by the pattern structure.
/// only limits a search depth for a pattern's root node but other nodes
/// that are parts of the pattern may be searched at any depth depending on
/// what is defined by the pattern structure.
///
/// Set to `None` to remove the maximum start depth.
#[doc(alias = "ts_query_cursor_set_max_start_depth")]