on master help sign in
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.

commitf04d2a9d6a45739861168074d6f3dd84544c318c authorMartin Nordholts <enselic@gmail.com> dateMon 20 Sep 2021, 20:33 (5 years ago) parenteb3b3b9
1 file changed+24−24
src/assets/build_assets.rs+24−24
src/assets/build_assets.rs+24−24
@@ -11,18 +11,18 @@ use crate::assets::*;
1111type SyntaxName = String;
1212
1313/// Used to look up what dependencies a given [SyntaxDefinition] has
14−type SyntaxToDependencies = HashMap<SyntaxName, Vec<Dependency>>;
14+type SyntaxToDependencies = HashMap<SyntaxName, Vec<OtherSyntax>>;
1515
16−/// Used to look up which [SyntaxDefinition] corresponds to a given [Dependency]
17−type DependencyToSyntax<'a> = HashMap<Dependency, &'a SyntaxDefinition>;
16+/// Used to look up which [SyntaxDefinition] corresponds to a given [OtherSyntax]
17+type OtherSyntaxLookup<'a> = HashMap<OtherSyntax, &'a SyntaxDefinition>;
1818
19−/// Represents a dependency on an external `.sublime-syntax` file.
19+/// Represents some other `*.sublime-syntax` file, i.e. another [SyntaxDefinition].
2020#[derive(Debug, Eq, PartialEq, Clone, Hash)]
21−enum Dependency {
22− /// By name. Example YAML: `include: C.sublime-syntax`
21+enum OtherSyntax {
22+ /// By name. Example YAML: `include: C.sublime-syntax` (name is `"C"`)
2323 ByName(String),
2424
25− /// By scope. Example YAML: `embed: scope:source.c`
25+ /// By scope. Example YAML: `embed: scope:source.c` (scope is `"source.c"`)
2626 ByScope(Scope),
2727}
2828
@@ -215,7 +215,7 @@ fn build_minimal_syntax_sets(
215215 let syntaxes = syntax_set_builder.syntaxes();
216216
217217 // Build the data structures we need for dependency resolution
218− let (syntax_to_dependencies, dependency_to_syntax) = generate_maps(syntaxes);
218+ let (syntax_to_dependencies, other_syntax_lookup) = generate_maps(syntaxes);
219219
220220 // Create one minimal SyntaxSet from each (non-hidden) SyntaxDefinition
221221 syntaxes.iter().filter_map(move |syntax| {
@@ -224,7 +224,7 @@ fn build_minimal_syntax_sets(
224224 }
225225
226226 let mut builder = SyntaxSetDependencyBuilder::new();
227− builder.add_with_dependencies(syntax, &syntax_to_dependencies, &dependency_to_syntax);
227+ builder.add_with_dependencies(syntax, &syntax_to_dependencies, &other_syntax_lookup);
228228 let syntax_set = builder.build();
229229
230230 if std::env::var("BAT_PRINT_SYNTAX_DEPENDENCIES").is_ok() {
@@ -238,21 +238,21 @@ fn build_minimal_syntax_sets(
238238}
239239
240240/// In order to analyze dependencies, we need two key pieces of data.
241−/// First, when we have a [Dependency], we need to know what [SyntaxDefinition] that
241+/// First, when we have a [OtherSyntax], we need to know what [SyntaxDefinition] that
242242/// corresponds to. Second, when we have a [SyntaxDefinition], we need to know
243243/// what dependencies it has. This functions generates that data for each syntax.
244−fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, DependencyToSyntax) {
244+fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, OtherSyntaxLookup) {
245245 let mut syntax_to_dependencies = HashMap::new();
246− let mut dependency_to_syntax = HashMap::new();
246+ let mut other_syntax_lookup = HashMap::new();
247247
248248 for syntax in syntaxes {
249249 syntax_to_dependencies.insert(syntax.name.clone(), dependencies_for_syntax(syntax));
250250
251− dependency_to_syntax.insert(Dependency::ByName(syntax.name.clone()), syntax);
252− dependency_to_syntax.insert(Dependency::ByScope(syntax.scope), syntax);
251+ other_syntax_lookup.insert(OtherSyntax::ByName(syntax.name.clone()), syntax);
252+ other_syntax_lookup.insert(OtherSyntax::ByScope(syntax.scope), syntax);
253253 }
254254
255− (syntax_to_dependencies, dependency_to_syntax)
255+ (syntax_to_dependencies, other_syntax_lookup)
256256}
257257
258258/// Gets what external dependencies a given [SyntaxDefinition] has.
@@ -260,8 +260,8 @@ fn generate_maps(syntaxes: &[SyntaxDefinition]) -> (SyntaxToDependencies, Depend
260260/// It does that by looking for variants of the following YAML patterns:
261261/// - `include: C.sublime-syntax`
262262/// - `embed: scope:source.c`
263−fn dependencies_for_syntax(syntax: &SyntaxDefinition) -> Vec<Dependency> {
264− let mut dependencies: Vec<Dependency> = syntax
263+fn dependencies_for_syntax(syntax: &SyntaxDefinition) -> Vec<OtherSyntax> {
264+ let mut dependencies: Vec<OtherSyntax> = syntax
265265 .contexts
266266 .values()
267267 .flat_map(|context| &context.patterns)
@@ -274,7 +274,7 @@ fn dependencies_for_syntax(syntax: &SyntaxDefinition) -> Vec<Dependency> {
274274 dependencies
275275}
276276
277−fn dependencies_from_pattern(pattern: &Pattern) -> Vec<Dependency> {
277+fn dependencies_from_pattern(pattern: &Pattern) -> Vec<OtherSyntax> {
278278 match *pattern {
279279 Pattern::Match(MatchPattern {
280280 operation: MatchOperation::Push(ref context_references),
@@ -293,10 +293,10 @@ fn dependencies_from_pattern(pattern: &Pattern) -> Vec<Dependency> {
293293 .collect()
294294}
295295
296−fn dependency_from_context_reference(context_reference: &ContextReference) -> Option<Dependency> {
296+fn dependency_from_context_reference(context_reference: &ContextReference) -> Option<OtherSyntax> {
297297 match &context_reference {
298− ContextReference::File { ref name, .. } => Some(Dependency::ByName(name.clone())),
299− ContextReference::ByScope { ref scope, .. } => Some(Dependency::ByScope(*scope)),
298+ ContextReference::File { ref name, .. } => Some(OtherSyntax::ByName(name.clone())),
299+ ContextReference::ByScope { ref scope, .. } => Some(OtherSyntax::ByScope(*scope)),
300300 _ => None,
301301 }
302302}
@@ -321,7 +321,7 @@ impl SyntaxSetDependencyBuilder {
321321 &mut self,
322322 syntax: &SyntaxDefinition,
323323 syntax_to_dependencies: &SyntaxToDependencies,
324− dependency_to_syntax: &DependencyToSyntax,
324+ other_syntax_lookup: &OtherSyntaxLookup,
325325 ) {
326326 let name = &syntax.name;
327327 if self.is_syntax_already_added(name) {
@@ -337,11 +337,11 @@ impl SyntaxSetDependencyBuilder {
337337 }
338338
339339 for dependency in dependencies.unwrap() {
340− if let Some(syntax_definition_dependency) = dependency_to_syntax.get(dependency) {
340+ if let Some(syntax_definition_dependency) = other_syntax_lookup.get(dependency) {
341341 self.add_with_dependencies(
342342 syntax_definition_dependency,
343343 syntax_to_dependencies,
344− dependency_to_syntax,
344+ other_syntax_lookup,
345345 )
346346 }
347347 }