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
64 stars 29 forks source link

Support for `module procedure ::` #405

Closed TeranIvy closed 1 year ago

TeranIvy commented 1 year ago

fparser2 raises a syntax error for module procedure statement when it is followed by double colon (::), e.g.

INTERFACE get_free_unit
MODULE PROCEDURE :: get_free_unit_32, get_free_unit_64
END INTERFACE get_free_unit

(see the relevant LFRic source).

When the double colon is omitted (e.g. MODULE PROCEDURE get_free_unit_32, get_free_unit_64), everything is fine. Both expressions pass compilation, so they should both be valid.

rupertford commented 1 year ago

The 2003 spec does not allow this: R1206 procedure-stmt is [ MODULE ] PROCEDURE procedure-name-list but the 2008 spec does: R1206 procedure-stmt is [ MODULE ] PROCEDURE [ :: ] procedure-name-list

rupertford commented 1 year ago

I can confirm this with gfortran ...

module test
  INTERFACE get_value
     MODULE PROCEDURE :: get_int, get_real
  END INTERFACE get_value
contains
  subroutine get_int(arg)
    integer :: arg
  end subroutine get_int
  subroutine get_real(arg)
    real :: arg
  end subroutine get_real
end module test
$ gfortran -c -std=f2003 module_procedure.f90
module_procedure.f90:3:22:

    3 |      MODULE PROCEDURE :: get_int, get_real
      |                      1
Error: Fortran 2008: double colon in MODULE PROCEDURE statement at (1)
$ gfortran -c -std=f2008 module_procedure.f90
$
rupertford commented 1 year ago

So we need to add support for this as a F2008 extension. I've removed the bug label and added f2008 :-).

rupertford commented 1 year ago

Created branch 405_module_procedure_colons

arporter commented 1 year ago

@TeranIvy this is now on master. Please could you check that it resolves the Stylist problem and then I'll close this issue (and make a new release).

rupertford commented 1 year ago

This is now on master and has been checked with stylist.