Skip to content

Comment on Ask HN: Suggestions for Building a Code Generation

Comments

You would think there would be parsing frameworks that would work like

   Language -> AST -> Language
like maybe you could compile Java to an AST, modify the AST, then write the Java out. I have a list of "things that current parser generators don't do that are keeping us from writing interesting applications" and that's one of them. (There is also a space for tools that work with concrete syntax trees, particularly there were some high end CASE tools in the 1990s that were meant to let you edit a program by editing something like a UML document and make a patch like a professional programmer would make that would leave comments, spacing and all of that intact.)

The universal excuse that is brought out is that a bidirectional parser would be slow compared to a conventional parser. I wrote a simple site generator that made this page

https://ontology2.com/essays/LookingForMetadataInAllTheWrong...

that did templating at the DOM level, that is the template of the page as a whole is an HTML document which is parsed, manipulated with the DOM, then written out again in HTML. It works just fine, but it is 100-1000x slower than a conventional templating engine so it is a non-starter for a lot of people.

My own opinion is the property of LISP being homoiconic would be less special if other languages had tools that made it easy to parse bidirectionally and process ASTs, but it hasn't really been done.

If you are interested in going down this road click on my profile link and send me an email!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.