refactor translators: introduce all

This commit is contained in:
DavHau 2022-02-25 16:40:24 +07:00
parent 5004d7eb5a
commit 0c7e66d79a
2 changed files with 39 additions and 9 deletions

View File

@ -33,7 +33,7 @@ let
translators = import ./translators.nix { inherit dlib lib; }; translators = import ./translators.nix { inherit dlib lib; };
discoverers = import ../discoverers { inherit dlib lib; }; discoverers = import ../discoverers { inherit dlib lib; };
parseUtils = callPackageDream ./parsing.nix {}; parseUtils = import ./parsing.nix { inherit lib; };
# INTERNAL # INTERNAL

View File

@ -13,11 +13,28 @@ let
# attrset of: subsystem -> translator-type -> (function subsystem translator-type) # attrset of: subsystem -> translator-type -> (function subsystem translator-type)
mkTranslatorsSet = function: mkTranslatorsSet = function:
l.genAttrs (dlib.dirNames ../translators) (subsystem:
l.genAttrs l.genAttrs
(l.filter (dir: builtins.pathExists (../translators + "/${subsystem}/${dir}")) translatorTypes) (dlib.dirNames ../translators)
(transType: function subsystem transType) (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) # flat list of all translators sorted by priority (pure translators first)
translatorsList = translatorsList =
@ -58,9 +75,22 @@ let
# attrset of: subsystem -> translator-type -> translator # attrset of: subsystem -> translator-type -> translator
translators = mkTranslatorsSet (subsystem: type: translators = mkTranslatorsSet (subsystem: type:
l.genAttrs (dlib.dirNames (../translators + "/${subsystem}/${type}")) (translatorName: let
callTranslator subsystem type translatorName (../translators + "/${subsystem}/${type}/${translatorName}") {} translatorNames =
) dlib.dirNames (../translators + "/${subsystem}/${type}");
translatorsLoaded =
l.genAttrs
translatorNames
(translatorName:
callTranslator
subsystem
type
translatorName
(../translators + "/${subsystem}/${type}/${translatorName}")
{});
in
translatorsLoaded
); );
mapTranslators = f: mapTranslators = f: