* 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.
This commit is contained in:
		
							parent
							
								
									f793caf936
								
							
						
					
					
						commit
						215ec2ddc6
					
				
					 3 changed files with 12 additions and 0 deletions
				
			
		|  | @ -5,6 +5,7 @@ | ||||||
| #include "eval.hh" | #include "eval.hh" | ||||||
| #include "globals.hh" | #include "globals.hh" | ||||||
| #include "nixexpr-ast.hh" | #include "nixexpr-ast.hh" | ||||||
|  | #include "expr-to-xml.hh" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| static Expr primBuiltins(EvalState & state, const ATermVector & args) | 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. */ | /* Boolean constructors. */ | ||||||
| static Expr primTrue(EvalState & state, const ATermVector & args) | static Expr primTrue(EvalState & state, const ATermVector & args) | ||||||
| { | { | ||||||
|  | @ -705,6 +714,7 @@ void EvalState::addPrimOps() | ||||||
|     addPrimOp("baseNameOf", 1, primBaseNameOf); |     addPrimOp("baseNameOf", 1, primBaseNameOf); | ||||||
|     addPrimOp("dirOf", 1, primDirOf); |     addPrimOp("dirOf", 1, primDirOf); | ||||||
|     addPrimOp("toString", 1, primToString); |     addPrimOp("toString", 1, primToString); | ||||||
|  |     addPrimOp("__toXML", 1, primToXML); | ||||||
|     addPrimOp("isNull", 1, primIsNull); |     addPrimOp("isNull", 1, primIsNull); | ||||||
|     addPrimOp("dependencyClosure", 1, primDependencyClosure); |     addPrimOp("dependencyClosure", 1, primDependencyClosure); | ||||||
|     addPrimOp("abort", 1, primAbort); |     addPrimOp("abort", 1, primAbort); | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								tests/lang/eval-okay-to-xml.exp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/lang/eval-okay-to-xml.exp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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") | ||||||
							
								
								
									
										1
									
								
								tests/lang/eval-okay-to-xml.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/lang/eval-okay-to-xml.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | ||||||
|  | builtins.toXML [("a" + "b") 10 (rec {x = "x"; y = x;})] | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue