stfc / fparser

This project maintains and develops a Fortran parser called fparser2 written purely in Python which supports Fortran 2003 and some Fortran 2008. A legacy parser fparser1 is also available but is not supported. The parsers were originally part of the f2py project by Pearu Peterson.
https://fparser.readthedocs.io
Other
61 stars 29 forks source link

fparser2 reports invalid Fortran for "use module_name, only:" #118

Closed TeranIvy closed 5 years ago

TeranIvy commented 5 years ago

Apparently, use module_name, only: is valid Fortran. The example used is below.

program test_module_name
  use module_name, only:
  implicit none
  integer :: i1, i2, i3
  i1 = 1; i2 = 2; i3 = 3
  write(*,*) "i1 = ", i1
end program test_module_name

This example compiles with Intel 17.0.1 and Gnu 6.1.0 and the effect of use module_name, only: is that nothing from the module_name gets used so it is effectively waste of code.

fparser2 reports invalid Fortran:

...
    raise FortranSyntaxError(error)
fparser.two.utils.FortranSyntaxError: at line 2

Perhaps raising a warning for this case would be useful.

rupertford commented 5 years ago

I've just looked at the Fortran2003 spec [https://wg5-fortran.org/N1601-N1650/N1601.pdf] and on page 468 it gives an example of use module_name, only :. The reason for doing this would be to keep variables inside the module in-scope e.g. when two children subroutines called from a parent subroutine want to use the module, the information would go out-of-scope when in the parent subroutine. However, whilst adding use module_name, only : disallows the parent subroutine from using the data, it does keep the module in-scope so that the children subroutines can share data from within the module.

rupertford commented 5 years ago

Created empty_only branch to work on this

TeranIvy commented 5 years ago

I learned something about F2003 here, thanks for explaining! As I said yesterday in Telco, I am happy to take on the review after PR is issued.

rupertford commented 5 years ago

Thanks @TeranIvy. I'm about to create a PR and assign it to you.

TeranIvy commented 5 years ago

PR #122 merged, closing issue.