Compile time XML Parser?
Adam D. Ruppe
destructionator at gmail.com
Wed Feb 5 01:51:07 UTC 2020
On Wednesday, 5 February 2020 at 01:43:24 UTC, Kaitlyn Emmons
wrote:
> Is there one in existence?
Most ordinary xml D parser can run at compile time.
I've tested my dom.d with it and it parses successfully, though
several actual manipulations cause the compiler to crash [!].
import arsd.dom;
string translate(string xml) {
auto document = new Document(xml, true, true);
foreach(p; document.querySelectorAll("p"))
p.removeAllChildren(); // this worked at least
//p.innerText = "compile time"; // crashed!
//p.addClass("paragraph"); // crashed!
return document.toString();
}
// with the `enum` keyword, it runs the function at compile-time
enum e = translate("<xml><p>cool</p></xml>");
void main() {
pragma(msg, e); // and this prints the result as it
compiles
}
More information about the Digitalmars-d
mailing list