Macro Processing - Programming On Unix
Users browsing this thread: 3 Guest(s)
|
|||
Hello fellow nixers,
Let's discuss macro processing and weird places where you can use and abuse them. You certainly know about the C one. You can stop the gcc compiler after macro processing by using the -E flag Code: echo "#include <stdbool.h>" | gcc -E - | grep stdbool m4 is the popular macro processing tool on Unix systems. It can be used for almost anything that requires transformation. There are a lot of other sort of macro or text generator on Unix, as mostly everything is text. To just name a few: * groff/troff * yacc/bison * lex * sed/awk? Here are some fun links to read: https://en.wikipedia.org/wiki/General-pu..._processor http://iotek.github.io/m4/ http://www.tldp.org/LDP/LG/issue22/using...4%3C/EM%3E Let's just start an abstract discussion about those and see where it goes. |
|||
|
|||
Transformation of text is surprisingly easy on Unix and wannabe-Unix thanks to the concept of pipes. tr, sed and awk are still incredibly useful once you understood how they act.
The "GCC one" is not a "C one" though. It took me a while to notice that you're not talking about preprocessors. Apropos: C happens to have built-in (sort of) macro processing as of C11 via _Generic. That's actually kind of sweet. For all other usages like that I found myself to (ab)use Perl which pretty much does anything sed/awk/... does. By the way: lexers and macro processors are not necessarily the same thing. -- <mort> choosing a terrible license just to be spiteful towards others is possibly the most tux0r thing I've ever seen |
|||
|
|||
(06-06-2017, 12:43 PM)jkl Wrote: The "GCC one" is not a "C one" though.Nice catch, yes different compilers might have different way of doing those preprocessing. (06-06-2017, 12:43 PM)jkl Wrote: C happens to have built-in (sort of) macro processing as of C11 via _Generic.That's cool, I had no idea this existed. http://www.robertgamble.net/2012/01/c11-...tions.html It's still pretty new, none of my libs in `/usr/include` uses them, which is not surprising. (06-06-2017, 12:43 PM)jkl Wrote: By the way: lexers and macro processors are not necessarily the same thing.Definitely. Maybe I shouldn't have brought them in the same discussion. It would've been more appropriate to bring autoconf and makefiles. |
|||
|
|||
I've been using ronn[1] to write manual pages, since markdown is a lot nicer than raw (g)roff macros. Unfortunately, it has some bugs of its own.
So I wrote my own "preprocessor" [2] (really just a series of regexps) to transform pseudo-Markdown into ronn-style-Markdown, which is then processed into HTML (and from there finally man-compatible roff macros). It works quite nicely! [3] In terms of real preprocessing, I use m4 pretty often. I was thinking of writing some kind of m4-based utility for combining different configuration fragments for each of my systems, so that I could have one i3 config.master and a bunch of config.<host> files that would get magically stitched together upon fetch. That's just an idea for the time being, though... [1]: https://github.com/rtomayko/ronn [2]: https://github.com/woodruffw/dotfiles/bl...pts/ronnpp [3]: https://yossarian.net/docs/kbsecret-man/kbsecret.1 |
|||