forked from pearu/f2py
-
Notifications
You must be signed in to change notification settings - Fork 34
390 ignore linemarkers #498
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
Open
hiker
wants to merge
14
commits into
master
Choose a base branch
from
390_ignore_linemarkers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ae41c50
#390 Start to add support for linemarker.
hiker 5e124e5
#390 Improve linermarker handling to support detection of invalid mar…
hiker 7e482a2
#390 Simplified parameterization.
hiker 88a74ee
#390 Fix incorrect linemarker specification in comment.
hiker 8eb3954
#390 Remove need for using an additional regex to verify the linemark…
hiker fedc82c
#390 Updated manual.
hiker 8480ccf
#390 Updated comments and added proper typing.
hiker b5e1f9f
#390 Added test that preprocessor directives are indeed properly pars…
hiker 76441b6
#390 Moved location of preprocessor directive (which means it is now …
hiker 099a818
#390 Fixed black.
hiker 1634379
#390 Fix for github black, my black does not need that comma.
hiker 27c7817
#390 Fix missing ',' which resulted in incorrectly concatenating stri…
hiker 09099bf
Merge remote-tracking branch 'origin/master' into 390_ignore_linemarkers
hiker 773ff8a
#390 Fixed previous fix - oops.
hiker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,14 +32,19 @@ | |
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
|
||
| """C99 Preprocessor Syntax Rules.""" | ||
| """C99 Preprocessor Syntax Rules. It also supports linemarker statements | ||
| (which are technically not preprocessor directives, but are very close | ||
| in their syntax, i.e. starting with `#`) | ||
|
|
||
| """ | ||
|
|
||
| # Author: Balthasar Reuter <balthasar.reuter@ecmwf.int> | ||
| # Based on previous work by Martin Schlipf (https://github.com/martin-schlipf) | ||
| # First version created: Jan 2020 | ||
|
|
||
| import re | ||
| import sys | ||
| from typing import Optional, Union | ||
|
|
||
| from fparser.common.readfortran import FortranReaderBase, CppDirective | ||
| from fparser.two import pattern_tools as pattern | ||
|
|
@@ -57,6 +62,7 @@ | |
| "Cpp_Macro_Stmt", | ||
| "Cpp_Undef_Stmt", | ||
| "Cpp_Line_Stmt", | ||
| "Cpp_Linemarker_Stmt", | ||
| "Cpp_Error_Stmt", | ||
| "Cpp_Warning_Stmt", | ||
| "Cpp_Null_Stmt", | ||
|
|
@@ -649,6 +655,64 @@ def tostr(self): | |
| return "{0} {1}".format(*self.items) | ||
|
|
||
|
|
||
| class Cpp_Linemarker_Stmt(WORDClsBase): # Linemarker | ||
| """ | ||
| This class represents a Linemarker. A linemarker indicates the | ||
| line number and file name the following line is coming from (e.g. | ||
| if a file has been inlined, this will allow the compiler to correctly | ||
| indicate the original source line). While linemarkers are technically | ||
| not preprocessor directives, their syntax is very similar, so they are | ||
| handled here. | ||
|
|
||
| linemarker-stmt is # digit-sequence "s-char-sequence" [digit ...] | ||
| """ | ||
|
|
||
| subclass_names = [] | ||
| use_names = ["Cpp_Pp_Tokens"] | ||
|
|
||
| # The match method will check that it is a valid linemarker, i.e. | ||
| # it has a line number, and file name in double quotes. Setting value | ||
| # to None means that the pattern matching will return the matched | ||
| # string (i.e. `# linenumber "filename"`), any following flags will | ||
| # be stored as items of type Cpp_Pp_Tokens. | ||
| _pattern = pattern.Pattern("<linemarker>", r"^\s*#\s+\d+\s+\".*\".*$", value=None) | ||
|
|
||
| @staticmethod | ||
| def match( | ||
| string: Union[str, FortranReaderBase], | ||
| ) -> Optional[tuple[str, "Cpp_Linemarker_Stmt"]]: | ||
| """Implements the matching for a linemarker. | ||
| The optional flag (digits) allowed after the file name are not matched | ||
| any further but simply kept as a string. | ||
|
|
||
| :param string: the string to match with as a line statement. | ||
|
|
||
| :return: an instance of Cpp_Linemarker_Stmt or `None` if there is no | ||
| match. | ||
|
|
||
| """ | ||
| if not string: | ||
| return None | ||
|
|
||
| return WORDClsBase.match( | ||
| Cpp_Linemarker_Stmt._pattern, | ||
| Cpp_Pp_Tokens, | ||
| string, | ||
| colons=False, | ||
| require_cls=False, | ||
| ) | ||
|
|
||
| def tostr(self) -> str: | ||
| """ | ||
| Returns the line marker as string. Note that fparser accepts | ||
| spaces before the `#`, but it should remove the spaces, hence | ||
| we lstrip the result | ||
|
|
||
| :return: this linemarker as a string. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line before :return: please.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops. |
||
| """ | ||
| return self.items[0].lstrip() | ||
|
|
||
|
|
||
| class Cpp_Error_Stmt(WORDClsBase): # 6.10.5 Error directive | ||
| """ | ||
| C99 6.10.5 Error directive | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the documentation (https://fparser.readthedocs.io/en/latest/fparser2.html#preprocessing-directives)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I missed that, thanks.