Skip to content

Commit d13dfca

Browse files
committed
make separate routine for checking validity of name
1 parent 55a7efe commit d13dfca

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

src/fpm/error.f90

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
!> Implementation of basic error handling.
22
module fpm_error
3+
use fpm_strings, only : is_fortran_name, to_fortran_name
34
implicit none
45
private
56

67
public :: error_t
78
public :: fatal_error, syntax_error, file_not_found_error
89
public :: file_parse_error
10+
public :: bad_name_error
911

1012

1113
!> Data type defining an error
@@ -45,6 +47,30 @@ subroutine syntax_error(error, message)
4547

4648
end subroutine syntax_error
4749

50+
function bad_name_error(error, label,name)
51+
52+
!> Instance of the error data
53+
type(error_t), allocatable, intent(out) :: error
54+
55+
!> Error message label to add to message
56+
character(len=*), intent(in) :: label
57+
58+
!> name value to check
59+
character(len=*), intent(in) :: name
60+
61+
logical :: bad_name_error
62+
63+
if(.not.is_fortran_name(to_fortran_name(name)))then
64+
bad_name_error=.true.
65+
allocate(error)
66+
error%message = 'manifest file syntax error: '//label//' name must be composed only of &
67+
&alphanumerics, "-" and "_" and start with a letter ::'//name
68+
else
69+
bad_name_error=.false.
70+
endif
71+
72+
end function bad_name_error
73+
4874

4975
!> Error created when a file is missing or not found
5076
subroutine file_not_found_error(error, file_name)
@@ -87,9 +113,9 @@ subroutine file_parse_error(error, file_name, message, line_num, &
87113

88114
allocate(error)
89115
error%message = 'Parse error: '//message//new_line('a')
90-
116+
91117
error%message = error%message//file_name
92-
118+
93119
if (present(line_num)) then
94120

95121
write(temp_string,'(I0)') line_num
@@ -120,9 +146,9 @@ subroutine file_parse_error(error, file_name, message, line_num, &
120146

121147
error%message = error%message//new_line('a')
122148
error%message = error%message//' | '//repeat(' ',line_col-1)//'^'
123-
149+
124150
end if
125-
151+
126152
end if
127153

128154
end if

src/fpm/manifest/example.f90

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
module fpm_manifest_example
1818
use fpm_manifest_dependency, only : dependency_config_t, new_dependencies
1919
use fpm_manifest_executable, only : executable_config_t
20-
use fpm_error, only : error_t, syntax_error
20+
use fpm_error, only : error_t, syntax_error, bad_name_error
2121
use fpm_toml, only : toml_table, toml_key, toml_stat, get_value
22-
use fpm_strings, only : to_fortran_name, is_fortran_name
2322
implicit none
2423
private
2524

@@ -62,9 +61,7 @@ subroutine new_example(self, table, error)
6261
call syntax_error(error, "Could not retrieve example name")
6362
return
6463
end if
65-
if(.not.is_fortran_name(to_fortran_name(self%name)))then
66-
call syntax_error(error, 'manifest file syntax error: example name must be composed only of &
67-
&alphanumerics, "-" and "_" and start with a letter::'//self%name)
64+
if (bad_name_error(error,'example',self%name))then
6865
return
6966
endif
7067
call get_value(table, "source-dir", self%source_dir, "example")

src/fpm/manifest/executable.f90

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
!>```
1313
module fpm_manifest_executable
1414
use fpm_manifest_dependency, only : dependency_config_t, new_dependencies
15-
use fpm_error, only : error_t, syntax_error
16-
use fpm_strings, only : string_t, is_fortran_name, to_fortran_name
15+
use fpm_error, only : error_t, syntax_error, bad_name_error
16+
use fpm_strings, only : string_t
1717
use fpm_toml, only : toml_table, toml_key, toml_stat, get_value
1818
implicit none
1919
private
@@ -72,9 +72,7 @@ subroutine new_executable(self, table, error)
7272
call syntax_error(error, "Could not retrieve executable name")
7373
return
7474
end if
75-
if(.not.is_fortran_name(to_fortran_name(self%name)))then
76-
call syntax_error(error, 'manifest file syntax error: executable name must be composed only of &
77-
&alphanumerics, "-" and "_" and start with a letter::'//self%name)
75+
if (bad_name_error(error,'executable',self%name))then
7876
return
7977
endif
8078
call get_value(table, "source-dir", self%source_dir, "app")

src/fpm/manifest/package.f90

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ module fpm_manifest_package
3939
use fpm_manifest_install, only: install_config_t, new_install_config
4040
use fpm_manifest_test, only : test_config_t, new_test
4141
use fpm_filesystem, only : exists, getline, join_path
42-
use fpm_error, only : error_t, fatal_error, syntax_error
42+
use fpm_error, only : error_t, fatal_error, syntax_error, bad_name_error
4343
use fpm_toml, only : toml_table, toml_array, toml_key, toml_stat, get_value, &
4444
& len
45-
use fpm_strings, only : is_fortran_name, to_fortran_name
4645
use fpm_versioning, only : version_t, new_version
4746
implicit none
4847
private
@@ -132,9 +131,7 @@ subroutine new_package(self, table, root, error)
132131
call syntax_error(error, "Could not retrieve package name")
133132
return
134133
end if
135-
if(.not.is_fortran_name(to_fortran_name(self%name)))then
136-
call syntax_error(error, 'manifest file syntax error: package name must be composed only of &
137-
&alphanumerics, "-" and "_" and start with a letter::'//self%name)
134+
if (bad_name_error(error,'package',self%name))then
138135
return
139136
endif
140137

src/fpm/manifest/test.f90

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
module fpm_manifest_test
1818
use fpm_manifest_dependency, only : dependency_config_t, new_dependencies
1919
use fpm_manifest_executable, only : executable_config_t
20-
use fpm_error, only : error_t, syntax_error
20+
use fpm_error, only : error_t, syntax_error, bad_name_error
2121
use fpm_toml, only : toml_table, toml_key, toml_stat, get_value
22-
use fpm_strings, only : to_fortran_name, is_fortran_name
2322
implicit none
2423
private
2524

@@ -62,9 +61,7 @@ subroutine new_test(self, table, error)
6261
call syntax_error(error, "Could not retrieve test name")
6362
return
6463
end if
65-
if(.not.is_fortran_name(to_fortran_name(self%name)))then
66-
call syntax_error(error, 'manifest file syntax error: test name must be composed only of &
67-
&alphanumerics, "-" and "_" and start with a letter ::'//self%name)
64+
if (bad_name_error(error,'test',self%name))then
6865
return
6966
endif
7067
call get_value(table, "source-dir", self%source_dir, "test")

0 commit comments

Comments
 (0)