stfc / fparser

This project maintains and develops a Fortran parser called fparser2 written purely in Python which supports Fortran 2003 and some Fortran 2008. A legacy parser fparser1 is also available but is not supported. The parsers were originally part of the f2py project by Pearu Peterson.
https://fparser.readthedocs.io
Other
63 stars 29 forks source link

Pre-processor directives created by fparser do not compile #441

Open hiker opened 8 months ago

hiker commented 8 months ago

fparser has limited support for preprocessor directives. Example:

MODULE lfric_abort_mod
  IMPLICIT NONE
  CONTAINS
  SUBROUTINE parallel_abort(ierr)
    #ifdef NO_MPI
    #else
    USE mpi, ONLY: mpi_abort, MPI_COMM_WORLD
    #endif

But the indentation causes gfortran to abort:

gfortran -C -g -O0 -c lfric_abort_mod.F90
lfric_abort_mod.F90:5:6:

    5 |     #ifdef NO_MPI
      |      1
Error: Invalid character in name at (1)

And intel issues a warning:

 ifort -C -g -O0 -c lfric_abort_mod.F90
lfric_abort_mod.F90(5): warning #5117: Bad # preprocessor line
    #ifdef NO_MPI
-----^

Using the pre-processor explicitly (cpp -P) works.

As a discussion: It might be useful to avoid indentation for preprocessor directives. I don't strongly needed it, I can add a pre-processing step instead, but I think it could be useful for some applications? But I am equally happy to close this ticket since our preprocessor support is documented to be very limited.