
GPP – general-purpose preprocessor - nerdponx
https://logological.org/gpp
======
lf-non
From my past C experience I had developed a distaste for clever pre-processors
tricks that a lot of people love showing around.

However while easing myself into typed languages after multiple years of using
ruby and erlang exclusively, I have found myself needing a pre-processor to
eliminate the boilerplate often required to satisfy type systems. In addition
I wanted to create a project to generate type definitions (and associated
tests) for multiple languages (esp. Typescript, bucklescript and Nim) having
js targets for library authors.

The approach I settled in was a very simple template driven pre-processor that
would inject the generated code right into the source files between annotated
comment directives. I expect this, along with an explicit focus on non-
composability, to discourage people from using templates where normal language
features would do just as well.

This project (written in typescript) is available at
[https://github.com/lorefnon/InGenR](https://github.com/lorefnon/InGenR) and
any feedback and contributions are welcome.

------
B1FF_PSUVM
> _its syntax is lighter and more flexible than that of GNU m4._

The old Unix utils were pretty good, so that made me think why anyone would go
to the trouble of redoing m4.

There's more at
[https://files.nothingisreal.com/software/gpp/gpp.html](https://files.nothingisreal.com/software/gpp/gpp.html)
(man page with examples), namely:

 _" GPP is targeted at all common preprocessing tasks where cpp is not
suitable and where no very sophisticated features are needed. In order to be
able to process equally efficiently text files or source code in a variety of
languages, the syntax used by GPP is fully customizable. The handling of
comments and strings is especially advanced."_

The man page also details options such as "-C cpp compatibility mode. [...] -T
TeX-like mode. [...] -H HTML-like mode. [...]"

~~~
nerdponx
I actually used GPP to write my thesis in Markdown. I had a "main" document
containing a bunch of GPP "include" lines. Then I fed that into Pandoc all in
one shot. I wouldn't have dreamed of doing the same in M4.

------
Const-me
I usually use T4 for such tasks.
[https://en.wikipedia.org/wiki/Text_Template_Transformation_T...](https://en.wikipedia.org/wiki/Text_Template_Transformation_Toolkit)

Unlike macros, T4 includes a fully-featured programming language (C#), with
all the goodies like collections, cryptography, globalization, etc..

~~~
skrebbel
Yeah, T4 is awesome.

And for those readers here who don't like C# for good or bad reasons, you can
pretty much do the same with other languages.

Eg Ruby has ERB, usualy used for html templating but you can use it for
anything. Make a command line tool that loads a a something.ext.erb file, runs
it, and writes a something.ext file and you just made yourself a super
powerful preprocessor that you already know how to use.

Many languages have this (eg EJS in JavaScript, PHP itself in PHP (use output
buffering), EEx in Elixir, etc). I'd use this over a "learn yet another
language" preprocessor language anytime.

~~~
nerdponx
Liquid and Jinja2 (both descendants of Django templating language) are also
both used outside the web context now. For example, Conda package specs
(called "recipes") are written in YAML, but are processed with Jinja2 first.

~~~
skrebbel
You still need to learn a new language though (the jinja2 language)

------
msoloviev
I wrote a similar tool a while back which provides a more natural way to
implement full-fledged programming language constructions such as loops (the
example in the documentation here, which involves redefining a macro and
explicit evaluation, feels a bit convoluted in comparison...), but is
specifically tailored towards supporting C/C++:
[https://github.com/blackhole89/macros](https://github.com/blackhole89/macros)

I suppose the only strictly language-specific feature is the support for C
string literals and it could otherwise also be made to run on top of different
tokenisers.

m4 is surely more powerful still, but its syntax always struck me as somewhat
jarring both on its own and in the context of any other language.

------
adiM
I use GPP as a wrapper to add features to markdown:

[https://adityam.github.io/context-blog/post/markdown-with-
gp...](https://adityam.github.io/context-blog/post/markdown-with-gpp/)

------
bmn__
Another one, geared toward taking repetition and verbosity out of programming:

[https://github.com/hzhou/MyDef](https://github.com/hzhou/MyDef)

[https://htmlpreview.github.io/?https://github.com/hzhou/MyDe...](https://htmlpreview.github.io/?https://github.com/hzhou/MyDef/blob/master/manual/mydef.html#intro_mydef)

------
comesee
I know this library, my old 18.02 professor wrote it originally.

