diff --git a/cli/benches/benchmark.rs b/cli/benches/benchmark.rs index 0712facc..8957227b 100644 --- a/cli/benches/benchmark.rs +++ b/cli/benches/benchmark.rs @@ -1,9 +1,14 @@ +use std::{ + collections::BTreeMap, + env, fs, + path::{Path, PathBuf}, + str, + time::Instant, + usize, +}; + use anyhow::Context; use lazy_static::lazy_static; -use std::collections::BTreeMap; -use std::path::{Path, PathBuf}; -use std::time::Instant; -use std::{env, fs, str, usize}; use tree_sitter::{Language, Parser, Query}; use tree_sitter_loader::{CompileConfig, Loader}; diff --git a/cli/config/src/lib.rs b/cli/config/src/lib.rs index 1686b54f..4f5bef19 100644 --- a/cli/config/src/lib.rs +++ b/cli/config/src/lib.rs @@ -1,10 +1,10 @@ #![doc = include_str!("../README.md")] +use std::{env, fs, path::PathBuf}; + use anyhow::{anyhow, Context, Result}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::path::PathBuf; -use std::{env, fs}; /// Holds the contents of tree-sitter's configuration file. /// diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index b584abd4..52c89387 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -1,14 +1,18 @@ #![doc = include_str!("../README.md")] -use std::collections::HashMap; -use std::ffi::{OsStr, OsString}; -use std::io::{BufRead, BufReader}; -use std::ops::Range; -use std::path::{Path, PathBuf}; -use std::process::Command; -use std::sync::Mutex; -use std::time::SystemTime; -use std::{env, fs, mem}; +use std::{ + collections::HashMap, + env, + ffi::{OsStr, OsString}, + fs, + io::{BufRead, BufReader}, + mem, + ops::Range, + path::{Path, PathBuf}, + process::Command, + sync::Mutex, + time::SystemTime, +}; use anyhow::{anyhow, Context, Error, Result}; use fs4::FileExt; diff --git a/cli/src/generate/build_tables/build_lex_table.rs b/cli/src/generate/build_tables/build_lex_table.rs index bc65447c..361e437c 100644 --- a/cli/src/generate/build_tables/build_lex_table.rs +++ b/cli/src/generate/build_tables/build_lex_table.rs @@ -1,14 +1,18 @@ -use super::coincident_tokens::CoincidentTokenIndex; -use super::token_conflicts::TokenConflictMap; -use crate::generate::dedup::split_state_id_groups; -use crate::generate::grammars::{LexicalGrammar, SyntaxGrammar}; -use crate::generate::nfa::NfaCursor; -use crate::generate::rules::{Symbol, TokenSet}; -use crate::generate::tables::{AdvanceAction, LexState, LexTable, ParseStateId, ParseTable}; +use std::{ + collections::{hash_map::Entry, HashMap, VecDeque}, + mem, +}; + use log::info; -use std::collections::hash_map::Entry; -use std::collections::{HashMap, VecDeque}; -use std::mem; + +use super::{coincident_tokens::CoincidentTokenIndex, token_conflicts::TokenConflictMap}; +use crate::generate::{ + dedup::split_state_id_groups, + grammars::{LexicalGrammar, SyntaxGrammar}, + nfa::NfaCursor, + rules::{Symbol, TokenSet}, + tables::{AdvanceAction, LexState, LexTable, ParseStateId, ParseTable}, +}; pub fn build_lex_table( parse_table: &mut ParseTable, diff --git a/cli/src/generate/build_tables/build_parse_table.rs b/cli/src/generate/build_tables/build_parse_table.rs index b9b78966..b16ebc26 100644 --- a/cli/src/generate/build_tables/build_parse_table.rs +++ b/cli/src/generate/build_tables/build_parse_table.rs @@ -1,25 +1,30 @@ -use super::item::{ParseItem, ParseItemSet, ParseItemSetCore}; -use super::item_set_builder::ParseItemSetBuilder; -use crate::generate::grammars::PrecedenceEntry; -use crate::generate::grammars::{ - InlinedProductionMap, LexicalGrammar, SyntaxGrammar, VariableType, +use std::{ + cmp::Ordering, + collections::{BTreeMap, HashMap, HashSet, VecDeque}, + fmt::Write, + hash::BuildHasherDefault, }; -use crate::generate::node_types::VariableInfo; -use crate::generate::rules::{Associativity, Precedence, Symbol, SymbolType, TokenSet}; -use crate::generate::tables::{ - FieldLocation, GotoAction, ParseAction, ParseState, ParseStateId, ParseTable, ParseTableEntry, - ProductionInfo, ProductionInfoId, -}; -use anyhow::{anyhow, Result}; -use std::cmp::Ordering; -use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; -use std::fmt::Write; -use std::hash::BuildHasherDefault; -use std::u32; +use anyhow::{anyhow, Result}; use indexmap::{map::Entry, IndexMap}; use rustc_hash::FxHasher; +use super::{ + item::{ParseItem, ParseItemSet, ParseItemSetCore}, + item_set_builder::ParseItemSetBuilder, +}; +use crate::generate::{ + grammars::{ + InlinedProductionMap, LexicalGrammar, PrecedenceEntry, SyntaxGrammar, VariableType, + }, + node_types::VariableInfo, + rules::{Associativity, Precedence, Symbol, SymbolType, TokenSet}, + tables::{ + FieldLocation, GotoAction, ParseAction, ParseState, ParseStateId, ParseTable, + ParseTableEntry, ProductionInfo, ProductionInfoId, + }, +}; + // For conflict reporting, each parse state is associated with an example // sequence of symbols that could lead to that parse state. type SymbolSequence = Vec; diff --git a/cli/src/generate/build_tables/coincident_tokens.rs b/cli/src/generate/build_tables/coincident_tokens.rs index a2181438..9341145d 100644 --- a/cli/src/generate/build_tables/coincident_tokens.rs +++ b/cli/src/generate/build_tables/coincident_tokens.rs @@ -1,8 +1,11 @@ -use crate::generate::grammars::LexicalGrammar; -use crate::generate::rules::Symbol; -use crate::generate::tables::{ParseStateId, ParseTable}; use std::fmt; +use crate::generate::{ + grammars::LexicalGrammar, + rules::Symbol, + tables::{ParseStateId, ParseTable}, +}; + pub struct CoincidentTokenIndex<'a> { entries: Vec>, grammar: &'a LexicalGrammar, diff --git a/cli/src/generate/build_tables/item.rs b/cli/src/generate/build_tables/item.rs index 82c32a81..54edc811 100644 --- a/cli/src/generate/build_tables/item.rs +++ b/cli/src/generate/build_tables/item.rs @@ -1,10 +1,15 @@ -use crate::generate::grammars::{LexicalGrammar, Production, ProductionStep, SyntaxGrammar}; -use crate::generate::rules::{Associativity, Precedence, Symbol, SymbolType, TokenSet}; +use std::{ + cmp::Ordering, + fmt, + hash::{Hash, Hasher}, +}; + use lazy_static::lazy_static; -use std::cmp::Ordering; -use std::fmt; -use std::hash::{Hash, Hasher}; -use std::u32; + +use crate::generate::{ + grammars::{LexicalGrammar, Production, ProductionStep, SyntaxGrammar}, + rules::{Associativity, Precedence, Symbol, SymbolType, TokenSet}, +}; lazy_static! { static ref START_PRODUCTION: Production = Production { diff --git a/cli/src/generate/build_tables/item_set_builder.rs b/cli/src/generate/build_tables/item_set_builder.rs index 8f9644d0..13cf2847 100644 --- a/cli/src/generate/build_tables/item_set_builder.rs +++ b/cli/src/generate/build_tables/item_set_builder.rs @@ -1,8 +1,13 @@ +use std::{ + collections::{HashMap, HashSet}, + fmt, +}; + use super::item::{ParseItem, ParseItemDisplay, ParseItemSet, TokenSetDisplay}; -use crate::generate::grammars::{InlinedProductionMap, LexicalGrammar, SyntaxGrammar}; -use crate::generate::rules::{Symbol, SymbolType, TokenSet}; -use std::collections::{HashMap, HashSet}; -use std::fmt; +use crate::generate::{ + grammars::{InlinedProductionMap, LexicalGrammar, SyntaxGrammar}, + rules::{Symbol, SymbolType, TokenSet}, +}; #[derive(Clone, Debug, PartialEq, Eq)] struct TransitiveClosureAddition<'a> { diff --git a/cli/src/generate/build_tables/minimize_parse_table.rs b/cli/src/generate/build_tables/minimize_parse_table.rs index d9d2b7f5..5eb6260b 100644 --- a/cli/src/generate/build_tables/minimize_parse_table.rs +++ b/cli/src/generate/build_tables/minimize_parse_table.rs @@ -1,13 +1,17 @@ -use super::token_conflicts::TokenConflictMap; -use crate::generate::dedup::split_state_id_groups; -use crate::generate::grammars::{LexicalGrammar, SyntaxGrammar, VariableType}; -use crate::generate::rules::{AliasMap, Symbol, TokenSet}; -use crate::generate::tables::{ - GotoAction, ParseAction, ParseState, ParseStateId, ParseTable, ParseTableEntry, +use std::{ + collections::{HashMap, HashSet}, + mem, }; + use log::info; -use std::collections::{HashMap, HashSet}; -use std::mem; + +use super::token_conflicts::TokenConflictMap; +use crate::generate::{ + dedup::split_state_id_groups, + grammars::{LexicalGrammar, SyntaxGrammar, VariableType}, + rules::{AliasMap, Symbol, TokenSet}, + tables::{GotoAction, ParseAction, ParseState, ParseStateId, ParseTable, ParseTableEntry}, +}; pub fn minimize_parse_table( parse_table: &mut ParseTable, diff --git a/cli/src/generate/build_tables/mod.rs b/cli/src/generate/build_tables/mod.rs index edb13cac..7946c144 100644 --- a/cli/src/generate/build_tables/mod.rs +++ b/cli/src/generate/build_tables/mod.rs @@ -6,19 +6,25 @@ mod item_set_builder; mod minimize_parse_table; mod token_conflicts; -use self::build_lex_table::build_lex_table; -use self::build_parse_table::{build_parse_table, ParseStateInfo}; -use self::coincident_tokens::CoincidentTokenIndex; -use self::minimize_parse_table::minimize_parse_table; -use self::token_conflicts::TokenConflictMap; -use crate::generate::grammars::{InlinedProductionMap, LexicalGrammar, SyntaxGrammar}; -use crate::generate::nfa::NfaCursor; -use crate::generate::node_types::VariableInfo; -use crate::generate::rules::{AliasMap, Symbol, SymbolType, TokenSet}; -use crate::generate::tables::{LexTable, ParseAction, ParseTable, ParseTableEntry}; +use std::collections::{BTreeSet, HashMap}; + use anyhow::Result; use log::info; -use std::collections::{BTreeSet, HashMap}; + +use self::{ + build_lex_table::build_lex_table, + build_parse_table::{build_parse_table, ParseStateInfo}, + coincident_tokens::CoincidentTokenIndex, + minimize_parse_table::minimize_parse_table, + token_conflicts::TokenConflictMap, +}; +use crate::generate::{ + grammars::{InlinedProductionMap, LexicalGrammar, SyntaxGrammar}, + nfa::NfaCursor, + node_types::VariableInfo, + rules::{AliasMap, Symbol, SymbolType, TokenSet}, + tables::{LexTable, ParseAction, ParseTable, ParseTableEntry}, +}; pub fn build_tables( syntax_grammar: &SyntaxGrammar, diff --git a/cli/src/generate/build_tables/token_conflicts.rs b/cli/src/generate/build_tables/token_conflicts.rs index 33a904b0..47a114d6 100644 --- a/cli/src/generate/build_tables/token_conflicts.rs +++ b/cli/src/generate/build_tables/token_conflicts.rs @@ -1,10 +1,11 @@ -use crate::generate::build_tables::item::TokenSetDisplay; -use crate::generate::grammars::{LexicalGrammar, SyntaxGrammar}; -use crate::generate::nfa::{CharacterSet, NfaCursor, NfaTransition}; -use crate::generate::rules::TokenSet; -use std::cmp::Ordering; -use std::collections::HashSet; -use std::fmt; +use std::{cmp::Ordering, collections::HashSet, fmt}; + +use crate::generate::{ + build_tables::item::TokenSetDisplay, + grammars::{LexicalGrammar, SyntaxGrammar}, + nfa::{CharacterSet, NfaCursor, NfaTransition}, + rules::TokenSet, +}; #[derive(Clone, Debug, Default, PartialEq, Eq)] struct TokenConflictStatus { @@ -372,9 +373,11 @@ fn compute_conflict_status( #[cfg(test)] mod tests { use super::*; - use crate::generate::grammars::{Variable, VariableType}; - use crate::generate::prepare_grammar::{expand_tokens, ExtractedLexicalGrammar}; - use crate::generate::rules::{Precedence, Rule, Symbol}; + use crate::generate::{ + grammars::{Variable, VariableType}, + prepare_grammar::{expand_tokens, ExtractedLexicalGrammar}, + rules::{Precedence, Rule, Symbol}, + }; #[test] fn test_starting_characters() { diff --git a/cli/src/generate/grammar_files.rs b/cli/src/generate/grammar_files.rs index b9303fab..f7e7bb4c 100644 --- a/cli/src/generate/grammar_files.rs +++ b/cli/src/generate/grammar_files.rs @@ -1,13 +1,18 @@ -use super::write_file; +use std::{ + fs, + fs::File, + io::BufReader, + path::{Path, PathBuf}, + str, +}; + use anyhow::{anyhow, Context, Result}; use heck::{ToKebabCase, ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase}; use indoc::indoc; use serde::Deserialize; use serde_json::{json, Map, Value}; -use std::fs::File; -use std::io::BufReader; -use std::path::{Path, PathBuf}; -use std::{fs, str}; + +use super::write_file; const CLI_VERSION: &str = env!("CARGO_PKG_VERSION"); const CLI_VERSION_PLACEHOLDER: &str = "CLI_VERSION"; diff --git a/cli/src/generate/grammars.rs b/cli/src/generate/grammars.rs index 5f057a1b..1f3b9070 100644 --- a/cli/src/generate/grammars.rs +++ b/cli/src/generate/grammars.rs @@ -1,7 +1,9 @@ -use super::nfa::Nfa; -use super::rules::{Alias, Associativity, Precedence, Rule, Symbol}; -use std::collections::HashMap; -use std::fmt; +use std::{collections::HashMap, fmt}; + +use super::{ + nfa::Nfa, + rules::{Alias, Associativity, Precedence, Rule, Symbol}, +}; #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum VariableType { diff --git a/cli/src/generate/mod.rs b/cli/src/generate/mod.rs index ea850c8d..2f07361e 100644 --- a/cli/src/generate/mod.rs +++ b/cli/src/generate/mod.rs @@ -1,20 +1,21 @@ -use std::io::Write; -use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio}; -use std::{env, fs}; +use std::{ + env, fs, + io::Write, + path::{Path, PathBuf}, + process::{Command, Stdio}, +}; use anyhow::{anyhow, Context, Result}; -use lazy_static::lazy_static; -use regex::{Regex, RegexBuilder}; -use semver::Version; - use build_tables::build_tables; use grammar_files::path_in_ignore; use grammars::{InlinedProductionMap, LexicalGrammar, SyntaxGrammar}; +use lazy_static::lazy_static; use parse_grammar::parse_grammar; use prepare_grammar::prepare_grammar; +use regex::{Regex, RegexBuilder}; use render::render_c_code; use rules::AliasMap; +use semver::Version; mod build_tables; mod char_tree; diff --git a/cli/src/generate/nfa.rs b/cli/src/generate/nfa.rs index 66f78074..e793199f 100644 --- a/cli/src/generate/nfa.rs +++ b/cli/src/generate/nfa.rs @@ -1,10 +1,11 @@ -use std::char; -use std::cmp::max; -use std::cmp::Ordering; -use std::collections::HashSet; -use std::fmt; -use std::mem::swap; -use std::ops::Range; +use std::{ + char, + cmp::{max, Ordering}, + collections::HashSet, + fmt, + mem::swap, + ops::Range, +}; /// A set of characters represented as a vector of ranges. #[derive(Clone, PartialEq, Eq, Hash)] diff --git a/cli/src/generate/node_types.rs b/cli/src/generate/node_types.rs index 7f512458..114bf900 100644 --- a/cli/src/generate/node_types.rs +++ b/cli/src/generate/node_types.rs @@ -1,9 +1,15 @@ -use super::grammars::{LexicalGrammar, SyntaxGrammar, VariableType}; -use super::rules::{Alias, AliasMap, Symbol, SymbolType}; +use std::{ + cmp::Ordering, + collections::{BTreeMap, HashMap, HashSet}, +}; + use anyhow::{anyhow, Result}; use serde::Serialize; -use std::cmp::Ordering; -use std::collections::{BTreeMap, HashMap, HashSet}; + +use super::{ + grammars::{LexicalGrammar, SyntaxGrammar, VariableType}, + rules::{Alias, AliasMap, Symbol, SymbolType}, +}; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum ChildType { @@ -715,11 +721,13 @@ where #[cfg(test)] mod tests { use super::*; - use crate::generate::grammars::{ - InputGrammar, LexicalVariable, Production, ProductionStep, SyntaxVariable, Variable, + use crate::generate::{ + grammars::{ + InputGrammar, LexicalVariable, Production, ProductionStep, SyntaxVariable, Variable, + }, + prepare_grammar::prepare_grammar, + rules::Rule, }; - use crate::generate::prepare_grammar::prepare_grammar; - use crate::generate::rules::Rule; #[test] fn test_node_types_simple() { diff --git a/cli/src/generate/parse_grammar.rs b/cli/src/generate/parse_grammar.rs index 356536e5..9ba43c94 100644 --- a/cli/src/generate/parse_grammar.rs +++ b/cli/src/generate/parse_grammar.rs @@ -1,9 +1,12 @@ -use super::grammars::{InputGrammar, PrecedenceEntry, Variable, VariableType}; -use super::rules::{Precedence, Rule}; use anyhow::{anyhow, Result}; use serde::Deserialize; use serde_json::{Map, Value}; +use super::{ + grammars::{InputGrammar, PrecedenceEntry, Variable, VariableType}, + rules::{Precedence, Rule}, +}; + #[derive(Deserialize)] #[serde(tag = "type")] #[allow(non_camel_case_types)] diff --git a/cli/src/generate/prepare_grammar/expand_repeats.rs b/cli/src/generate/prepare_grammar/expand_repeats.rs index e296d425..4b97e53c 100644 --- a/cli/src/generate/prepare_grammar/expand_repeats.rs +++ b/cli/src/generate/prepare_grammar/expand_repeats.rs @@ -1,8 +1,10 @@ +use std::{collections::HashMap, mem}; + use super::ExtractedSyntaxGrammar; -use crate::generate::grammars::{Variable, VariableType}; -use crate::generate::rules::{Rule, Symbol}; -use std::collections::HashMap; -use std::mem; +use crate::generate::{ + grammars::{Variable, VariableType}, + rules::{Rule, Symbol}, +}; struct Expander { variable_name: String, diff --git a/cli/src/generate/prepare_grammar/expand_tokens.rs b/cli/src/generate/prepare_grammar/expand_tokens.rs index 70a92cae..a11f9ad9 100644 --- a/cli/src/generate/prepare_grammar/expand_tokens.rs +++ b/cli/src/generate/prepare_grammar/expand_tokens.rs @@ -1,15 +1,18 @@ -use super::ExtractedLexicalGrammar; -use crate::generate::grammars::{LexicalGrammar, LexicalVariable}; -use crate::generate::nfa::{CharacterSet, Nfa, NfaState}; -use crate::generate::rules::{Precedence, Rule}; +use std::collections::HashMap; + use anyhow::{anyhow, Context, Result}; use lazy_static::lazy_static; use regex_syntax::ast::{ parse, Ast, ClassPerlKind, ClassSet, ClassSetBinaryOpKind, ClassSetItem, ClassUnicodeKind, RepetitionKind, RepetitionRange, }; -use std::collections::HashMap; -use std::i32; + +use super::ExtractedLexicalGrammar; +use crate::generate::{ + grammars::{LexicalGrammar, LexicalVariable}, + nfa::{CharacterSet, Nfa, NfaState}, + rules::{Precedence, Rule}, +}; lazy_static! { static ref UNICODE_CATEGORIES: HashMap<&'static str, Vec> = @@ -539,8 +542,10 @@ impl NfaBuilder { #[cfg(test)] mod tests { use super::*; - use crate::generate::grammars::Variable; - use crate::generate::nfa::{NfaCursor, NfaTransition}; + use crate::generate::{ + grammars::Variable, + nfa::{NfaCursor, NfaTransition}, + }; fn simulate_nfa<'a>(grammar: &'a LexicalGrammar, s: &'a str) -> Option<(usize, &'a str)> { let start_states = grammar.variables.iter().map(|v| v.start_state).collect(); diff --git a/cli/src/generate/prepare_grammar/extract_default_aliases.rs b/cli/src/generate/prepare_grammar/extract_default_aliases.rs index 6ffc7eca..b08761d5 100644 --- a/cli/src/generate/prepare_grammar/extract_default_aliases.rs +++ b/cli/src/generate/prepare_grammar/extract_default_aliases.rs @@ -1,5 +1,7 @@ -use crate::generate::grammars::{LexicalGrammar, SyntaxGrammar}; -use crate::generate::rules::{Alias, AliasMap, Symbol, SymbolType}; +use crate::generate::{ + grammars::{LexicalGrammar, SyntaxGrammar}, + rules::{Alias, AliasMap, Symbol, SymbolType}, +}; #[derive(Clone, Default)] struct SymbolStatus { diff --git a/cli/src/generate/prepare_grammar/extract_tokens.rs b/cli/src/generate/prepare_grammar/extract_tokens.rs index 7d87bbd2..f9aa1bca 100644 --- a/cli/src/generate/prepare_grammar/extract_tokens.rs +++ b/cli/src/generate/prepare_grammar/extract_tokens.rs @@ -1,9 +1,12 @@ -use super::{ExtractedLexicalGrammar, ExtractedSyntaxGrammar, InternedGrammar}; -use crate::generate::grammars::{ExternalToken, Variable, VariableType}; -use crate::generate::rules::{MetadataParams, Rule, Symbol, SymbolType}; +use std::{collections::HashMap, mem}; + use anyhow::{anyhow, Result}; -use std::collections::HashMap; -use std::mem; + +use super::{ExtractedLexicalGrammar, ExtractedSyntaxGrammar, InternedGrammar}; +use crate::generate::{ + grammars::{ExternalToken, Variable, VariableType}, + rules::{MetadataParams, Rule, Symbol, SymbolType}, +}; pub(super) fn extract_tokens( mut grammar: InternedGrammar, diff --git a/cli/src/generate/prepare_grammar/flatten_grammar.rs b/cli/src/generate/prepare_grammar/flatten_grammar.rs index 8f56dbf9..4b707bee 100644 --- a/cli/src/generate/prepare_grammar/flatten_grammar.rs +++ b/cli/src/generate/prepare_grammar/flatten_grammar.rs @@ -1,10 +1,11 @@ -use super::ExtractedSyntaxGrammar; -use crate::generate::grammars::{ - Production, ProductionStep, SyntaxGrammar, SyntaxVariable, Variable, -}; -use crate::generate::rules::{Alias, Associativity, Precedence, Rule, Symbol}; use anyhow::{anyhow, Result}; +use super::ExtractedSyntaxGrammar; +use crate::generate::{ + grammars::{Production, ProductionStep, SyntaxGrammar, SyntaxVariable, Variable}, + rules::{Alias, Associativity, Precedence, Rule, Symbol}, +}; + struct RuleFlattener { production: Production, precedence_stack: Vec, diff --git a/cli/src/generate/prepare_grammar/intern_symbols.rs b/cli/src/generate/prepare_grammar/intern_symbols.rs index 092126ae..707aa864 100644 --- a/cli/src/generate/prepare_grammar/intern_symbols.rs +++ b/cli/src/generate/prepare_grammar/intern_symbols.rs @@ -1,8 +1,11 @@ -use super::InternedGrammar; -use crate::generate::grammars::{InputGrammar, Variable, VariableType}; -use crate::generate::rules::{Rule, Symbol}; use anyhow::{anyhow, Result}; +use super::InternedGrammar; +use crate::generate::{ + grammars::{InputGrammar, Variable, VariableType}, + rules::{Rule, Symbol}, +}; + pub(super) fn intern_symbols(grammar: &InputGrammar) -> Result { let interner = Interner { grammar }; diff --git a/cli/src/generate/prepare_grammar/mod.rs b/cli/src/generate/prepare_grammar/mod.rs index 15243c45..7e4800c1 100644 --- a/cli/src/generate/prepare_grammar/mod.rs +++ b/cli/src/generate/prepare_grammar/mod.rs @@ -6,26 +6,28 @@ mod flatten_grammar; mod intern_symbols; mod process_inlines; -pub use self::expand_tokens::expand_tokens; - -use self::expand_repeats::expand_repeats; -use self::extract_default_aliases::extract_default_aliases; -use self::extract_tokens::extract_tokens; -use self::flatten_grammar::flatten_grammar; -use self::intern_symbols::intern_symbols; -use self::process_inlines::process_inlines; -use super::grammars::{ - ExternalToken, InlinedProductionMap, InputGrammar, LexicalGrammar, PrecedenceEntry, - SyntaxGrammar, Variable, -}; -use super::rules::{AliasMap, Precedence, Rule, Symbol}; -use anyhow::{anyhow, Result}; use std::{ cmp::Ordering, collections::{hash_map, HashMap, HashSet}, mem, }; +use anyhow::{anyhow, Result}; + +pub use self::expand_tokens::expand_tokens; +use self::{ + expand_repeats::expand_repeats, extract_default_aliases::extract_default_aliases, + extract_tokens::extract_tokens, flatten_grammar::flatten_grammar, + intern_symbols::intern_symbols, process_inlines::process_inlines, +}; +use super::{ + grammars::{ + ExternalToken, InlinedProductionMap, InputGrammar, LexicalGrammar, PrecedenceEntry, + SyntaxGrammar, Variable, + }, + rules::{AliasMap, Precedence, Rule, Symbol}, +}; + pub struct IntermediateGrammar { variables: Vec, extra_symbols: Vec, diff --git a/cli/src/generate/prepare_grammar/process_inlines.rs b/cli/src/generate/prepare_grammar/process_inlines.rs index 659927a1..040841c1 100644 --- a/cli/src/generate/prepare_grammar/process_inlines.rs +++ b/cli/src/generate/prepare_grammar/process_inlines.rs @@ -1,9 +1,11 @@ +use std::collections::HashMap; + +use anyhow::{anyhow, Result}; + use crate::generate::{ grammars::{InlinedProductionMap, LexicalGrammar, Production, ProductionStep, SyntaxGrammar}, rules::SymbolType, }; -use anyhow::{anyhow, Result}; -use std::collections::HashMap; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] struct ProductionStepId { @@ -223,8 +225,10 @@ pub(super) fn process_inlines( #[cfg(test)] mod tests { use super::*; - use crate::generate::grammars::{LexicalVariable, SyntaxVariable, VariableType}; - use crate::generate::rules::{Associativity, Precedence, Symbol}; + use crate::generate::{ + grammars::{LexicalVariable, SyntaxVariable, VariableType}, + rules::{Associativity, Precedence, Symbol}, + }; #[test] fn test_basic_inlining() { diff --git a/cli/src/generate/render.rs b/cli/src/generate/render.rs index f5c190b9..7d62a8ef 100644 --- a/cli/src/generate/render.rs +++ b/cli/src/generate/render.rs @@ -1,3 +1,11 @@ +use core::ops::Range; +use std::{ + cmp, + collections::{HashMap, HashSet}, + fmt::Write, + mem::swap, +}; + use super::{ char_tree::{CharacterTree, Comparator}, grammars::{ExternalToken, LexicalGrammar, SyntaxGrammar, VariableType}, @@ -7,13 +15,6 @@ use super::{ ParseTableEntry, }, }; -use core::ops::Range; -use std::{ - cmp, - collections::{HashMap, HashSet}, - fmt::Write, - mem::swap, -}; const LARGE_CHARACTER_RANGE_COUNT: usize = 8; const SMALL_STATE_THRESHOLD: usize = 64; diff --git a/cli/src/generate/rules.rs b/cli/src/generate/rules.rs index af744781..ab74a14b 100644 --- a/cli/src/generate/rules.rs +++ b/cli/src/generate/rules.rs @@ -1,7 +1,9 @@ -use super::grammars::VariableType; -use smallbitvec::SmallBitVec; use std::{collections::HashMap, fmt}; +use smallbitvec::SmallBitVec; + +use super::grammars::VariableType; + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum SymbolType { External, diff --git a/cli/src/generate/tables.rs b/cli/src/generate/tables.rs index 3d84c541..541a301c 100644 --- a/cli/src/generate/tables.rs +++ b/cli/src/generate/tables.rs @@ -1,6 +1,9 @@ -use super::nfa::CharacterSet; -use super::rules::{Alias, Symbol, TokenSet}; use std::collections::BTreeMap; + +use super::{ + nfa::CharacterSet, + rules::{Alias, Symbol, TokenSet}, +}; pub type ProductionInfoId = usize; pub type ParseStateId = usize; pub type LexStateId = usize; diff --git a/cli/src/highlight.rs b/cli/src/highlight.rs index e48ca4e8..f350778c 100644 --- a/cli/src/highlight.rs +++ b/cli/src/highlight.rs @@ -1,14 +1,12 @@ +use std::{ + collections::HashMap, fmt::Write, fs, io, path, str, sync::atomic::AtomicUsize, time::Instant, +}; + use ansi_term::Color; use anyhow::Result; use lazy_static::lazy_static; -use serde::ser::SerializeMap; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{json, Value}; -use std::collections::HashMap; -use std::fmt::Write; -use std::sync::atomic::AtomicUsize; -use std::time::Instant; -use std::{fs, io, path, str, usize}; use tree_sitter_highlight::{HighlightConfiguration, HighlightEvent, Highlighter, HtmlRenderer}; use tree_sitter_loader::Loader; @@ -417,9 +415,10 @@ pub fn html( #[cfg(test)] mod tests { - use super::*; use std::env; + use super::*; + const JUNGLE_GREEN: &str = "#26A69A"; const DARK_CYAN: &str = "#00AF87"; diff --git a/cli/src/main.rs b/cli/src/main.rs index 9078eece..9564e5b0 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,17 +1,21 @@ +use std::{ + collections::HashSet, + env, fs, + path::{Path, PathBuf}, +}; + use anstyle::{AnsiColor, Color, Style}; use anyhow::{anyhow, Context, Result}; use clap::{crate_authors, Args, Command, FromArgMatches as _, Subcommand}; use glob::glob; use regex::Regex; -use std::collections::HashSet; -use std::path::{Path, PathBuf}; -use std::{env, fs, u64}; use tree_sitter::{ffi, Parser, Point}; -use tree_sitter_cli::test::TestOptions; use tree_sitter_cli::{ generate, highlight, logger, parse::{self, ParseFileOptions, ParseOutput}, - playground, query, tags, test, test_highlight, test_tags, util, wasm, + playground, query, tags, test, + test::TestOptions, + test_highlight, test_tags, util, wasm, }; use tree_sitter_config::Config; use tree_sitter_highlight::Highlighter; diff --git a/cli/src/parse.rs b/cli/src/parse.rs index 4849bda3..0624382b 100644 --- a/cli/src/parse.rs +++ b/cli/src/parse.rs @@ -1,12 +1,16 @@ -use super::util; +use std::{ + fmt, fs, + io::{self, Write}, + path::Path, + sync::atomic::AtomicUsize, + time::{Duration, Instant}, +}; + use anyhow::{anyhow, Context, Result}; -use std::io::{self, Write}; -use std::path::Path; -use std::sync::atomic::AtomicUsize; -use std::time::{Duration, Instant}; -use std::{fmt, fs, usize}; use tree_sitter::{ffi, InputEdit, Language, LogType, Parser, Point, Tree}; +use super::util; + #[derive(Debug)] pub struct Edit { pub position: usize, diff --git a/cli/src/playground.rs b/cli/src/playground.rs index 34da71ad..adc0c6c2 100644 --- a/cli/src/playground.rs +++ b/cli/src/playground.rs @@ -1,5 +1,3 @@ -use super::wasm; -use anyhow::{anyhow, Context, Result}; use std::{ borrow::Cow, env, fs, @@ -7,8 +5,12 @@ use std::{ path::{Path, PathBuf}, str::{self, FromStr as _}, }; + +use anyhow::{anyhow, Context, Result}; use tiny_http::{Header, Response, Server}; +use super::wasm; + macro_rules! optional_resource { ($name: tt, $path: tt) => { #[cfg(TREE_SITTER_EMBED_WASM_BINDING)] diff --git a/cli/src/query.rs b/cli/src/query.rs index e5601a30..bffa0588 100644 --- a/cli/src/query.rs +++ b/cli/src/query.rs @@ -1,5 +1,3 @@ -use crate::query_testing; -use anyhow::{Context, Result}; use std::{ fs, io::{self, Write}, @@ -7,8 +5,12 @@ use std::{ path::Path, time::Instant, }; + +use anyhow::{Context, Result}; use tree_sitter::{Language, Parser, Point, Query, QueryCursor}; +use crate::query_testing; + #[allow(clippy::too_many_arguments)] pub fn query_files_at_paths( language: &Language, diff --git a/cli/src/query_testing.rs b/cli/src/query_testing.rs index a0ac260d..cdf2e988 100644 --- a/cli/src/query_testing.rs +++ b/cli/src/query_testing.rs @@ -1,7 +1,8 @@ +use std::fs; + use anyhow::{anyhow, Result}; use lazy_static::lazy_static; use regex::Regex; -use std::fs; use tree_sitter::{Language, Parser, Point}; lazy_static! { diff --git a/cli/src/tags.rs b/cli/src/tags.rs index 14ecef0d..4e2058c7 100644 --- a/cli/src/tags.rs +++ b/cli/src/tags.rs @@ -1,12 +1,17 @@ -use super::util; +use std::{ + fs, + io::{self, Write}, + path::Path, + str, + time::Instant, +}; + use anyhow::{anyhow, Result}; -use std::io::{self, Write}; -use std::path::Path; -use std::time::Instant; -use std::{fs, str}; use tree_sitter_loader::{Config, Loader}; use tree_sitter_tags::TagsContext; +use super::util; + pub fn generate_tags( loader: &Loader, loader_config: &Config, diff --git a/cli/src/test.rs b/cli/src/test.rs index 142da4f2..2764cf22 100644 --- a/cli/src/test.rs +++ b/cli/src/test.rs @@ -1,20 +1,26 @@ -use super::util; +use std::{ + collections::BTreeMap, + ffi::OsStr, + fs, + io::{self, Write}, + path::{Path, PathBuf}, + str, +}; + use ansi_term::Colour; use anyhow::{anyhow, Context, Result}; use difference::{Changeset, Difference}; use indoc::indoc; use lazy_static::lazy_static; -use regex::bytes::{Regex as ByteRegex, RegexBuilder as ByteRegexBuilder}; -use regex::Regex; -use std::collections::BTreeMap; -use std::ffi::OsStr; -use std::fs; -use std::io::{self, Write}; -use std::path::{Path, PathBuf}; -use std::str; +use regex::{ + bytes::{Regex as ByteRegex, RegexBuilder as ByteRegexBuilder}, + Regex, +}; use tree_sitter::{format_sexp, Language, LogType, Parser, Query}; use walkdir::WalkDir; +use super::util; + lazy_static! { static ref HEADER_REGEX: ByteRegex = ByteRegexBuilder::new( r"^(?x) diff --git a/cli/src/test_highlight.rs b/cli/src/test_highlight.rs index 919d7864..ab56695b 100644 --- a/cli/src/test_highlight.rs +++ b/cli/src/test_highlight.rs @@ -1,5 +1,4 @@ -use std::fs; -use std::path::Path; +use std::{fs, path::Path}; use ansi_term::Colour; use anyhow::{anyhow, Result}; diff --git a/cli/src/test_tags.rs b/cli/src/test_tags.rs index 11395e10..db508e62 100644 --- a/cli/src/test_tags.rs +++ b/cli/src/test_tags.rs @@ -1,5 +1,4 @@ -use std::fs; -use std::path::Path; +use std::{fs, path::Path}; use ansi_term::Colour; use anyhow::{anyhow, Result}; diff --git a/cli/src/tests/async_context_test.rs b/cli/src/tests/async_context_test.rs index db9bedd4..cb2345cc 100644 --- a/cli/src/tests/async_context_test.rs +++ b/cli/src/tests/async_context_test.rs @@ -1,10 +1,14 @@ -use super::helpers::fixtures::get_language; -use std::future::Future; -use std::pin::{pin, Pin}; -use std::ptr; -use std::task::{self, Context, Poll, RawWaker, RawWakerVTable, Waker}; +use std::{ + future::Future, + pin::{pin, Pin}, + ptr, + task::{self, Context, Poll, RawWaker, RawWakerVTable, Waker}, +}; + use tree_sitter::Parser; +use super::helpers::fixtures::get_language; + #[test] fn test_node_in_fut() { let (ret, pended) = tokio_like_spawn(async { diff --git a/cli/src/tests/corpus_test.rs b/cli/src/tests/corpus_test.rs index 057a672f..c516c897 100644 --- a/cli/src/tests/corpus_test.rs +++ b/cli/src/tests/corpus_test.rs @@ -1,3 +1,8 @@ +use std::{collections::HashMap, env, fs}; + +use tree_sitter::{LogType, Node, Parser, Point, Range, Tree}; +use tree_sitter_proc_macro::test_with_seed; + use super::helpers::{ allocations, edits::{get_random_edit, invert_edit}, @@ -14,9 +19,6 @@ use crate::{ test::{parse_tests, print_diff, print_diff_key, strip_sexp_fields, TestEntry}, util, }; -use std::{collections::HashMap, env, fs}; -use tree_sitter::{LogType, Node, Parser, Point, Range, Tree}; -use tree_sitter_proc_macro::test_with_seed; #[test_with_seed(retry=10, seed=*START_SEED, seed_fn=new_seed)] fn test_corpus_for_bash(seed: usize) { diff --git a/cli/src/tests/detect_language.rs b/cli/src/tests/detect_language.rs index c4f41185..a663f891 100644 --- a/cli/src/tests/detect_language.rs +++ b/cli/src/tests/detect_language.rs @@ -1,8 +1,9 @@ -use crate::tests::helpers::fixtures::scratch_dir; +use std::{fs, path::Path}; -use std::path::Path; use tree_sitter_loader::Loader; +use crate::tests::helpers::fixtures::scratch_dir; + #[test] fn detect_language_by_first_line_regex() { let strace_dir = tree_sitter_dir( diff --git a/cli/src/tests/helpers/edits.rs b/cli/src/tests/helpers/edits.rs index 11fd659c..9e8751ca 100644 --- a/cli/src/tests/helpers/edits.rs +++ b/cli/src/tests/helpers/edits.rs @@ -1,7 +1,7 @@ +use std::{ops::Range, str}; + use super::random::Rand; use crate::parse::Edit; -use std::ops::Range; -use std::str; #[derive(Debug)] pub struct ReadRecorder<'a> { diff --git a/cli/src/tests/helpers/fixtures.rs b/cli/src/tests/helpers/fixtures.rs index 6e473a61..786c18ff 100644 --- a/cli/src/tests/helpers/fixtures.rs +++ b/cli/src/tests/helpers/fixtures.rs @@ -1,7 +1,10 @@ +use std::{ + env, fs, + path::{Path, PathBuf}, +}; + use anyhow::Context; use lazy_static::lazy_static; -use std::path::{Path, PathBuf}; -use std::{env, fs}; use tree_sitter::Language; use tree_sitter_highlight::HighlightConfiguration; use tree_sitter_loader::{CompileConfig, Loader}; diff --git a/cli/src/tests/helpers/mod.rs b/cli/src/tests/helpers/mod.rs index 35e4dc86..229c7987 100644 --- a/cli/src/tests/helpers/mod.rs +++ b/cli/src/tests/helpers/mod.rs @@ -5,9 +5,10 @@ pub(super) mod query_helpers; pub(super) mod random; pub(super) mod scope_sequence; +use std::env; + use lazy_static::lazy_static; use rand::Rng; -use std::env; lazy_static! { pub static ref LOG_ENABLED: bool = env::var("TREE_SITTER_LOG").is_ok(); diff --git a/cli/src/tests/helpers/query_helpers.rs b/cli/src/tests/helpers/query_helpers.rs index 608d4914..9e7a6f63 100644 --- a/cli/src/tests/helpers/query_helpers.rs +++ b/cli/src/tests/helpers/query_helpers.rs @@ -1,5 +1,6 @@ -use rand::prelude::Rng; use std::{cmp::Ordering, fmt::Write, ops::Range}; + +use rand::prelude::Rng; use tree_sitter::{ Language, Node, Parser, Point, Query, QueryCapture, QueryCursor, QueryMatch, Tree, TreeCursor, }; diff --git a/cli/src/tests/highlight_test.rs b/cli/src/tests/highlight_test.rs index 77a95d7d..e898b2f6 100644 --- a/cli/src/tests/highlight_test.rs +++ b/cli/src/tests/highlight_test.rs @@ -1,13 +1,18 @@ -use super::helpers::fixtures::{get_highlight_config, get_language, get_language_queries_path}; +use std::{ + ffi::CString, + fs, + os::raw::c_char, + ptr, slice, str, + sync::atomic::{AtomicUsize, Ordering}, +}; + use lazy_static::lazy_static; -use std::ffi::CString; -use std::os::raw::c_char; -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::{fs, ptr, slice, str}; use tree_sitter_highlight::{ c, Error, Highlight, HighlightConfiguration, HighlightEvent, Highlighter, HtmlRenderer, }; +use super::helpers::fixtures::{get_highlight_config, get_language, get_language_queries_path}; + lazy_static! { static ref JS_HIGHLIGHT: HighlightConfiguration = get_highlight_config("javascript", Some("injections.scm"), &HIGHLIGHT_NAMES); diff --git a/cli/src/tests/language_test.rs b/cli/src/tests/language_test.rs index 5528c77c..681b93f3 100644 --- a/cli/src/tests/language_test.rs +++ b/cli/src/tests/language_test.rs @@ -1,6 +1,7 @@ -use super::helpers::fixtures::get_language; use tree_sitter::Parser; +use super::helpers::fixtures::get_language; + #[test] fn test_lookahead_iterator() { let mut parser = Parser::new(); diff --git a/cli/src/tests/node_test.rs b/cli/src/tests/node_test.rs index 193b4562..5e50beaf 100644 --- a/cli/src/tests/node_test.rs +++ b/cli/src/tests/node_test.rs @@ -1,11 +1,14 @@ -use super::helpers::edits::get_random_edit; -use super::helpers::fixtures::{fixtures_dir, get_language, get_test_language}; -use super::helpers::random::Rand; -use crate::generate::generate_parser_for_grammar; -use crate::parse::perform_edit; use std::fs; + use tree_sitter::{Node, Parser, Point, Tree}; +use super::helpers::{ + edits::get_random_edit, + fixtures::{fixtures_dir, get_language, get_test_language}, + random::Rand, +}; +use crate::{generate::generate_parser_for_grammar, parse::perform_edit}; + const JSON_EXAMPLE: &str = r#" [ diff --git a/cli/src/tests/parser_hang_test.rs b/cli/src/tests/parser_hang_test.rs index 0c742d80..52243496 100644 --- a/cli/src/tests/parser_hang_test.rs +++ b/cli/src/tests/parser_hang_test.rs @@ -1,15 +1,17 @@ // For some reasons `Command::spawn` doesn't work in CI env for many exotic arches. #![cfg(all(any(target_arch = "x86_64", target_arch = "x86"), not(sanitizing)))] +use std::{ + env::VarError, + process::{Command, Stdio}, +}; + +use tree_sitter::Parser; + use crate::{ generate::{generate_parser_for_grammar, load_grammar_file}, tests::helpers::fixtures::{fixtures_dir, get_test_language}, }; -use std::{ - env::VarError, - process::{Command, Stdio}, -}; -use tree_sitter::Parser; // The `sanitizing` cfg is required to don't run tests under specific sunitizer // because they don't work well with subprocesses _(it's an assumption)_. diff --git a/cli/src/tests/parser_test.rs b/cli/src/tests/parser_test.rs index 725a165f..53a2f02d 100644 --- a/cli/src/tests/parser_test.rs +++ b/cli/src/tests/parser_test.rs @@ -1,3 +1,12 @@ +use std::{ + fs, + sync::atomic::{AtomicUsize, Ordering}, + thread, time, +}; + +use tree_sitter::{IncludedRangesError, InputEdit, LogType, Parser, Point, Range}; +use tree_sitter_proc_macro::retry; + use super::helpers::{ allocations, edits::{invert_edit, ReadRecorder}, @@ -8,13 +17,6 @@ use crate::{ parse::{perform_edit, Edit}, tests::helpers::fixtures::fixtures_dir, }; -use std::{ - fs, - sync::atomic::{AtomicUsize, Ordering}, - thread, time, -}; -use tree_sitter::{IncludedRangesError, InputEdit, LogType, Parser, Point, Range}; -use tree_sitter_proc_macro::retry; #[test] fn test_parsing_simple_string() { diff --git a/cli/src/tests/pathological_test.rs b/cli/src/tests/pathological_test.rs index 7e6dad16..6e008a65 100644 --- a/cli/src/tests/pathological_test.rs +++ b/cli/src/tests/pathological_test.rs @@ -1,6 +1,7 @@ -use super::helpers::{allocations, fixtures::get_language}; use tree_sitter::Parser; +use super::helpers::{allocations, fixtures::get_language}; + #[test] fn test_pathological_example_1() { let language = "cpp"; diff --git a/cli/src/tests/query_test.rs b/cli/src/tests/query_test.rs index e2c3fd82..39a4c986 100644 --- a/cli/src/tests/query_test.rs +++ b/cli/src/tests/query_test.rs @@ -1,3 +1,14 @@ +use std::{env, fmt::Write}; + +use indoc::indoc; +use lazy_static::lazy_static; +use rand::{prelude::StdRng, SeedableRng}; +use tree_sitter::{ + CaptureQuantifier, Language, Node, Parser, Point, Query, QueryCursor, QueryError, + QueryErrorKind, QueryPredicate, QueryPredicateArg, QueryProperty, +}; +use unindent::Unindent; + use super::helpers::{ allocations, fixtures::{get_language, get_test_language}, @@ -8,15 +19,6 @@ use crate::{ generate::generate_parser_for_grammar, tests::helpers::query_helpers::{collect_captures, collect_matches}, }; -use indoc::indoc; -use lazy_static::lazy_static; -use rand::{prelude::StdRng, SeedableRng}; -use std::{env, fmt::Write}; -use tree_sitter::{ - CaptureQuantifier, Language, Node, Parser, Point, Query, QueryCursor, QueryError, - QueryErrorKind, QueryPredicate, QueryPredicateArg, QueryProperty, -}; -use unindent::Unindent; lazy_static! { static ref EXAMPLE_FILTER: Option = env::var("TREE_SITTER_TEST_EXAMPLE_FILTER").ok(); diff --git a/cli/src/tests/tags_test.rs b/cli/src/tests/tags_test.rs index a6a2d135..cb07fb75 100644 --- a/cli/src/tests/tags_test.rs +++ b/cli/src/tests/tags_test.rs @@ -1,14 +1,16 @@ -use super::helpers::{ - allocations, - fixtures::{get_language, get_language_queries_path}, -}; use std::{ ffi::{CStr, CString}, fs, ptr, slice, str, }; + use tree_sitter::Point; use tree_sitter_tags::{c_lib as c, Error, TagsConfiguration, TagsContext}; +use super::helpers::{ + allocations, + fixtures::{get_language, get_language_queries_path}, +}; + const PYTHON_TAG_QUERY: &str = r#" ( (function_definition diff --git a/cli/src/tests/test_highlight_test.rs b/cli/src/tests/test_highlight_test.rs index 92ac76d7..8699c2a6 100644 --- a/cli/src/tests/test_highlight_test.rs +++ b/cli/src/tests/test_highlight_test.rs @@ -1,9 +1,12 @@ -use super::helpers::fixtures::{get_highlight_config, get_language, test_loader}; -use crate::query_testing::{parse_position_comments, Assertion}; -use crate::test_highlight::get_highlight_positions; use tree_sitter::{Parser, Point}; use tree_sitter_highlight::{Highlight, Highlighter}; +use super::helpers::fixtures::{get_highlight_config, get_language, test_loader}; +use crate::{ + query_testing::{parse_position_comments, Assertion}, + test_highlight::get_highlight_positions, +}; + #[test] fn test_highlight_test_with_basic_test() { let language = get_language("javascript"); diff --git a/cli/src/tests/test_tags_test.rs b/cli/src/tests/test_tags_test.rs index 3efba9ed..5e7bf9c9 100644 --- a/cli/src/tests/test_tags_test.rs +++ b/cli/src/tests/test_tags_test.rs @@ -1,9 +1,12 @@ -use super::helpers::fixtures::{get_language, get_tags_config}; -use crate::query_testing::{parse_position_comments, Assertion}; -use crate::test_tags::get_tag_positions; use tree_sitter::{Parser, Point}; use tree_sitter_tags::TagsContext; +use super::helpers::fixtures::{get_language, get_tags_config}; +use crate::{ + query_testing::{parse_position_comments, Assertion}, + test_tags::get_tag_positions, +}; + #[test] fn test_tags_test_with_basic_test() { let language = get_language("python"); diff --git a/cli/src/tests/text_provider_test.rs b/cli/src/tests/text_provider_test.rs index b0b70243..e35e20ec 100644 --- a/cli/src/tests/text_provider_test.rs +++ b/cli/src/tests/text_provider_test.rs @@ -1,8 +1,9 @@ use std::{iter, sync::Arc}; -use crate::tests::helpers::fixtures::get_language; use tree_sitter::{Language, Node, Parser, Point, Query, QueryCursor, TextProvider, Tree}; +use crate::tests::helpers::fixtures::get_language; + fn parse_text(text: impl AsRef<[u8]>) -> (Tree, Language) { let language = get_language("c"); let mut parser = Parser::new(); diff --git a/cli/src/tests/tree_test.rs b/cli/src/tests/tree_test.rs index f498c5fc..fb7297a9 100644 --- a/cli/src/tests/tree_test.rs +++ b/cli/src/tests/tree_test.rs @@ -1,9 +1,10 @@ -use super::helpers::edits::invert_edit; -use super::helpers::fixtures::get_language; -use crate::parse::{perform_edit, Edit}; use std::str; + use tree_sitter::{InputEdit, Parser, Point, Range, Tree}; +use super::helpers::{edits::invert_edit, fixtures::get_language}; +use crate::parse::{perform_edit, Edit}; + #[test] fn test_tree_edit() { let mut parser = Parser::new(); diff --git a/cli/src/tests/wasm_language_test.rs b/cli/src/tests/wasm_language_test.rs index 61c468cd..cf36dc57 100644 --- a/cli/src/tests/wasm_language_test.rs +++ b/cli/src/tests/wasm_language_test.rs @@ -1,10 +1,12 @@ -use crate::tests::helpers::{allocations, fixtures::WASM_DIR}; -use lazy_static::lazy_static; use std::fs; + +use lazy_static::lazy_static; use tree_sitter::{ wasmtime::Engine, Parser, Query, QueryCursor, WasmError, WasmErrorKind, WasmStore, }; +use crate::tests::helpers::{allocations, fixtures::WASM_DIR}; + lazy_static! { static ref ENGINE: Engine = Engine::default(); } diff --git a/cli/src/wasm.rs b/cli/src/wasm.rs index ae77ba4e..eaacef36 100644 --- a/cli/src/wasm.rs +++ b/cli/src/wasm.rs @@ -1,13 +1,15 @@ -use super::generate::parse_grammar::GrammarJSON; -use anyhow::{anyhow, Context, Result}; use std::{ fs, path::{Path, PathBuf}, }; + +use anyhow::{anyhow, Context, Result}; use tree_sitter::wasm_stdlib_symbols; use tree_sitter_loader::Loader; use wasmparser::Parser; +use super::generate::parse_grammar::GrammarJSON; + pub fn load_language_wasm_file(language_dir: &Path) -> Result<(String, Vec)> { let grammar_name = get_grammar_name(language_dir) .with_context(|| "Failed to get wasm filename") diff --git a/highlight/src/c_lib.rs b/highlight/src/c_lib.rs index 6b4d1cf8..6fd385b9 100644 --- a/highlight/src/c_lib.rs +++ b/highlight/src/c_lib.rs @@ -1,13 +1,13 @@ -use super::{Error, Highlight, HighlightConfiguration, Highlighter, HtmlRenderer}; +use std::{ + collections::HashMap, ffi::CStr, fmt, os::raw::c_char, process::abort, slice, str, + sync::atomic::AtomicUsize, +}; + use regex::Regex; -use std::collections::HashMap; -use std::ffi::CStr; -use std::os::raw::c_char; -use std::process::abort; -use std::sync::atomic::AtomicUsize; -use std::{fmt, slice, str}; use tree_sitter::Language; +use super::{Error, Highlight, HighlightConfiguration, Highlighter, HtmlRenderer}; + pub struct TSHighlighter { languages: HashMap, HighlightConfiguration)>, attribute_strings: Vec<&'static [u8]>, diff --git a/highlight/src/lib.rs b/highlight/src/lib.rs index 22c0bc86..192b90d9 100644 --- a/highlight/src/lib.rs +++ b/highlight/src/lib.rs @@ -1,12 +1,14 @@ #![doc = include_str!("../README.md")] pub mod c_lib; -pub use c_lib as c; +use std::{ + collections::HashSet, + iter, mem, ops, str, + sync::atomic::{AtomicUsize, Ordering}, +}; +pub use c_lib as c; use lazy_static::lazy_static; -use std::collections::HashSet; -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::{iter, mem, ops, str, usize}; use thiserror::Error; use tree_sitter::{ Language, LossyUtf8, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError, diff --git a/lib/binding_rust/build.rs b/lib/binding_rust/build.rs index 9203704d..19cb0f6e 100644 --- a/lib/binding_rust/build.rs +++ b/lib/binding_rust/build.rs @@ -1,5 +1,7 @@ -use std::path::{Path, PathBuf}; -use std::{env, fs}; +use std::{ + env, fs, + path::{Path, PathBuf}, +}; fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); diff --git a/lib/binding_rust/ffi.rs b/lib/binding_rust/ffi.rs index 23b9e33f..7cfca1ff 100644 --- a/lib/binding_rust/ffi.rs +++ b/lib/binding_rust/ffi.rs @@ -18,10 +18,11 @@ extern "C" { pub(crate) fn _ts_dup(handle: *mut std::os::raw::c_void) -> std::os::raw::c_int; } +use std::{marker::PhantomData, mem::ManuallyDrop, ptr::NonNull, str}; + use crate::{ Language, LookaheadIterator, Node, Parser, Query, QueryCursor, QueryError, Tree, TreeCursor, }; -use std::{marker::PhantomData, mem::ManuallyDrop, ptr::NonNull, str}; impl Language { /// Reconstructs a [`Language`] from a raw pointer. diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 45626c14..2928f1cd 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -7,7 +7,6 @@ mod util; use std::os::unix::io::AsRawFd; #[cfg(windows)] use std::os::windows::io::AsRawHandle; - use std::{ char, error, ffi::CStr, @@ -21,7 +20,6 @@ use std::{ ptr::{self, NonNull}, slice, str, sync::atomic::AtomicUsize, - u16, }; #[cfg(feature = "wasm")] diff --git a/lib/binding_rust/util.rs b/lib/binding_rust/util.rs index 69e5ec7c..89970e95 100644 --- a/lib/binding_rust/util.rs +++ b/lib/binding_rust/util.rs @@ -1,6 +1,7 @@ -use super::FREE_FN; use std::os::raw::c_void; +use super::FREE_FN; + /// A raw pointer and a length, exposed as an iterator. pub struct CBufferIter { ptr: *mut T, diff --git a/lib/binding_rust/wasm_language.rs b/lib/binding_rust/wasm_language.rs index 3138bca4..2b44dc8c 100644 --- a/lib/binding_rust/wasm_language.rs +++ b/lib/binding_rust/wasm_language.rs @@ -1,4 +1,3 @@ -use crate::{ffi, Language, LanguageError, Parser, FREE_FN}; use std::{ error, ffi::{CStr, CString}, @@ -6,8 +5,11 @@ use std::{ mem::{self, MaybeUninit}, os::raw::c_char, }; + pub use wasmtime_c_api::wasmtime; +use crate::{ffi, Language, LanguageError, Parser, FREE_FN}; + // Force Cargo to include wasmtime-c-api as a dependency of this crate, // even though it is only used by the C code. #[allow(unused)] diff --git a/tags/src/c_lib.rs b/tags/src/c_lib.rs index ece53720..6041642d 100644 --- a/tags/src/c_lib.rs +++ b/tags/src/c_lib.rs @@ -1,12 +1,12 @@ -use super::{Error, TagsConfiguration, TagsContext}; -use std::collections::HashMap; -use std::ffi::CStr; -use std::os::raw::c_char; -use std::process::abort; -use std::sync::atomic::AtomicUsize; -use std::{fmt, slice, str}; +use std::{ + collections::HashMap, ffi::CStr, fmt, os::raw::c_char, process::abort, slice, str, + sync::atomic::AtomicUsize, +}; + use tree_sitter::Language; +use super::{Error, TagsConfiguration, TagsContext}; + const BUFFER_TAGS_RESERVE_CAPACITY: usize = 100; const BUFFER_DOCS_RESERVE_CAPACITY: usize = 1024; diff --git a/tags/src/lib.rs b/tags/src/lib.rs index 797e59c7..d8dad5c6 100644 --- a/tags/src/lib.rs +++ b/tags/src/lib.rs @@ -2,14 +2,19 @@ pub mod c_lib; +use std::{ + char, + collections::HashMap, + ffi::{CStr, CString}, + mem, + ops::Range, + os::raw::c_char, + str, + sync::atomic::{AtomicUsize, Ordering}, +}; + use memchr::memchr; use regex::Regex; -use std::collections::HashMap; -use std::ffi::{CStr, CString}; -use std::ops::Range; -use std::os::raw::c_char; -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::{char, mem, str}; use thiserror::Error; use tree_sitter::{ Language, LossyUtf8, Parser, Point, Query, QueryCursor, QueryError, QueryPredicateArg, Tree, diff --git a/xtask/src/bump.rs b/xtask/src/bump.rs index e9889036..4e0fc400 100644 --- a/xtask/src/bump.rs +++ b/xtask/src/bump.rs @@ -1,5 +1,4 @@ -use std::cmp::Ordering; -use std::path::Path; +use std::{cmp::Ordering, path::Path}; use git2::{DiffOptions, Repository}; use indoc::indoc;