There are other preprocessor implementions for / or usable with PHP.
phpp
PHPP is meant for PHP scripts of course.
- Provides basic #ifdef symbol branching, no
#if
expressions. - Runs atop a task-specific tokenizer, can strip out comments optionally, and syntax lint the resulting files.
- Uses
{{{CONSTANT}}}
markers - which are supported in phrep via -m phpp.
Quite apt for joining PHP apps.
CCPP
CCPP is an earlier C-preprocessor implementation for PHP.
- Uses the PHP tokenizer for all rewriting (thus #directives only within
<?php
blocks). Internally transforms preprocessed files into php includes before execution. - Allows inlined
<?php
tags via#includephp
. - Strips comments however, and substitutes C/C++ trigraphs.
- Single-level macro substitutions.
- Uses PHP evaluation for complex
#if
s and macro replacements. - Has a
#literal
directive (like#srcout
in Phrep).
It's just a library though, not being updated since.
Preprocess.py
preprocess is a very generic file preprocessor implemented in Python.
- Handles PHP scripts, as well as Ruby, Tcl, Shell, C/C++, HTML, JavaScript.
- Provides built-in
// #directive
double prefixes. - Uses Python expressions for
#if
directives etc. - Doesn't do code substitutions per default, or only for literal text matches (no syntax checking for any language).
- Phrep is compatible with its doubly-escaped
# #directives
, but ignores/*…*/
multi-line embedded directives. And some cmdline flags -k are mirrored in phrep.
It's available in most distros per default.
other PHP-specific processors
cedricwalter/joomla-packager also provides a
#directive
-based build system. It's tied to building Joomla extensions, but has a reusable preprocessor implementation, with basic #define/#ifdef and conditional branching support.tmuguet/PreProcessorFilter is a ready-to-use hook for Phing, which provides in-XML-task-defined constants. Only symbol branching, but an interesting
#call macro()
syntax variation (and substitution corpuses in custom text files).ircmaxell/PreProcessor works on a PHP token stream to substitute real include/require() statements, conditional symbol branching.
andreiz/prep is a PHP extension that implements preprocessing hooks directly in the interpreter. Untested. And it's not exactly normal preprocessor directives, but scripted filters, registered per php.ini, and meant for arbitrary code transformations (sortof like the complex macros in phrep).
crodas/Artifex implements a custom macro scheme using
#*
prefixes, a PHP and JSONish substitution syntax, and__
identifier markers. So, not quite a traditional preprocessor, but still useful for code templating.noptic/rough uses an
#@…@#
inline substitution syntax and comes with a few predefined code generators.monperrus/pp4php is a rather basic string replacing processor, with a few comment-inlined constant replacements, and symbol branching.
GPP (General-Purpose Preprocessor)
GPP is similar to the C preprocessor, but provides a few abstractions and flexibility over CPP and M4.
- Allows customizable directive syntax, builtins for HTML, XML, TeX, C.
- Implements recursive directive and macro declarations (per meta macros).
- Can be made syntax-aware of comments and strings.
It's not an active project anymore, but still functional, readily available in all distros.
CPP (GNU or Clang)
Theoretically one could use plain cpp for preprocessing other source files. It's quite the command-line though:
gcc -E -P -w -ansi -traditional-cpp -no-integrated-cpp -nostdinc -iconfig.h file.php
CPP however is too strongly tied to C/C++ and will trip over literal #
comments,
and often butcher up the rest (stripping comments is useless outside of C compiling
tasks).