pep508: Fix incorrect evaluation of groups

This commit is contained in:
adisbladis 2019-11-16 19:23:24 +00:00
parent 17cfb71c37
commit d5a2bce5ec
No known key found for this signature in database
GPG key ID: 110BFAD44C6249B7

View file

@ -43,7 +43,9 @@ let
exprPos = 0;
startPos = 0;
} (lib.stringToCharacters expr);
in acc.exprs ++ [ (substr acc.exprPos acc.pos expr) ];
tailExpr = (substr acc.exprPos acc.pos expr);
tailExprs = if tailExpr != "" then [ tailExpr ] else [];
in acc.exprs ++ tailExprs;
parseExpressions = exprs: let
splitCond = (s: builtins.map
@ -59,11 +61,14 @@ let
else {
type = "expr";
value = expr;
});
}
);
parsed = builtins.filter (x: x != null) (builtins.map mapfn (splitCond exprs));
parse = expr: builtins.filter (x: x != null) (builtins.map mapfn (splitCond expr));
in if builtins.typeOf exprs == "string" then parsed else builtins.map parseExpressions exprs;
in builtins.foldl' (acc: v: acc ++ (
if builtins.typeOf v == "string" then parse v else [(parseExpressions v)]
)) [] exprs;
# Transform individual expressions to structured expressions
# This function also performs variable substitution, replacing environment markers with their explicit values
@ -155,7 +160,6 @@ let
"and" = x: y: x && y;
"or" = x: y: x || y;
};
reduceExpressionsFun = acc: v: (
if builtins.typeOf v == "set" then (
if v.type == "value" then (
@ -168,7 +172,14 @@ let
}
) else throw "Unsupported type"
) else if builtins.typeOf v == "list" then (
builtins.foldl' reduceExpressionsFun acc v
let
ret = builtins.foldl' reduceExpressionsFun {
value = true;
cond = "and";
} v;
in acc // {
value = cond."${acc.cond}" acc.value ret.value;
}
) else throw "Unsupported type"
);
in (builtins.foldl' reduceExpressionsFun {