Add support for preprocessor directives to fparser2#239
Add support for preprocessor directives to fparser2#239rupertford merged 53 commits intostfc:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #239 +/- ##
==========================================
+ Coverage 90.24% 90.41% +0.16%
==========================================
Files 34 35 +1
Lines 12150 12349 +199
==========================================
+ Hits 10965 11165 +200
+ Misses 1185 1184 -1
Continue to review full report at Codecov.
|
|
OK, apparently the section symbol used in the draft isn't ASCII... removed it from comments and docstring |
rupertford
left a comment
There was a problem hiding this comment.
Great PR, thanks. Comments and requests for change are inline. I'm afraid I'll also need you to describe the new functionality in the documentation.
If you want to record the fact you have made changes to certain files then you can add a copyright line at the top of the file next to the existing one and/or add you name saying Modified by: ...
So far we have avoided adding names in and adding additional copyright info but I would be happy for that to change.
I'll check for codestyle conformance next time.
|
Thanks a lot for your review and the suggested changes! |
|
@rupertford I tried to address all of your requested changes. I have marked most of your comments as resolved after having worked on that bit simply to keep track of what remains to be done (Not sure if this is just a personal setting or if they appear like that for you as well). It may not necessarily mean that the raised point is resolved to your satisfaction ;-) When you find time I'd be glad if you could have another look and come back with some further remarks. |
|
Thanks @reuterbal. I've changed the status to ready-for-review and will review when I next get the chance. For the record, our policy is that the reviewer marks things resolved :-). We would be happy to give you access to the repo if you would prefer to work here rather than on a fork. |
|
Sorry, I un-resolved them again... I would not mind repository access but it's also not a problem to work on a fork. It doesn't really change much for me. Any changes that I have to make I will send your way as a PR anyways and there will be an issue about that beforehand (unless it's something very tiny like #241). |
rupertford
left a comment
There was a problem hiding this comment.
I just have one inline comment about reducing code replication - I should have mentioned this in the first review before asking you to update all the docstrings - apologies. Could you also 1) update the documentation with the new functionality 2) check coverage of the changes as codecov is not saying 100% 3) bring the code up-to-date with master.
|
Thanks for looking through it again. Code duplication is a fair point that I did not think about since most of the matching was already implemented by @martin-schlipf and I changed only a few bits. Looking through the relevant matching routines and leaving case sensitivity aside, I think the following could be done:
Thus, in principal it should be possible but the question is how to take care of case sensitivity. |
|
Yes, good point about case insensitive matching, I forgot about that. The simplest thing would probably be to add an an A nicer way would be to do a case sensitive match and then subclass this for a case insensitive match and use |
|
If it's OK I would go with the |
|
Fine by me. |
|
No need to apologize, really. I appreciate the scrutiny. |
rupertford
left a comment
There was a problem hiding this comment.
It looks great. There is one thing mentioned inline and could you also please add yourself as an author to the fparser documentation and as an author in the documentation license file.
I've checked everything else so once these are done it can be merged to master.
| from fparser.api import get_reader | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module', name='f2003_parser') |
There was a problem hiding this comment.
This f2003 fixture is picked up from conftest.py so no need to specify it in the file.
There was a problem hiding this comment.
The fixture in conftest.py creates the parser but does not return it. However, in a few tests I'm parsing longer pieces of code to check that directives can appear everywhere in a source file, i.e., I do need that parser, which is why I added that separate fixture here. I could also change the fixture in conftest.py such that it does return the parser, if you prefer?
There was a problem hiding this comment.
Ah yes, good point, I missed that. If you could move the fixture you have created into conftest.py so it is available to other tests in the future that would be great. We can decide whether to merge them into one fixture at a later date (I would be in favour but let's minimise the changes you have to make in this PR).
|
Many thanks, happy to hear that :) |
I've just talked to @arporter about this. We agree that you should go 3rd if you are OK with that. We don't currently have an official policy, it was just the order in which people contributed to the documentation (in time) + Pearu, so it is at least consistent with that informal policy. We agree there should be an official policy but suggest we park that decision for the time being. And, yes, the files you mention are the correct ones. If you wouldn't mind updating the copyright date to 2020 as well that would be great (but the PR will still be approved if you don't :-)). |
|
I have moved the fixture and updated the author list (changed copyright dates wherever I've seen some). I don't care much about the order but wanted to avoid tipping on any toes. Many thanks again for taking the time to work through this big change. This is a very crucial feature for our downstream tools and I'm very happy that it makes its way into master. |
rupertford
left a comment
There was a problem hiding this comment.
all issues have been addressed. All checks pass. Approving.
|
Just for clarification: Is it correct, that only C preprocessor directives are supported? I'm currently stumbling over CoCo directives starting with |
Yes that's right . This PR added support for cpp directives. Do you need to reason about the CoCo directives or would it be OK if they were removed? |
No, for my current task it would be sufficient to ignore them. At the moment the culprit is this one: But I fear that this won't be as straight forward as there are lines starting with ?? like above, but also macros within code lines like: However, I never came across one of those yet, so I don't know whether they'll also cause a NoMatchError. |
Ah. Yes, that is a problem. Presumably you are not wanting/able to pre-process the code first. I don't know much about CoCo but pre-processor syntax and Fortran syntax are not typically designed to be mixed. We could follow the approach taken by the cpp support but it would have the same restriction that the code without the directives was valid Fortran (which would include, not allowing inline macro code unless the macros always aligned with Fortran tokens - then we could potentially extend the associated rule). |
|
Well, I want to avoid operating on intermediate files. But I also want to create a working script, thus I'll go for the preprocessed files. Trying to get fparser to be able to cope with CoCo directives would take considerable effort, I presume. Nevertheless, thanks for your fast response :) |
|
No problem. Getting fparser to cope with full line CoCo directives should be relatively simple, so if that would be useful we could look at adding that. Adding understanding about the Coco syntax of full line directives would be feasible, but a reasonable amount of effort, but it sounds like you don't need this. Adding support for inline macros would be considerable effort I suspect and might only work in certain circumstances. |
|
Exactly, for my current problem I don't need to understand CoCo syntax. Additionally, we are making plans to switch to Fypp (in the not so near future), which would introduce it's own specialties. Thanks for clarifications and support. :) |
This adds support for preprocessor directives to fparser2 as discussed in #215
It operates under the assumption that the code reduces to valid Fortran when preprocessor directives are left out. The implementation follows closely the description in the C99 draft, omitting only the
#pragmastatement.Please mention any changes that you would like to be made.