MAINT: crackfortran regex simplify#18072
Conversation
* remove extraneous character class markers used in `crackline_re_1`: `\w` and `=` on their own have no benefit to character class `[]` inclusion * `name_match` has a character class that can be simplified because `\w` metacharacter already encompasses the digit metacharacter and the underscore
numpy/f2py/crackfortran.py
Outdated
|
|
||
| dep_matches = {} | ||
| name_match = re.compile(r'\w[\w\d_$]*').match | ||
| name_match = re.compile(r'\w[\w$]*').match |
There was a problem hiding this comment.
I suspect the original here was wrong.
A Fortran identifier must satisfy the following rules:
The first character must be a letter, The remaining characters, if any, may be letters, digits, or underscores, Fortran identifiers are case insensitive. That is, Smith, smith, sMiTh, SMiTH, smitH are all identical identifiers.
The first \w should probably be [A-Za-z]. The addition of \d_ is consistent with misunderstanding of \w not to include digits and underscores. The $ could probably be omitted, but it seems to work as is.
There was a problem hiding this comment.
Thanks, I revised based on your feedback
* `name_match` regular expression now starts by matching a letter only, based on reviewer feedback
|
Thanks Tyler. Looks like
|
remove extraneous character class markers used in
crackline_re_1:\wand=on their own have nobenefit to character class
[]inclusionname_matchhas a character class that can besimplified because
\wmetacharacter alreadyencompasses the digit metacharacter and the
underscore