phrep

Artifact Content
Login

Artifact 761bb8fe7d0ca4c12480b805f29febe050cbe507:

Wiki page [phrep] by mario 2015-04-28 22:18:02.
D 2015-04-28T22:18:02.152
L phrep
N text/x-markdown
P 8b84dda9a4dabdb56346a746cbc78a9a2b7950e9
U mario
W 2969
<h1>PHP Macro Preprocessor</h1>

<kbd>phrep</kbd> is a command-line **macro preprocessor** for PHP code.
<img src=logo width=133 height=144 align=right style=margin:25pt data-origin="https://openclipart.org/detail/214574/lego-by-eggib-214574">

  * It handles C-style [processing directives](wiki/directives) like `#define`,
    `#include`, `#if`, `#ifdef`, `#elif`, `#else`, `#endif`, `#undef`,
    `#pragma`, `#stderr`, `#srcout`.
  * Applies constants and standard [macro substitutions](wiki/macro) only
    within code sections.
  * Also allows more [complex](wiki/complex) MACRO@() transformations per PHP
    inline callbacks.
  * Is somewhat compatible with [cpp / preprocess / phpp](wiki/alternatives),
    can read C header `.h` files.
  * Otherwise leaves comments and code structure intact.

It's intended as static configuration tool[...](wiki/use+cases)

  * Can be used within trivial [makefiles](wiki/makefiles), or slim packaging scripts.
  * Useful for simple code templating or one-off generation tasks.
  * And reduces runtime softcoding, as it allows code-embedded feature branches.

### Usage

Preprocessing a source script is as simple as:

     phrep -i config.src -o config.php -D PKG_USE_SQLITE=1

Where [source](wiki/file+extensions) files might look like this:

     <?php
     #if __PHP_VERSION__ >= 5.4 && defined(PKG_USE_SQLITE)
      #pragma(dirs=./includes)
      #include <sqlite.ph>
     #else
         include("./lib/basic_db.php");
      #ifdef PKG_DB_EXTENSION
         $db->option = PKG_DB_EXTENSION;
      #endif
     #endif

Most preprocessor constants are just meant for conditional sectioning. But
they can also be substituted in PHP code blocks. Just like macros such as
`HTML($var)` or even `PARAMETERIZE@(select $x FROM $y)`.

### Status

  * Experimental / development
  * Command line <kbd>-flags</kbd> don't completely map all
    [#pragma directives](wiki/pragma) yet.
  * [#if expressions](wiki/expressions) are mostly usable already.
  * No [composer-plugin](wiki/composer-plugin) yet defined.
  * A [man page](wiki/manpage) exists.

### Download

  * Use the [zip](zip/phrep.zip?uuid=trunk) or [tar](tarball/phrep.tgz?uuid=trunk)
    for literal sources.
  * Get the combined [*phrep* script](doc/trunk/phrep).
  * Or install <kbd>phrep</kbd> per
    <a class=download href="http://apt.include-once.org/phrep-0.2.0.deb">phrep-0.2.0.deb</a> /
    <a class=download href="http://apt.include-once.org/phrep-0.2.0.rpm">phrep-0.2.0.rpm</a>
    directly.
  * Updates are announced via
    [http://freshcode.club/projects/macro.php](http://freshcode.club/projects/macro.php)


<style>
.download {
  background: linear-gradient(180deg, #66DD55, #448822);
  border: 1px solid #449933;
  color: #FFFFFF;
  text-shadow: 0px 1px 0px #888888;
  border-radius: 5px;
  font-weight: 500;
  font-size: 115%;
  margin: 2pt;
  padding: 2pt 5pt;
}
</style>

Z e983de708f2d238f58759f6555919a46