IIRC the earliest version of the C++ language, before a C++ compiler existed, was implemented with C and the M4 preprocessor. https://en.wikipedia.org/wiki/M4_(computer_language) https://www.gnu.org/software/m4/
Yep, it was called cfront. https://en.wikipedia.org/wiki/Cfront
Using the C preprocessor as an HTML templating engine
21–30 of 34 posts
Re: Using the C preprocessor as an HTML templating engine
#22Re: Using the C preprocessor as an HTML templating engine
#23Re: Using the C preprocessor as an HTML templating engine
#24Seems like a bad idea, given that the CPP and HTML have a fair number of overlapping tokens (e.g. `#` for both URL fragments and macro beginnings). Why not use SSI[1]? It's inspired by the CPP's syntax, but is supported directly by most HTTP servers (and is more powerful, to boot). [1]: https://en.wikipedia.org/wiki/Server_Side_Includes
>Why not use SSI[1]? Because hacking is fun, and it's still fun if it's a bad idea
Re: Using the C preprocessor as an HTML templating engine
#25Re: Using the C preprocessor as an HTML templating engine
#26Seems like a bad idea, given that the CPP and HTML have a fair number of overlapping tokens (e.g. `#` for both URL fragments and macro beginnings). Why not use SSI[1]? It's inspired by the CPP's syntax, but is supported directly by most HTTP servers (and is more powerful, to boot). [1]: https://en.wikipedia.org/wiki/Server_Side_Includes
# is only processed by cpp when it's the first non-whitespace character in a line so that shouldn't be an issue in the real world. But, yeah, SSI.
Re: Using the C preprocessor as an HTML templating engine
#27Earlier quoted context omitted.
Thank you, I did not know this. I was about to comment and say: Why not go with m4(1)? I have used it for a personal homepage and while it certainly will try to stab you in the back like any old macro processor will, it is more full-fledged that its C counterpart and will also allow to to smugly state that your homepage is POSIX compliant [1]. There are a few guides out there from around 2000 to get you started, but…
one of the first things i did with html was to attempt to use m4 to simplify my personal home page. not only did that not work, it backfired to an incredible degree, but that's because i was using proprietary vendor m4. gnu m4 has a couple of features that make it significantly less error-prone: 1. built-in macro names that require arguments such as `define' are not "expanded" if you don't follow them with parenthese…
This one is pure pain. Thankfully, the only implementation I have encountered that does this is Heirloom's [1]. I doubt POSIX will do it, but I wish they would just define this behaviour out of existence for the built-ins as it is a minefield when trying to write prose (or comments, for that matter).
[1]: https://heirloom.sourceforge.net
As for outputs being interpreted iteratively, there is no way around it that I know of. To make invocation more explicit, I have just settled on prefixing macros with an underscore and it has worked well so far as it is uncommon in English text, HTML, and CSS.
Re: Using the C preprocessor as an HTML templating engine
#28[flagged]
Re: Using the C preprocessor as an HTML templating engine
#29Re: Using the C preprocessor as an HTML templating engine
#30I was considering doing something like this just the other day. It had a gnuplot script and it seemed to me that it would be so much more versatile if I could use #ifdefine and #include in it. I ended up using a Perl preprocessor, but it seems like cpp would work ok-ish for certain use cases that don’t require, say, strict tabs like Python among a few other things mentioned on the cpp manual.
Check out https://github.com/logological/gpp it's what I use when I feel like I need a preprocessor. It's more flexible in syntax and operation than cpp. I've used it in the past for wrangling the definitions of a multitude of SQL triggers I was using to generate a real-time materialized view. The fact that you can modify its syntax is very helpful for making it work with non-C syntaxes (like SQL or even LaTeX). It e…