phrep

directives
Login

Phrep handles C-style preprocessing #directives.

Conditional #if...#endif sections can mask both literal output and other directives. And they can be nested.

All directives are processed in the first file transformation phase, where output (literal and from #include files) simply gets merged. Constant substitution however happens in the second phase - on the assembled code.

#define const value

Declares a token, constant, standard macro or complex macro.

#undef const

Removes a defined constant or macro name.

#ifdef const

Probes for existing flags or constants

#ifndef const

Tests if a flag/constant/macro is not defined yet.

#if expr

An #if directive obviously can also start a conditional section, or a nested condition.

See expressions on further allowed constructs, such as =~ regex comparisons, or * + - arithmetics, or == and && or || operations.

#elif expr

A conditional else leave can be expressed with #elif.

There can be multiple #elifs between the initial #if and the closing #else/#endif.

#else

If all previous conditional sections failed, then the source/directives between #else and #endif will be processed.

An else is entirely optional, so a conditional section #if..#endif can be completely inactive.

#endif

Ends a conditional section. Note that #if/#endif constructs can be nested. Which is why space-indenting ␣#if directives is useful.

#include file

Files and dependencies can be interpolated using an #include directive. It accepts the filename as literal string, or enclosed in <...> or "..." or '...' quotes.

Some care is taken to step around commented-out PHP include() statements.

Files are always searched among the defined include path, as set per -I or #pragma(dirs=...) directive.

#pragma (opt=val)

The #pragma directive sets a few global and/or local processing flags.

See pragma options for a list of available options.

#stderr msg

Outputs a warning or error message. This should obviously be used within conditional sections etc. (Paired with pragma fail even).

Why? Unike in CPP this isn't called #error or #warning, because both seem entirely too likely to preexist as PHP code comments.

#srcout code

Writes literal code to the final output.

This is a phrep-specific extension. Mozilla and CCPP agree on #literal for this purpose. However #srcout seems even less likely to accidentially reside in existing PHP comments.

Aliases

#macro

Is just an alias for #define.

#macro X(y) (y+CONST_X)

Again see: macro.

Ignored directives

Phrep ignores following directive extensions or variations:

Extending the MacroProccessor is trivial however. Each new directive just needs an entry in RX_DIRECTIVES, a switch case in block(), and a handler method like d_import().