Skip to main content

Portable multi-language file preprocessor

Project description

pepe—a portable multi-language file preprocessor
================================================

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.

Who is it for?
--------------
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#

History
-------
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++.

How it works
------------
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.

Install Notes
-------------
Installing Pepe is easy::

$ pip install pepe

Getting Started
---------------

Using as a shell command::

$ pepe --help

Pepe can also be used as a module. Please see the documentation_
for more information.

.. _preprocess: http://code.google.com/p/preprocess/
.. _Komodo: http://www.activestate.com/Komodo
.. _documentation: http://packages.python.org/pepe/

Project details


Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page