From 3e5a019a070cbaac7d1248e208c66da9fdb23313 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 16 Nov 2003 17:46:31 +0000 Subject: * Some utility functions for working with ATerms. --- src/fix-ng/primops.cc | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'src/fix-ng/primops.cc') diff --git a/src/fix-ng/primops.cc b/src/fix-ng/primops.cc index 07281e89beaf..a68352579753 100644 --- a/src/fix-ng/primops.cc +++ b/src/fix-ng/primops.cc @@ -5,8 +5,9 @@ Expr primImport(EvalState & state, Expr arg) { - char * path; - if (!ATmatch(arg, "Path()", &path)) + ATMatcher m; + string path; + if (!(atMatch(m, arg) >> "Path" >> path)) throw badTerm("path expected", arg); return evalFile(state, path); } @@ -79,15 +80,16 @@ static string processBinding(EvalState & state, Expr e, NixExpr & ne) { e = evalExpr(state, e); - char * s; + ATMatcher m; + string s; ATermList es; - if (ATmatch(e, "Str()", &s)) return s; - if (ATmatch(e, "Uri()", &s)) return s; - if (ATmatch(e, "Bool(True)")) return "1"; - if (ATmatch(e, "Bool(False)")) return ""; + if (atMatch(m, e) >> "Str" >> s) return s; + if (atMatch(m, e) >> "Uri" >> s) return s; + if (atMatch(m, e) >> "Bool" >> "True") return "1"; + if (atMatch(m, e) >> "Bool" >> "False") return ""; - if (ATmatch(e, "Attrs([])", &es)) { + if (atMatch(m, e) >> "Attrs" >> es) { Expr a = queryAttr(e, "type"); if (a && evalString(state, a) == "derivation") { a = queryAttr(e, "drvPath"); @@ -98,12 +100,12 @@ static string processBinding(EvalState & state, Expr e, NixExpr & ne) } } - if (ATmatch(e, "Path()", &s)) { + if (atMatch(m, e) >> "Path" >> s) { Path drvPath = copyAtom(state, s); return addInput(state, drvPath, ne); } - if (ATmatch(e, "List([])", &es)) { + if (atMatch(m, e) >> "List" >> es) { string s; bool first = true; while (!ATisEmpty(es)) { @@ -115,7 +117,7 @@ static string processBinding(EvalState & state, Expr e, NixExpr & ne) return s; } - if (ATmatch(e, "Null")) return ""; + if (atMatch(m, e) >> "Null") return ""; throw badTerm("invalid derivation binding", e); } @@ -148,14 +150,17 @@ Expr primDerivation(EvalState & state, Expr args) /* The `args' attribute is special: it supplies the command-line arguments to the builder. */ if (key == "args") { + throw Error("args not implemented"); +#if 0 ATermList args; - if (!ATmatch(value, "[]", &args)) + if (!(ATmatch(value, "[]", &args)) throw badTerm("list expected", value); while (!ATisEmpty(args)) { Expr arg = evalExpr(state, ATgetFirst(args)); ne.derivation.args.push_back(processBinding(state, arg, ne)); args = ATgetNext(args); } +#endif } /* All other attributes are passed to the builder through the @@ -220,11 +225,12 @@ Expr primBaseNameOf(EvalState & state, Expr arg) Expr primToString(EvalState & state, Expr arg) { arg = evalExpr(state, arg); - char * s; - if (ATmatch(arg, "Str()", &s) || - ATmatch(arg, "Path()", &s) || - ATmatch(arg, "Uri()", &s)) - return ATmake("Str()", s); + ATMatcher m; + string s; + if (atMatch(m, arg) >> "Str" >> s || + atMatch(m, arg) >> "Path" >> s || + atMatch(m, arg) >> "Uri" >> s) + return ATmake("Str()", s.c_str()); else throw badTerm("cannot coerce to string", arg); } @@ -238,5 +244,6 @@ Expr primNull(EvalState & state) Expr primIsNull(EvalState & state, Expr arg) { arg = evalExpr(state, arg); - return makeBool(ATmatch(arg, "Null")); + ATMatcher m; + return makeBool(atMatch(m, arg) >> "Null"); } -- cgit 1.4.1