There are tons of template systems. This is just a basic preprocessor.
Pepe is usable both as a command line app and as a Python module. Pepe syntax is hidden within comments (whatever the syntax for comments in the target file type), so that the file can still have valid syntax. Pepe syntax mimics that of the C preprocessor, but its behavior differs.
Pepe is targeted at build systems that deal with many types of files. Languages for which it works include:
- C++
- Python,
- Perl
- Tcl
- XML
- JavaScript
- CSS
- IDL
- TeX
- Fortran
- PHP
- Java
- Shell scripts (Bash, CSH, etc.)
- C#
Pepe began as a fork of Trent Mick's preprocess which has been used for build-time code differentiation in the Komodo build system, which includes source code in Python, JavaScript, XML, CSS, Perl, and C/C++.
All preprocessor statements are on their own line. A preprocessor statement is a comment (as appropriate for the language of the file being preprocessed). This way the preprocessor statements do not make an unpreprocessed file syntactically incorrect.
For example:
pepe -D FEATURES=macros,scc code.py
will yield this transformation:
... ... # #if "macros" in FEATURES def do_work_with_macros(): def do_work_with_macros(): pass pass # #else def do_work_without_macros(): pass # #endif ... ...
or, with a JavaScript file:
... ... // #if "macros" in FEATURES function do_work_with_macros() { function do_work_with_macros() { } } // #else function do_work_without_macros() { } // #endif ... ...
The #if
expression ("macros" in FEATURES
in the example) is Python
code, so it has Python's full comparison richness. A number of
preprocessor statements are implemented:
#define VAR [VALUE] #undef VAR #ifdef VAR #ifndef VAR #if EXPRESSION #elif EXPRESSION #else #endif #error ERROR_STRING #include "FILE"
As well, pepe will do inline substitution of defined variables. Although, this is currently turned off by default because substitution occurs in program strings, which is not ideal. When a future version of pepe can lex languages being preprocessed it will NOT substitute into program strings and substitution will be turned ON by default.
Installing Pepe is easy:
$ pip install pepe
Using as a shell command:
$ pepe --help
Pepe can also be used as a module. Please see the documentation for more information.