phrep

Artifact [a82680f586]
Login

Artifact a82680f5863b242bbcc4f34e51235ee722ff5678:

Wiki page [alternatives] by mario 2015-03-06 17:42:12.
D 2015-03-06T17:42:12.566
L alternatives
N text/x-markdown
P 9a6c8afb2f4b8e7460136680b4646b0d6a5f2dcb
U mario
W 4693
There are other preprocessor implementions for / or usable with PHP.


### phpp

[PHPP](https://github.com/tobiasmathes/nanoserv/blob/develop/build/phpp.php)
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 <kbd>-m phpp</kbd>.

Quite apt for joining PHP apps.


### CCPP

[CCPP](https://github.com/metala/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](https://code.google.com/p/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 <kbd>-k</kbd>
    are mirrored in <kbd>phrep</kbd>.

It's available in most distros per default.


### other PHP-specific processors

* [cedricwalter/joomla-packager](https://github.com/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](https://github.com/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](https://github.com/ircmaxell/PreProcessor/tree/master/lib/preprocessor)
  works on a PHP token stream to substitute real include/require() statements,
  conditional symbol branching.

* [andreiz/prep](https://github.com/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](https://github.com/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](https://github.com/noptic/rough) uses an `#@…@#` inline
  substitution syntax and comes with a few predefined code generators.

* [monperrus/pp4php](http://www.monperrus.net/martin/pp4php)
  is a rather basic string replacing processor, with a few comment-inlined constant
  replacements, and symbol branching.

<div class=note>
  Don't refrain from adding a comment if you know of another implementation.
</div>

### GPP (General-Purpose Preprocessor)

[GPP](http://en.nothingisreal.com/wiki/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](https://gcc.gnu.org/onlinedocs/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).


Z afd100c294145bb1839e3de3e86fcfed