aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-08-24 14:34:29 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-08-24 14:34:29 +0000
commit215ec2ddc6088be2291722a544c6ab5a1b00a5a1 (patch)
tree55f65759701dba8513986bcf23e33086b472e2f5
parentf793caf93674350f8c1e6fa740ab6cce649d0db8 (diff)
* 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.
-rw-r--r--src/libexpr/primops.cc10
-rw-r--r--tests/lang/eval-okay-to-xml.exp1
-rw-r--r--tests/lang/eval-okay-to-xml.nix1
3 files changed, 12 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 3d8d9b8ad..d82cc5870 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);
diff --git a/tests/lang/eval-okay-to-xml.exp b/tests/lang/eval-okay-to-xml.exp
new file mode 100644
index 000000000..ee7d4c7d3
--- /dev/null
+++ b/tests/lang/eval-okay-to-xml.exp
@@ -0,0 +1 @@
+Str("<?xml version='1.0' encoding='utf-8'?>\n<expr>\n <list>\n <string value=\"ab\" />\n <int value=\"10\" />\n <attrs>\n <attr name=\"x\">\n <string value=\"x\" />\n </attr>\n <attr name=\"y\">\n <string value=\"x\" />\n </attr>\n </attrs>\n </list>\n</expr>\n")
diff --git a/tests/lang/eval-okay-to-xml.nix b/tests/lang/eval-okay-to-xml.nix
new file mode 100644
index 000000000..ff1791b30
--- /dev/null
+++ b/tests/lang/eval-okay-to-xml.nix
@@ -0,0 +1 @@
+builtins.toXML [("a" + "b") 10 (rec {x = "x"; y = x;})]