diff options
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/eval.cc | 12 | ||||
-rw-r--r-- | src/libexpr/get-drvs.cc | 7 | ||||
-rw-r--r-- | src/libexpr/nixexpr-ast.def | 9 | ||||
-rw-r--r-- | src/libexpr/nixexpr.cc | 15 | ||||
-rw-r--r-- | src/libexpr/nixexpr.hh | 3 | ||||
-rw-r--r-- | src/libexpr/parser.cc | 6 | ||||
-rw-r--r-- | src/libexpr/parser.y | 7 |
7 files changed, 33 insertions, 26 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 5315619d4..e45de729b 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -37,15 +37,17 @@ static Expr substArgs(Expr body, ATermList formals, Expr arg) ATermVector defsUsed; ATermList recAttrs = ATempty; for (ATermIterator i(formals); i; ++i) { - Expr name, def = 0; - if (!matchNoDefFormal(*i, name) && !matchDefFormal(*i, name, def)) - abort(); /* can't happen */ + Expr name, def; DefaultValue def2; ATerm dummy; + if (!matchFormal(*i, name, dummy, def2)) abort(); /* can't happen */ + if (!matchDefaultValue(def2, def)) def = 0; if (subs[name] == 0) { if (def == 0) throw TypeError(format("the argument named `%1%' required by the function is missing") % aterm2String(name)); defsUsed.push_back(name); recAttrs = ATinsert(recAttrs, makeBind(name, def, makeNoPos())); } + /* !!! check that the argument are in the valid values list, + if present */ } /* Make a recursive attribute set out of the (argument-name, @@ -64,8 +66,8 @@ static Expr substArgs(Expr body, ATermList formals, Expr arg) /* One or more actual arguments were not declared as formal arguments. Find out which. */ for (ATermIterator i(formals); i; ++i) { - Expr name, def; - matchNoDefFormal(*i, name) || matchDefFormal(*i, name, def); + Expr name; ATerm d1, d2; + matchFormal(*i, name, d1, d2); subs.remove(name); } throw TypeError(format("the function does not expect an argument named `%1%'") diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index 82e34f776..05b4897cf 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -121,12 +121,11 @@ static void getDerivations(EvalState & state, Expr e, ATerm body, pos; if (matchFunction(e, formals, body, pos)) { for (ATermIterator i(formals); i; ++i) { - Expr name, def; - if (matchNoDefFormal(*i, name)) + Expr name, def; ATerm values, def2; + if (!matchFormal(*i, name, values, def2)) abort(); + if (!matchDefaultValue(def2, def)) throw TypeError(format("cannot auto-call a function that has an argument without a default value (`%1%')") % aterm2String(name)); - else if (!matchDefFormal(*i, name, def)) - abort(); /* can't happen */ } getDerivations(state, makeCall(e, makeAttrs(ATermMap(0))), diff --git a/src/libexpr/nixexpr-ast.def b/src/libexpr/nixexpr-ast.def index a4565ab1f..4a92eaebf 100644 --- a/src/libexpr/nixexpr-ast.def +++ b/src/libexpr/nixexpr-ast.def @@ -45,8 +45,13 @@ Inherit | Expr ATermList Pos | ATerm | Scope | | Expr | -NoDefFormal | string | ATerm | -DefFormal | string Expr | ATerm | +Formal | string ValidValues DefaultValue | ATerm | + +ValidValues | ATermList | ValidValues | +UnrestrictedValues | | ValidValues | + +DefaultValue | Expr | DefaultValue | +NoDefaultValue | | DefaultValue | True | | ATerm | False | | ATerm | diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 938670f5b..cbcaec584 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -134,9 +134,8 @@ Expr substitute(const Substitution & subs, Expr e) if (matchFunction(e, formals, body, pos)) { ATermMap map(ATgetLength(formals)); for (ATermIterator i(formals); i; ++i) { - if (!matchNoDefFormal(*i, name) && - !matchDefFormal(*i, name, def)) - abort(); + ATerm d1, d2; + if (!matchFormal(*i, name, d1, d2)) abort(); map.set(name, makeRemoved()); } Substitution subs2(&subs, &map); @@ -221,16 +220,14 @@ static void checkVarDefs2(set<Expr> & done, const ATermMap & defs, Expr e) else if (matchFunction(e, formals, body, pos)) { ATermMap defs2(defs); for (ATermIterator i(formals); i; ++i) { - Expr deflt; - if (!matchNoDefFormal(*i, name) && - !matchDefFormal(*i, name, deflt)) - abort(); + Expr d1, d2; + if (!matchFormal(*i, name, d1, d2)) abort(); defs2.set(name, (ATerm) ATempty); } for (ATermIterator i(formals); i; ++i) { - Expr deflt; + Expr dummy, deflt; set<Expr> done2; - if (matchDefFormal(*i, name, deflt)) + if (matchFormal(*i, name, dummy, deflt)) /* !!! check dummy */ checkVarDefs2(done2, defs2, deflt); } set<Expr> done2; diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 4dc235c8e..6e67e5ebd 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -19,6 +19,9 @@ MakeError(TypeError, EvalError) normals forms efficiently. */ typedef ATerm Expr; +typedef ATerm DefaultValue; +typedef ATerm ValidValues; + typedef ATerm Pos; diff --git a/src/libexpr/parser.cc b/src/libexpr/parser.cc index 5c2c85cd7..7adbcb618 100644 --- a/src/libexpr/parser.cc +++ b/src/libexpr/parser.cc @@ -118,10 +118,8 @@ static void checkAttrSets(ATerm e) ATermMap names(ATgetLength(formals)); for (ATermIterator i(formals); i; ++i) { ATerm name; - Expr deflt; - if (!matchNoDefFormal(*i, name) && - !matchDefFormal(*i, name, deflt)) - abort(); + ATerm d1, d2; + if (!matchFormal(*i, name, d1, d2)) abort(); if (names.get(name)) throw EvalError(format("duplicate formal function argument `%1%' at %2%") % aterm2String(name) % showPos(pos)); diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index cba390d8d..b28aa2760 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -16,6 +16,8 @@ #include "lexer-tab.h" typedef ATerm Expr; +typedef ATerm ValidValues; +typedef ATerm DefaultValue; typedef ATerm Pos; #include "nixexpr-ast.hh" @@ -203,8 +205,9 @@ formals ; formal - : ID { $$ = makeNoDefFormal($1); } - | ID '?' expr { $$ = makeDefFormal($1, $3); } + : ID { $$ = makeFormal($1, makeUnrestrictedValues(), makeNoDefaultValue()); } +// | ID ':' '[' expr_list ']' { $$ = makeDefFormal($1, $3); } + | ID '?' expr { $$ = makeFormal($1, makeUnrestrictedValues(), makeDefaultValue($3)); } ; %% |