diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fpm/error.f90 | 34 | ||||
-rw-r--r-- | src/fpm/manifest/example.f90 | 7 | ||||
-rw-r--r-- | src/fpm/manifest/executable.f90 | 8 | ||||
-rw-r--r-- | src/fpm/manifest/package.f90 | 7 | ||||
-rw-r--r-- | src/fpm/manifest/test.f90 | 7 |
5 files changed, 39 insertions, 24 deletions
diff --git a/src/fpm/error.f90 b/src/fpm/error.f90 index 0a5e9b1..89d1383 100644 --- a/src/fpm/error.f90 +++ b/src/fpm/error.f90 @@ -1,11 +1,13 @@ !> Implementation of basic error handling. module fpm_error + use fpm_strings, only : is_fortran_name, to_fortran_name implicit none private public :: error_t public :: fatal_error, syntax_error, file_not_found_error public :: file_parse_error + public :: bad_name_error !> Data type defining an error @@ -45,6 +47,30 @@ contains end subroutine syntax_error + function bad_name_error(error, label,name) + + !> Instance of the error data + type(error_t), allocatable, intent(out) :: error + + !> Error message label to add to message + character(len=*), intent(in) :: label + + !> name value to check + character(len=*), intent(in) :: name + + logical :: bad_name_error + + if(.not.is_fortran_name(to_fortran_name(name)))then + bad_name_error=.true. + allocate(error) + error%message = 'manifest file syntax error: '//label//' name must be composed only of & + &alphanumerics, "-" and "_" and start with a letter ::'//name + else + bad_name_error=.false. + endif + + end function bad_name_error + !> Error created when a file is missing or not found subroutine file_not_found_error(error, file_name) @@ -87,9 +113,9 @@ contains allocate(error) error%message = 'Parse error: '//message//new_line('a') - + error%message = error%message//file_name - + if (present(line_num)) then write(temp_string,'(I0)') line_num @@ -120,9 +146,9 @@ contains error%message = error%message//new_line('a') error%message = error%message//' | '//repeat(' ',line_col-1)//'^' - + end if - + end if end if diff --git a/src/fpm/manifest/example.f90 b/src/fpm/manifest/example.f90 index 56f64c8..3319401 100644 --- a/src/fpm/manifest/example.f90 +++ b/src/fpm/manifest/example.f90 @@ -17,9 +17,8 @@ module fpm_manifest_example use fpm_manifest_dependency, only : dependency_config_t, new_dependencies use fpm_manifest_executable, only : executable_config_t - use fpm_error, only : error_t, syntax_error + use fpm_error, only : error_t, syntax_error, bad_name_error use fpm_toml, only : toml_table, toml_key, toml_stat, get_value - use fpm_strings, only : to_fortran_name, is_fortran_name implicit none private @@ -62,9 +61,7 @@ contains call syntax_error(error, "Could not retrieve example name") return end if - if(.not.is_fortran_name(to_fortran_name(self%name)))then - call syntax_error(error, 'manifest file syntax error: example name must be composed only of & - &alphanumerics, "-" and "_" and start with a letter::'//self%name) + if (bad_name_error(error,'example',self%name))then return endif call get_value(table, "source-dir", self%source_dir, "example") diff --git a/src/fpm/manifest/executable.f90 b/src/fpm/manifest/executable.f90 index 9447687..60c20ec 100644 --- a/src/fpm/manifest/executable.f90 +++ b/src/fpm/manifest/executable.f90 @@ -12,8 +12,8 @@ !>``` module fpm_manifest_executable use fpm_manifest_dependency, only : dependency_config_t, new_dependencies - use fpm_error, only : error_t, syntax_error - use fpm_strings, only : string_t, is_fortran_name, to_fortran_name + use fpm_error, only : error_t, syntax_error, bad_name_error + use fpm_strings, only : string_t use fpm_toml, only : toml_table, toml_key, toml_stat, get_value implicit none private @@ -72,9 +72,7 @@ contains call syntax_error(error, "Could not retrieve executable name") return end if - if(.not.is_fortran_name(to_fortran_name(self%name)))then - call syntax_error(error, 'manifest file syntax error: executable name must be composed only of & - &alphanumerics, "-" and "_" and start with a letter::'//self%name) + if (bad_name_error(error,'executable',self%name))then return endif call get_value(table, "source-dir", self%source_dir, "app") diff --git a/src/fpm/manifest/package.f90 b/src/fpm/manifest/package.f90 index fd5e873..1f85144 100644 --- a/src/fpm/manifest/package.f90 +++ b/src/fpm/manifest/package.f90 @@ -39,10 +39,9 @@ module fpm_manifest_package use fpm_manifest_install, only: install_config_t, new_install_config use fpm_manifest_test, only : test_config_t, new_test use fpm_filesystem, only : exists, getline, join_path - use fpm_error, only : error_t, fatal_error, syntax_error + use fpm_error, only : error_t, fatal_error, syntax_error, bad_name_error use fpm_toml, only : toml_table, toml_array, toml_key, toml_stat, get_value, & & len - use fpm_strings, only : is_fortran_name, to_fortran_name use fpm_versioning, only : version_t, new_version implicit none private @@ -132,9 +131,7 @@ contains call syntax_error(error, "Could not retrieve package name") return end if - if(.not.is_fortran_name(to_fortran_name(self%name)))then - call syntax_error(error, 'manifest file syntax error: package name must be composed only of & - &alphanumerics, "-" and "_" and start with a letter::'//self%name) + if (bad_name_error(error,'package',self%name))then return endif diff --git a/src/fpm/manifest/test.f90 b/src/fpm/manifest/test.f90 index a7e5e88..e689774 100644 --- a/src/fpm/manifest/test.f90 +++ b/src/fpm/manifest/test.f90 @@ -17,9 +17,8 @@ module fpm_manifest_test use fpm_manifest_dependency, only : dependency_config_t, new_dependencies use fpm_manifest_executable, only : executable_config_t - use fpm_error, only : error_t, syntax_error + use fpm_error, only : error_t, syntax_error, bad_name_error use fpm_toml, only : toml_table, toml_key, toml_stat, get_value - use fpm_strings, only : to_fortran_name, is_fortran_name implicit none private @@ -62,9 +61,7 @@ contains call syntax_error(error, "Could not retrieve test name") return end if - if(.not.is_fortran_name(to_fortran_name(self%name)))then - call syntax_error(error, 'manifest file syntax error: test name must be composed only of & - &alphanumerics, "-" and "_" and start with a letter ::'//self%name) + if (bad_name_error(error,'test',self%name))then return endif call get_value(table, "source-dir", self%source_dir, "test") |