From f04d2a9d6a45739861168074d6f3dd84544c318c Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Mon, 20 Sep 2021 20:33:01 +0200 Subject: [PATCH] build_assets.rs: Rename 'Dependency' to 'OtherSyntax' So that we later can use it for not only information about dependencies, but also for information about dependents. --- src/assets/build_assets.rs | 48 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/assets/build_assets.rs b/src/assets/build_assets.rs index e88890c5..3583f55b 100644 --- a/src/assets/build_assets.rs +++ b/src/assets/build_assets.rs @@ -11,18 +11,18 @@ use crate::assets::*; type SyntaxName = String; /// Used to look up what dependencies a given [SyntaxDefinition] has -type SyntaxToDependencies = HashMap>; +type SyntaxToDependencies = HashMap>; -/// Used to look up which [SyntaxDefinition] corresponds to a given [Dependency] -type DependencyToSyntax<'a> = HashMap; +/// Used to look up which [SyntaxDefinition] corresponds to a given [OtherSyntax] +type OtherSyntaxLookup<'a> = HashMap; -/// Represents a dependency on an external `.sublime-syntax` file. +/// Represents some other `*.sublime-syntax` file, i.e. another [SyntaxDefinition]. #[derive(Debug, Eq, PartialEq, Clone, Hash)] -enum Dependency { - /// By name. Example YAML: `include: C.sublime-syntax` +enum OtherSyntax { + /// By name. Example YAML: `include: C.sublime-syntax` (name is `"C"`) ByName(String), - /// By scope. Example YAML: `embed: scope:source.c` + /// By scope. Example YAML: `embed: scope:source.c` (scope is `"source.c"`) ByScope(Scope), } @@ -215,7 +215,7 @@ fn build_minimal_syntax_sets( let syntaxes = syntax_set_builder.syntaxes(); // Build the data structures we need for dependency resolution - let (syntax_to_dependencies, dependency_to_syntax) = generate_maps(syntaxes); + let (syntax_to_dependencies, other_syntax_lookup) = generate_maps(syntaxes); // Create one minimal SyntaxSet from each (non-hidden) SyntaxDefinition syntaxes.iter().filter_map(move |syntax| { @@ -224,7 +224,7 @@ fn build_minimal_syntax_sets( } let mut builder = SyntaxSetDependencyBuilder::new(); - builder.add_with_dependencies(syntax, &syntax_to_dependencies, &dependency_to_syntax); + builder.add_with_dependencies(syntax, &syntax_to_dependencies, &other_syntax_lookup); let syntax_set = builder.build(); if std::env::var("BAT_PRINT_SYNTAX_DEPENDENCIES").is_ok() { @@ -238,21 +238,21 @@ fn build_minimal_syntax_sets( } /// In order to analyze dependencies, we need two key pieces of data. -/// First, when we have a [Dependency], we need to know what [SyntaxDefinition] that +/// First, when we have a [OtherSyntax], we need to know what [SyntaxDefinition] that /// corresponds to. Second, when we have a [SyntaxDefinition], we need to know /// what dependencies it has. This functions generates that data for each syntax. -fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, DependencyToSyntax) { +fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, OtherSyntaxLookup) { let mut syntax_to_dependencies = HashMap::new(); - let mut dependency_to_syntax = HashMap::new(); + let mut other_syntax_lookup = HashMap::new(); for syntax in syntaxes { syntax_to_dependencies.insert(syntax.name.clone(), dependencies_for_syntax(syntax)); - dependency_to_syntax.insert(Dependency::ByName(syntax.name.clone()), syntax); - dependency_to_syntax.insert(Dependency::ByScope(syntax.scope), syntax); + other_syntax_lookup.insert(OtherSyntax::ByName(syntax.name.clone()), syntax); + other_syntax_lookup.insert(OtherSyntax::ByScope(syntax.scope), syntax); } - (syntax_to_dependencies, dependency_to_syntax) + (syntax_to_dependencies, other_syntax_lookup) } /// Gets what external dependencies a given [SyntaxDefinition] has. @@ -260,8 +260,8 @@ fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, Depend /// It does that by looking for variants of the following YAML patterns: /// - `include: C.sublime-syntax` /// - `embed: scope:source.c` -fn dependencies_for_syntax(syntax: &SyntaxDefinition) -> Vec { - let mut dependencies: Vec = syntax +fn dependencies_for_syntax(syntax: &SyntaxDefinition) -> Vec { + let mut dependencies: Vec = syntax .contexts .values() .flat_map(|context| &context.patterns) @@ -274,7 +274,7 @@ fn dependencies_for_syntax(syntax: &SyntaxDefinition) -> Vec { dependencies } -fn dependencies_from_pattern(pattern: &Pattern) -> Vec { +fn dependencies_from_pattern(pattern: &Pattern) -> Vec { match *pattern { Pattern::Match(MatchPattern { operation: MatchOperation::Push(ref context_references), @@ -293,10 +293,10 @@ fn dependencies_from_pattern(pattern: &Pattern) -> Vec { .collect() } -fn dependency_from_context_reference(context_reference: &ContextReference) -> Option { +fn dependency_from_context_reference(context_reference: &ContextReference) -> Option { match &context_reference { - ContextReference::File { ref name, .. } => Some(Dependency::ByName(name.clone())), - ContextReference::ByScope { ref scope, .. } => Some(Dependency::ByScope(*scope)), + ContextReference::File { ref name, .. } => Some(OtherSyntax::ByName(name.clone())), + ContextReference::ByScope { ref scope, .. } => Some(OtherSyntax::ByScope(*scope)), _ => None, } } @@ -321,7 +321,7 @@ impl SyntaxSetDependencyBuilder { &mut self, syntax: &SyntaxDefinition, syntax_to_dependencies: &SyntaxToDependencies, - dependency_to_syntax: &DependencyToSyntax, + other_syntax_lookup: &OtherSyntaxLookup, ) { let name = &syntax.name; if self.is_syntax_already_added(name) { @@ -337,11 +337,11 @@ impl SyntaxSetDependencyBuilder { } for dependency in dependencies.unwrap() { - if let Some(syntax_definition_dependency) = dependency_to_syntax.get(dependency) { + if let Some(syntax_definition_dependency) = other_syntax_lookup.get(dependency) { self.add_with_dependencies( syntax_definition_dependency, syntax_to_dependencies, - dependency_to_syntax, + other_syntax_lookup, ) } }