I'm writing a transpiler for Tiny C code to Python code, but I need to build a preprocessor solution to replace #define
and manage compilator C directive (#ifdef, #else, #define...)
I choose to use a pcpp module in Python but with no success... is a solution possible in a full Tatsu solution?
The parts of TatSu supporting pre-processing are, unfortunately, undocumented.
You can take a look at how
Buffer.include()
is implemented, replacing the original lines and line information by those of the block produced by the transformation.Basically, you can hook into the preprocessing methods with your own
Buffer
class, and transform the text in whichever way. A proper list ofLineIndexInfo
will let the parser report errors agains original source lines.For a preprocessor with macros, you'll probably need a parser for the preprocessor, and a parser for the main language. The trick will be making the first parser preserve the line information for the second one.
The preprocessor may run separately, but it must inject metadata enough to allow the main parser to recover the original line information.