I just published the first release of fpx, an extended Fortran preprocessor.
This project aims at providing a simple, embeddable, open-source preprocessor written in modern Fortran. fpx is mostly compliant with a C preprocessor, fine-tuned for the specificity of the Fortran language. fpx is an embeddable preprocessor. It can be used as a command-line tool or directly embedded into any solution.
fpx supports:
-
conditional compilation with
#if,#ifdef,#ifndef,#elif,#else,#endif -
simple macros and functions like macros with
#define,#undef,defined,and!defined -
simple arithmetic and bitwise operations with
+,-,*,**,/,>,<,>=,=<,||,&&,|,^,&,!and~. -
include files with
#include -
variadic macros with
__VA_ARGS__, and__VA_OPT__, -
build-in macros as
__LINE__,__FILE__,__FILENAME__,__TIME__,__DATE__,__TIMESTAMP__ -
stringification
#and concatenation## -
and more…
Command line
The preprocessor fpx can be used from the command line using your favorite shell. The following options are available:
| Option | Definition |
|---|---|
| -D | Define a with no value. |
| -D= | Define a with as its value. |
| -U | Undefine ’ |
| -I | Add to the end of the global include paths. |
| -h, -? | Display this help. |
| -o | Output file path with name and extension. |
| -v | Display the version of the program. |
Using the file preprocessor could not be easier. The function simply takes as arguments the input and output file paths.
Embedded
program test
use fpx_parser
call preprocess('tests/input.f90', 'tests/output.f90')
end program
*For more examples, please refer to the Documentation.
At the moment, the fpx passes all the tests from LFortran and tests of flang targeting modern Fortran. Some of the flang tests might differ since they are quite opiniated, especialy concerning the rules for line continuation in and after macro substitution.