diff options
-rw-r--r-- | src/fpm_source_parsing.f90 | 31 | ||||
-rw-r--r-- | test/fpm_test/test_source_parsing.f90 | 23 |
2 files changed, 34 insertions, 20 deletions
diff --git a/src/fpm_source_parsing.f90 b/src/fpm_source_parsing.f90 index dd9a4c5..6fa00d5 100644 --- a/src/fpm_source_parsing.f90 +++ b/src/fpm_source_parsing.f90 @@ -79,7 +79,7 @@ function parse_f_source(f_filename,error) result(f_source) integer :: stat integer :: fh, n_use, n_include, n_mod, i, j, ic, pass type(string_t), allocatable :: file_lines(:) - character(:), allocatable :: temp_string, mod_name + character(:), allocatable :: temp_string, mod_name, string_parts(:) f_source%file_name = f_filename @@ -191,22 +191,25 @@ function parse_f_source(f_filename,error) result(f_source) ! Extract name of module if is module if (index(adjustl(lower(file_lines(i)%s)),'module ') == 1) then - mod_name = lower(split_n(file_lines(i)%s,n=2,delims=' ',stat=stat)) - if (stat /= 0) then - call file_parse_error(error,f_filename, & - 'unable to find module name',i, & - file_lines(i)%s) - return + ! Remove any trailing comments + ic = index(file_lines(i)%s,'!')-1 + if (ic < 1) then + ic = len(file_lines(i)%s) + end if + temp_string = trim(file_lines(i)%s(1:ic)) + + ! R1405 module-stmt := "MODULE" module-name + ! module-stmt has two space-delimited parts only + ! (no line continuations) + call split(temp_string,string_parts,' ') + if (size(string_parts) /= 2) then + cycle end if - if (mod_name == 'procedure' .or. & - mod_name == 'subroutine' .or. & - mod_name == 'function' .or. & - scan(mod_name,'=(')>0 ) then + mod_name = lower(trim(adjustl(string_parts(2)))) + if (scan(mod_name,'=(&')>0 ) then ! Ignore these cases: - ! module procedure * - ! module function * - ! module subroutine * + ! module <something>& ! module =* ! module (i) cycle diff --git a/test/fpm_test/test_source_parsing.f90 b/test/fpm_test/test_source_parsing.f90 index 79a4d7a..12fc419 100644 --- a/test/fpm_test/test_source_parsing.f90 +++ b/test/fpm_test/test_source_parsing.f90 @@ -309,7 +309,7 @@ contains open(file=temp_file, newunit=unit) write(unit, '(a)') & - & 'module my_mod', & + & 'module my_mod ! A trailing comment', & & 'use module_one', & & 'interface', & & ' module subroutine f()', & @@ -320,8 +320,21 @@ contains & 'program =1', & & 'program (i) =1', & & 'contains', & - & 'module procedure f()', & - & 'end procedure f', & + & 'module subroutine&', & + & ' e()', & + & 'end subroutine e', & + & 'module subroutine f()', & + & 'end subroutine f', & + & 'module function g()', & + & 'end function g', & + & 'module integer function h()', & + & 'end function h', & + & 'module real function i()', & + & 'string = " &', & + & 'module name"', & + & 'string = " &', & + & 'module name !"', & + & 'end function i', & & 'end module test' close(unit) @@ -712,7 +725,7 @@ contains open(file=temp_file, newunit=unit) write(unit, '(a)') & - & 'module :: my_mod', & + & 'module ::my_mod', & & 'end module test' close(unit) @@ -721,8 +734,6 @@ contains return end if - write(*,*) '"',f_source%modules_used(1)%s,'"' - end subroutine test_invalid_module |