Literal XML in Erlang with parse_transform/2
Massimiliano Mirra - bard - June 26, 2007One of the things I dislike about Erlang is that it severely impairs bragging opportunities. Yesterday I wrote a module that allows writing literal XML in the source and have it parsed into Erlang structures at compile time—sort of like E4X minus the manipulation goodies at runtime (at least for now).
You write:
Doc = '<greeting>Hello!</greeting>',
io:format("~p~n", [Doc]).
And it prints…
<!—break—>
{xmlElement,greeting,
greeting,
[],
{xmlNamespace,[],[]},
[],
1,
[],
[{xmlText,[{greeting,1}],1,[],"Hello!",text}],
[],
"/tmp",
undeclared}
In most languages I’m familiar with, this would have granted the author instant Yacc-demigod status. With Erlang… it was less than 40 LOC. Hardly something you’d wear at a party.
Anyway, this code owes everything to Philip’s writings. It also uses parse_transform/2, and “programmers are strongly advised not to engage in parse transformations and no support is offered for problems encounteredâ€�. So unless you, like me, are still at the kid-in-a-candy-shop stage of Erlang experience, think twice before using this in production, ok?
The code is here.
Categories: Blogs Massimiliano Mirra
Erlang on Twitter
» Erlang_07 (Erlang ): @dwiafrianii d ngertiin dong
» nsolop (El Socio): Erlang, ¿entienden eso?, Erlang!
» Erlang_07 (Erlang ): @rhy_cherry acikk
» casio_juarez (Casio Juarez III): RT @coreyhaines: In Chicago on Monday? Want to see me give a book report on neural networks and erlang? http://t.co/ZvJUfuTfpH
» NotDoctorOk (Not Richard O'Keefe): Yes, the debt to the Smalltalk 4-pane browser and its “method categories” *is* pretty obvious, isn’t it? http://t.co/KKKgf7qK7W
» PetrMyazin (Petr Myazin): Funniest programming language promotion video I’ve ever seen http://t.co/Sh2DwB5G86 #erlang #otp
» jimmyhwang (James Hwang): Erlang is more interesting than I thought. Many concepts in Golang influenced from Erlang. Also, first time playing with “real” FP
» SNTalentHiring (SNTALENT Empleo): Lead Server Core Developer (Java/Erlang) http://t.co/IFaqmh3y9O #empleo #Barcelona #Internet #tecnologÃa #TIC
» TrainByTweet_VO (TrainByTweet_VO): VOIP: Blocking probability can be calculated from erlang-B formula
» agisanast (Agis Anastasopoulos): ok, it’s actually an IRC bot I’ve been writing in #erlang.. https://t.co/Yo5Dbc18PV
Statistics
Number of aggregated posts: 10648
Most recent article: May 14, 2013
Latest comments
» Moraru on This is Why You Spent All that Time Learning to Program: It is true that computer science was a pain in the back at time that i’ve had to learn it…
» Commercial hand dryers on Couchbase Meetup at new HQ: Buy online from here where you will get so much of variety in Commercial hand dryers for people. If you…
» Fort McMurray Homes on Motivated Reasoning and Erlang vs Python vs Node: I don’t really understand why this post is motivational? I don’t even see a post, just a title. Fort McMurray…