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/fix.cc | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) (limited to 'src/fix-ng/fix.cc') diff --git a/src/fix-ng/fix.cc b/src/fix-ng/fix.cc index dc2790a60ad9..49f19669a08b 100644 --- a/src/fix-ng/fix.cc +++ b/src/fix-ng/fix.cc @@ -27,37 +27,6 @@ static Path searchPath(const Paths & searchDirs, const Path & relPath) #endif -#if 0 -static Expr evalExpr2(EvalState & state, Expr e) -{ - /* Ad-hoc function for string matching. */ - if (ATmatch(e, "HasSubstr(, )", &e1, &e2)) { - e1 = evalExpr(state, e1); - e2 = evalExpr(state, e2); - - char * s1, * s2; - if (!ATmatch(e1, "", &s1)) - throw badTerm("expecting a string", e1); - if (!ATmatch(e2, "", &s2)) - throw badTerm("expecting a string", e2); - - return - string(s1).find(string(s2)) != string::npos ? - ATmake("True") : ATmake("False"); - } - - /* BaseName primitive function. */ - if (ATmatch(e, "BaseName()", &e1)) { - e1 = evalExpr(state, e1); - if (!ATmatch(e1, "", &s1)) - throw badTerm("string expected", e1); - return ATmake("", baseNameOf(s1).c_str()); - } - -} -#endif - - static Expr evalStdin(EvalState & state) { startNest(nest, lvlTalkative, format("evaluating standard input")); @@ -70,9 +39,10 @@ static Expr evalStdin(EvalState & state) static void printNixExpr(EvalState & state, Expr e) { + ATMatcher m; ATermList es; - 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"); @@ -83,7 +53,7 @@ static void printNixExpr(EvalState & state, Expr e) } } - if (ATmatch(e, "[]", &es)) { + if (ATgetType(e) == AT_LIST) { while (!ATisEmpty(es)) { printNixExpr(state, evalExpr(state, ATgetFirst(es))); es = ATgetNext(es); -- cgit 1.4.1