Hey good looking people,

My question is about the general problem of writing a tool (a source-to-source compiler) whose output is C++ and whose input is not. Think protocol buffers.

In my particular case, I'm translating a protobuf into a "legacy" C++-based class, with methods corresponding to the service's and with particular "legacy" vocabulary types (i.e. no STL).

In the past I've defined my own subset of the C++ AST in python/racket types, parsed the input language, translated it to compositions of the output structs ad hoc, and then defined renderers for the structs and run the output through clang-format.

I'd prefer a more off-the-shelf approach. I've looked into clang's AST class hierarchy (and libtooling, to boot), but as far as I can see, that's for C++ -> C++ transformation only (need compilation database to start).

Other tools seem to do what I described (i.e. case-by-case approximation of constructing a C++ AST for generation).

Does anybody know of a light way to generate C++ from arbitrary input? String templating is popular, but I want something, let's say, semantically stronger.