From 215ec2ddc6088be2291722a544c6ab5a1b00a5a1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 24 Aug 2006 14:34:29 +0000 Subject: * New primop __toXML (or builtins.toXML) to convert an expression to an XML representation stored in a string. This should be useful to pass structured information to builders. --- src/libexpr/primops.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/libexpr/primops.cc') diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 3d8d9b8ad7..d82cc5870a 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -5,6 +5,7 @@ #include "eval.hh" #include "globals.hh" #include "nixexpr-ast.hh" +#include "expr-to-xml.hh" static Expr primBuiltins(EvalState & state, const ATermVector & args) @@ -457,6 +458,14 @@ static Expr primToString(EvalState & state, const ATermVector & args) } +static Expr primToXML(EvalState & state, const ATermVector & args) +{ + ostringstream out; + printTermAsXML(strictEvalExpr(state, args[0]), out); + return makeStr(toATerm(out.str())); +} + + /* Boolean constructors. */ static Expr primTrue(EvalState & state, const ATermVector & args) { @@ -705,6 +714,7 @@ void EvalState::addPrimOps() addPrimOp("baseNameOf", 1, primBaseNameOf); addPrimOp("dirOf", 1, primDirOf); addPrimOp("toString", 1, primToString); + addPrimOp("__toXML", 1, primToXML); addPrimOp("isNull", 1, primIsNull); addPrimOp("dependencyClosure", 1, primDependencyClosure); addPrimOp("abort", 1, primAbort); -- cgit 1.4.1