From 0c7e66d79a68f8ee9293efb32e8a8a9294682559 Mon Sep 17 00:00:00 2001 From: DavHau Date: Fri, 25 Feb 2022 16:40:24 +0700 Subject: [PATCH] refactor translators: introduce `all` --- src/lib/default.nix | 2 +- src/lib/translators.nix | 46 ++++++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/lib/default.nix b/src/lib/default.nix index 76bc4a0d..d53356fe 100644 --- a/src/lib/default.nix +++ b/src/lib/default.nix @@ -33,7 +33,7 @@ let translators = import ./translators.nix { inherit dlib lib; }; discoverers = import ../discoverers { inherit dlib lib; }; - parseUtils = callPackageDream ./parsing.nix {}; + parseUtils = import ./parsing.nix { inherit lib; }; # INTERNAL diff --git a/src/lib/translators.nix b/src/lib/translators.nix index 12ee6ec6..19e0f3e4 100644 --- a/src/lib/translators.nix +++ b/src/lib/translators.nix @@ -13,11 +13,28 @@ let # attrset of: subsystem -> translator-type -> (function subsystem translator-type) mkTranslatorsSet = function: - l.genAttrs (dlib.dirNames ../translators) (subsystem: - l.genAttrs - (l.filter (dir: builtins.pathExists (../translators + "/${subsystem}/${dir}")) translatorTypes) - (transType: function subsystem transType) - ); + l.genAttrs + (dlib.dirNames ../translators) + (subsystem: + let + availableTypes = + l.filter + (type: l.pathExists (../translators + "/${subsystem}/${type}")) + translatorTypes; + + translatorsForTypes = + l.genAttrs + availableTypes + (transType: function subsystem transType); + + in + translatorsForTypes // { + all = + l.foldl' + (a: b: a // b) + {} + (l.attrValues translatorsForTypes); + }); # flat list of all translators sorted by priority (pure translators first) translatorsList = @@ -58,9 +75,22 @@ let # attrset of: subsystem -> translator-type -> translator translators = mkTranslatorsSet (subsystem: type: - l.genAttrs (dlib.dirNames (../translators + "/${subsystem}/${type}")) (translatorName: - callTranslator subsystem type translatorName (../translators + "/${subsystem}/${type}/${translatorName}") {} - ) + let + translatorNames = + dlib.dirNames (../translators + "/${subsystem}/${type}"); + + translatorsLoaded = + l.genAttrs + translatorNames + (translatorName: + callTranslator + subsystem + type + translatorName + (../translators + "/${subsystem}/${type}/${translatorName}") + {}); + in + translatorsLoaded ); mapTranslators = f: