fparser
fparser copied to clipboard
Can't parse preprocessed files
Because fparser doesn't do any preprocessing, some files need to be preprocessed first in order to get valid Fortran that can then be parsed. Unfortunately, fparser can't handle the output of either cpp or gfortran -E -cpp:
$ echo "end" | gfortran -E -cpp - > mvce.f90
$ cat mvce.f90
# 0 "<stdin>"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "<stdin>"
end
$ fparser2 --task=none mvce.f90
File: 'mvce.f90'
Syntax error: at line 1
>>># 0 "<stdin>"
This is because the annotations inserted by gfortran look like PP macros. To parse them successfully the existing preprocessor nodes would require to be extended.
We have had good experiences using pcpp to preprocess files before parsing with fparser, which might be a viable alternative for you?
This turns out to be basically equivalent to the #line directive, but is from the output of the preprocessor.
Playing about with different compilers on godbolt, it looks like this is fairly standard preprocessor output, so should probably be supported in fparser.
Yes, pcpp would also work for my use case too.