-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: Release crackfortran as a standalone tool for parsing Fortran. #25307
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: main
Are you sure you want to change the base?
Conversation
…ran declarations The `crackfortran` tool is developed to be a backend for the f2py utility. However, crackfortran could also be very useful on its own. The use of crackfortran could be demonstrated by the following example: ```json ► crackfortran symbol.f90 -show Reading fortran codes... Reading file 'symbol.f90' (format:free) Post-processing... Block: symbol Post-processing (stage 2)... [{'args': ['x', 'y', 'symx', 'opt'], 'block': 'subroutine', 'body': [], 'common': {'pltdat': ['model', 'ploter'], 'symbls': ['nsym', 'symbl']}, 'commonvars': ['model', 'ploter', 'nsym', 'symbl'], 'entry': {}, 'externals': [], 'from': 'symbol.f90', 'implicit': None, 'interfaced': [], 'name': 'symbol', 'sortvars': ['model', 'nsym', 'ploter', 'symbl', 'opt', 'x', 'y', 'symx'], 'vars': {'model': {'attrspec': [], 'typespec': 'integer'}, 'nsym': {'attrspec': [], 'typespec': 'integer'}, 'opt': {'typespec': 'integer'}, 'ploter': {'attrspec': [], 'typespec': 'integer'}, 'symbl': {'attrspec': [], 'dimension': ['20', '2'], 'typespec': 'integer'}, 'symx': {'attrspec': [], 'dimension': ['2'], 'typespec': 'integer'}, 'x': {'typespec': 'real'}, 'y': {'typespec': 'real'}}}] ``` The tool presents the subroutine declaration statements as a JSON that can be consumed by other tools for further analysis. Therefore, this patch adds changes required to expose crackfortran as an entry point, next to f2py3.
9bc04b9
to
ee1036e
Compare
This would be a good topic to raise on the numpy mailing list. |
@charris , could you please help with this? |
You can subscribe to the mailing list at https://mail.python.org/accounts/signup/?next=/mailman3/lists/numpy-discussion.python.org/. Then just send an email to numpy-discussion@python.org. You can also open a numpy issue with the suggestion. |
@HaoZeke does this seem reasonable, or is (for example) LFortran already exposing a more maintainable and robust parser? |
@rgommers , sincerely any rich compiler-level technology is irrelevant to this call. The beauty of crackfortran is in its simplicity. Crackfortran parses the source (actually, the interface part only, not the code!) unarmed, only by regex matching. This approach is more oriented on extracting analytics from the syntactically-correct source. Unlike that, compiler parser has to be precise about may possible error states to assist correction of malformed code. Furthermore, extracting a JSON usable by a non-compiler person from a yacc/bison-generated AST would be another tough adventure. So my point is: these are two different worlds. There are cars and carts, and good cars are not obsoleting the joy of carting. |
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.
Thanks for this @dmikushin. I have a technical problem, which is that this needs to follow #24552 and use the argparse
preparse for this.
I have some other thoughts which I'll comment with.
LFortran has a more robust parser, but it is still less complete than that of With regards to @dmikushin's eloquent comment:
I actually tend to agree. @pearu has mentioned on several occasions that F2PY doesn't need to penalize the user for not constructing correct Fortran (also F2PY takes the The cleanest route to couple LFortran and F2PY in the near future would be to generate F2PY's Some other projects also use However some more thoughts for @dmikushin:
In principle, letting users clean up |
@dmikushin is this still relevant? |
I'm still interested! |
Just some data points:
Regarding releasing crackfortran as a standalone tool: |
LFortran supports F77. |
[OT Warning]
which is a valid Fortran 77 source code. A true Fortran 77 parser cannot rely on nowadays tokenizers that LFortran uses. Hence my claim. |
AFAIK LFortran plans to support all of F77, but is continually in development, so eventually it will get there. https://github.com/pearu/f2py is a good place to look, but the frontend (CLI) should follow the newer Practically speaking of course, one of the current highest barriers to major changes within F2PY is the lack of existing test coverage within NumPy and in the larger context of parsing Fortran code. @dmikushin could you clarify the scope of your proposed work? Was the intent just to move the existing |
You have to tell LFortran to use its fixed-form parser:
LFortran supports fixed-form, for example it can parse all of SciPy correctly. If you find any bug, you can report it, but overall LFortran supports F77 and fixed-form. You can contact me offline if you want to check with me before posting online what LFortran can or cannot do. |
The
crackfortran
tool is developed to be a backend for the f2py utility. However, crackfortran could also be very useful on its own.The use of crackfortran could be demonstrated by the following example:
The tool presents the subroutine declaration statements as a JSON that can be consumed by other tools for further analysis.
Everyone who is looking for the Fortran parser should first come across crackfortran, before wasting time on many sloppy half-working parsers on the Internet. In this regard, the importance of crackfortran is currently misrepresented by keeping it in the depth of numpy internals. Therefore, this patch adds changes required to expose crackfortran as an entry point, next to f2py3 and reveal it to the world.