I wish I had known about cog some 14 years ago when I implemented exactly the same thing (<a href="https://github.com/ot/inpytex" rel="nofollow">https://github.com/ot/inpytex</a>).<p>It was made for LaTeX files but could have worked with anything. It even uses the same checksum protection!<p>I wonder how many people independently came up with the same idea.
I think the closest "standard" tool for this is m4, which doesn't seem powerful enough for most applications.<p>Lips seems similar, but for Lisp/Scheme (e.g. <a href="https://github.com/zc1036/lips" rel="nofollow">https://github.com/zc1036/lips</a> <a href="https://github.com/rbryan/guile-lips" rel="nofollow">https://github.com/rbryan/guile-lips</a> )
My immediate thoughts:<p>• PHP, the poster example for template-based languages, seems to have spent all its recent years in development trying to get <i>away</i> from its HTML templating roots. I basically never see a PHP file in the wild which is using the old style with mostly HTML with sprinkles of PHP; it’s almost <i>all</i> pure PHP.<p>• Python has a perfectly good templating system in Jinja2, used by Flask and many others. Last I looked, even <i>Django</i> seemed to imply that they’d themselves would rather be using Jinja2 than Django’s own templating language. IIRC, Django even natively supports replacing its templating engine with Jinja2.<p>• For small-ish templates embedded inline in code, Python now has f-strings.<p>Therefore, I wonder: In what situation, exactly, would Cog, a PHP-style inline code templating system, be better than Jinja2 and/or f-strings? And would this benefit be worth the added cost of having yet another model of abstractions which few people would be familiar with?
Looking at this reminds me strongly of texthon, but with a less attractive syntax. A quick skim through the source appears to show a similar use of eval.<p>Too bad texthon is essentially unknown and unmaintained, as far as I know. I worked on a project with it for several years and it always worked really well and was much more pleasant to use than something like jinja. Maybe I need to make a modern fork…<p>Anyway, anyone interested in cog should check it out as well.
I both like and dislike the "immediate inline" nature. I guess it depends on what you're using it for. It's great when the output is small, but I just imagine folks using it to generate enourmous classes or such inline, forcing programers to scroll through all of that, as well as giving false signals when searching code.<p>Like any tool, you need to use it well or it will be a foot gun.