[IMP]Hy base : use gensym for safer xml-write macro

This commit is contained in:
Fabien BOURGEOIS 2019-09-16 18:21:29 +02:00
parent 19b9fa6c69
commit 9a7027622f

View File

@ -50,11 +50,11 @@
(defmacro field-inherit [xmlid] `(field {"name" "inherit_id" "ref" ~xmlid} []))
(defmacro field-arch [&rest args] `(field {"name" "arch" "type" "xml"} ~@args))
(defmacro xml-write [filename tree]
(defmacro/g! xml-write [filename tree]
"Write XML file according to filename and given tree"
`(do
(import [os [path]])
(setv output-xml (.tostring ET tree)
output-path (.dirname path (.abspath path __file__))
fpath f"{output-path}/{filename}")
(with [f (open fpath "w")] (.write f output-xml))))
(import [os [path]])
(setv ~g!output-xml (.tostring ET tree)
~g!output-path (.dirname path (.abspath path __file__))
~g!fpath (+ ~g!output-path "/" ~g!filename))
(with [f (open ~g!fpath "w")] (.write f ~g!output-xml))))