390 ignore linemarkers#498
Conversation
|
I could also not find an official syntax for a linemaker, but looked at https://git.cels.anl.gov/ksalapenades/llvm-project/-/blob/develop/clang/test/Preprocessor/line-directive.c (and did some compiler tests to verify what gets rejected) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #498 +/- ##
=======================================
Coverage 92.23% 92.24%
=======================================
Files 88 88
Lines 13852 13866 +14
=======================================
+ Hits 12776 12790 +14
Misses 1076 1076 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Checking the git log, it appears this code was contributed by @reuterbal - I wonder if you would have time to provide some feedback? Thanks! |
reuterbal
left a comment
There was a problem hiding this comment.
Happy to provide my 2ct here. I agree that linemarkers should be handled like preprocessor directives and the implementation itself looks good to me.
As for the need for the additional regex validation: I believe you only need to encode the full linemarker specification as a regex pattern to use in WORDClsBase.match - either manually or using the building blocks in pattern_tools - e.g., like here:
fparser/src/fparser/two/pattern_tools.py
Line 416 in 5e124e5
Without testing it, I would expect this would maybe need to look like something like this:
_pattern = r"^\s*#\s+" + digit_string + "\s+" + file_name
…er syntax. Extend match function to be able to return the fully matched string.
|
Hi Balthasar, thanks a lot for the quick review, really appreciated.
I am glad that I made the right decision here :)
I tried that, and thanks a lot for the example. Looking at the But then I am stuck with my original problem: I am using: But if I do this, the matching in Basically, the rest of the match is discarded (line number and filename) :( I tried to fix that using: So, I provide This passed nearly all tests, except it would not remove spaces between "#" and line number and line number and file name. Therefore, I adjusted one linemarker test (but the test still checks that leading spaces before the I am not sure if this is the right solution tbh :( Maybe it should not be based on @reuterbal , @arporter , @sergisiso - feedback appreciated! The modification of the |
reuterbal
left a comment
There was a problem hiding this comment.
Nice work, the details of the keyword/value returns were lost on me and your proposal seems sensible to me.
Overall I think that's indeed much better now, no further comments!
arporter
left a comment
There was a problem hiding this comment.
Looks good to me Joerg, thanks. I could do with a bit of help understanding some of the changes - probably because I know pretty much nothing about the Pattern class.
I think it would also be good to test the new functionality in context - i.e. provide some Fortran containing some linemarkers and check that things work OK.
…ed when they are in a Fortran program.
…parsed in utils as part of classes, not as part of add_comments_includes_directives anymore).
|
I've resolved Balthasar's comments, and addressed all new issues. Back for next review. |
|
@arporter I just remembered that pylint flagged one issue, which looks wrong, but I just wanted to make sure it's not done on purpose before fixing. In Adding a The original (pre-black) line was: Which comes from Is it ok if I add the missing |
|
Nice catch, that was definitely a mistake when I expanded the test parameterisation. I'd say please add the missing |
|
Thanks for the confirmation. Updated to current master, ready for review. |
arporter
left a comment
There was a problem hiding this comment.
Thanks Joerg, pretty much there now - just a couple of minor things to tidy up and then this can go on.
|
All issues addressed, thanks! Ready for next review. |
…refers longer lines.
…y black prefers longer lines.
|
Since this could be the last PR before a new release, I triggered the psyclone integration tests with this last fparser commit. |
arporter
left a comment
There was a problem hiding this comment.
Thanks Joerg. CodeCov is happy now and so am I :-)
Fixes #390 by supporting linemarkers (
# 123 "test.f90"- indicating line number and file).I have used the existing preprocessor directive support, since linemarkers looks pretty much like a preprocessor directive (starting with
#). But I was unable to get it to verify properly out of the box - I feel like the existing implementation assumes that thevalueis constant (e.g.#ifdef), while in the case of a linemarker we don't have this (since it would need the line number and filename to verify correctness, and I couldn't work out how to do this). While it worked this way, it was unable to detect invalid linemarkers (# abc "xx.f90"or# 123 'no_single_quote_allowed.f90'). So, instead I added a simple regex check at the beginning, and only if that passes, it will use the established path.I am happy to reimplement (I know there is
pattern_tools.digit_stringandfile_name... I just couldn't figure out how to plug this all together.