-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FPP directives mid statement can cause trouble #429
Comments
Thanks for reporting this Matthew. In the fparser docs on FPP/CPP directives (https://fparser.readthedocs.io/en/latest/fparser2.html#preprocessing-directives) I can see there's the explicit limitation that any Fortran with directives in it must still be syntactically correct with them removed, which this code is. I'll do some digging and see whether it's feasible to support this case. I do feel like this might be a Road to Nowhere though as we'll fast end up with a parse tree that doesn't represent any code that is actually compiled which is of limited use? Could you describe why you need fparser to process this code rather than the code after it has been dealt with by a pre-processor? |
Bringing in @reuterbal as he may have some thoughts since he implemented the CPP support (I think?). |
(In this particular case, you could do a workaround:
) |
Yes, that's correct and the limitation statement is maybe not phrased perfectly as the limitation is even stricter: The input code must still be correct Fortran if the preprocessor directives were comments. Otherwise there's no alternative to preprocessing the Fortran before feeding it into Fparser (we use pcpp successfully where necessary). |
I discovered this problem on code like this:
So firstly I would like to acknowledge that this is hairy practice and the best solution is not to do it. However developers do do it and it is syntactically valid.
The problem seems to be that the appearance of a preprocessor directive within a statement, rather than between, is causing confusion.
This probably points to a wider problem where it would be true everywhere. For instance if people are using
#ifdef
to block out arguments in an argument list. Again something they really, really shouldn't but really, really have in the past.Do preprocessor directives need to be treated like comments which may also appear anywhere?
The text was updated successfully, but these errors were encountered: