-
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
ae41c50
5e124e5
7e482a2
88a74ee
8eb3954
fedc82c
8480ccf
b5e1f9f
76441b6
099a818
1634379
27c7817
09099bf
773ff8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,11 @@ | |
| # (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) | ||
|
|
@@ -57,6 +61,7 @@ | |
| "Cpp_Macro_Stmt", | ||
| "Cpp_Undef_Stmt", | ||
| "Cpp_Line_Stmt", | ||
| "Cpp_Linemarker_Stmt", | ||
| "Cpp_Error_Stmt", | ||
| "Cpp_Warning_Stmt", | ||
| "Cpp_Null_Stmt", | ||
|
|
@@ -649,6 +654,59 @@ def tostr(self): | |
| return "{0} {1}".format(*self.items) | ||
|
|
||
|
|
||
| class Cpp_Linemarker_Stmt(WORDClsBase): # Linemarker | ||
| """ | ||
| Linemarker | ||
|
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. A bit more detail would be good here. i.e. explain what a Linemarker is.
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. Done. |
||
|
|
||
| linemarker-stmt is # digit-sequence [ "s-char-sequence" ] [digit ...] | ||
|
hiker marked this conversation as resolved.
Outdated
|
||
| """ | ||
|
|
||
| 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. | ||
| _pattern = pattern.Pattern("<linemarker>", r"^\s*#", value="#") | ||
|
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. Note that most Fortran compilers don't accept white space in front of the
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. I actually remember that I was wondering about the |
||
|
|
||
| @staticmethod | ||
| def match(string): | ||
| """Implements the matching for a linemarker. | ||
| The right hand side of the directive is not matched any further | ||
|
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. What does the "right hand side of the directive" mean?
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. I've reworded that. |
||
| but simply kept as a string. | ||
|
|
||
| :param str string: the string to match with as a line statement. | ||
|
|
||
| :return: a tuple of size 1 with the right hand side 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. No line-continuation and please update to use type hints.
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. Fixed. |
||
| or `None` if there is no match. | ||
| :rtype: (`str`) or `NoneType` | ||
|
|
||
| """ | ||
| if not string: | ||
| return None | ||
|
|
||
| # We can't fully rely on WORDClsBase, since it can't easily | ||
| # test if there is a line number following (it returns | ||
| # `value` for a match, but can't insert the matched line number | ||
| # in this value). | ||
| if not re.match(r"^\s*#\s+[0-9]+\s+\".*\"", string): | ||
| return | ||
|
|
||
| return WORDClsBase.match( | ||
| Cpp_Linemarker_Stmt._pattern, | ||
| Cpp_Pp_Tokens, | ||
| string, | ||
| colons=False, | ||
| require_cls=True, | ||
| ) | ||
|
|
||
| def tostr(self): | ||
|
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. typehints pls.
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. Done. |
||
| """ | ||
| :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. |
||
| :rtype: str | ||
| """ | ||
| return "{0} {1}".format(*self.items) | ||
|
|
||
|
|
||
| class Cpp_Error_Stmt(WORDClsBase): # 6.10.5 Error directive | ||
| """ | ||
| C99 6.10.5 Error directive | ||
|
|
||
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.