Macro Processing - Programming On Unix
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
This can be useful to know where a library is loaded from, like in the previous example.
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:
Here are some fun links to read:
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.
(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.
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 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"  (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! 
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...