From 5566c16f184a20080238fcc731a4d1f039d9d29c Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 5 Jun 2021 14:18:08 +0100 Subject: [PATCH 1/4] Add: failing test for module stmt parsing --- test/fpm_test/test_source_parsing.f90 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/fpm_test/test_source_parsing.f90 b/test/fpm_test/test_source_parsing.f90 index 79a4d7a390..fb23030db4 100644 --- a/test/fpm_test/test_source_parsing.f90 +++ b/test/fpm_test/test_source_parsing.f90 @@ -309,7 +309,7 @@ subroutine test_module(error) 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,17 @@ subroutine test_module(error) & '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()', & + & 'end function i()', & & 'end module test' close(unit) @@ -712,7 +721,7 @@ subroutine test_invalid_module(error) open(file=temp_file, newunit=unit) write(unit, '(a)') & - & 'module :: my_mod', & + & 'module ::my_mod', & & 'end module test' close(unit) @@ -721,8 +730,6 @@ subroutine test_invalid_module(error) return end if - write(*,*) '"',f_source%modules_used(1)%s,'"' - end subroutine test_invalid_module From c1a902d6556d25fe491c3ba8eed4999c9ee27372 Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 5 Jun 2021 14:20:45 +0100 Subject: [PATCH 2/4] Fix: module stmt parsing --- src/fpm_source_parsing.f90 | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/fpm_source_parsing.f90 b/src/fpm_source_parsing.f90 index dd9a4c529b..6fa00d509e 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 & ! module =* ! module (i) cycle From 4ecf3f3a9ef1c6f6f559389d37281c0fe3d2ce1f Mon Sep 17 00:00:00 2001 From: LKedward Date: Sat, 5 Jun 2021 14:30:28 +0100 Subject: [PATCH 3/4] Cleanup test code --- test/fpm_test/test_source_parsing.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fpm_test/test_source_parsing.f90 b/test/fpm_test/test_source_parsing.f90 index fb23030db4..5d693755df 100644 --- a/test/fpm_test/test_source_parsing.f90 +++ b/test/fpm_test/test_source_parsing.f90 @@ -328,9 +328,9 @@ subroutine test_module(error) & 'module function g()', & & 'end function g', & & 'module integer function h()', & - & 'end function h()', & + & 'end function h', & & 'module real function i()', & - & 'end function i()', & + & 'end function i', & & 'end module test' close(unit) From 302782c036fc498dc3739c79fb34a814295f41e5 Mon Sep 17 00:00:00 2001 From: Laurence Kedward Date: Tue, 8 Jun 2021 15:48:53 +0100 Subject: [PATCH 4/4] Add: more edge cases for module parsing tests. --- test/fpm_test/test_source_parsing.f90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/fpm_test/test_source_parsing.f90 b/test/fpm_test/test_source_parsing.f90 index 5d693755df..12fc419b29 100644 --- a/test/fpm_test/test_source_parsing.f90 +++ b/test/fpm_test/test_source_parsing.f90 @@ -330,6 +330,10 @@ subroutine test_module(error) & '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)