|
1 | 1 | !> Implementation of basic error handling.
|
2 | 2 | module fpm_error
|
| 3 | + use fpm_strings, only : is_fortran_name, to_fortran_name |
3 | 4 | implicit none
|
4 | 5 | private
|
5 | 6 |
|
6 | 7 | public :: error_t
|
7 | 8 | public :: fatal_error, syntax_error, file_not_found_error
|
8 | 9 | public :: file_parse_error
|
| 10 | + public :: bad_name_error |
9 | 11 |
|
10 | 12 |
|
11 | 13 | !> Data type defining an error
|
@@ -45,6 +47,30 @@ subroutine syntax_error(error, message)
|
45 | 47 |
|
46 | 48 | end subroutine syntax_error
|
47 | 49 |
|
| 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 | + |
48 | 74 |
|
49 | 75 | !> Error created when a file is missing or not found
|
50 | 76 | subroutine file_not_found_error(error, file_name)
|
@@ -87,9 +113,9 @@ subroutine file_parse_error(error, file_name, message, line_num, &
|
87 | 113 |
|
88 | 114 | allocate(error)
|
89 | 115 | error%message = 'Parse error: '//message//new_line('a')
|
90 |
| - |
| 116 | + |
91 | 117 | error%message = error%message//file_name
|
92 |
| - |
| 118 | + |
93 | 119 | if (present(line_num)) then
|
94 | 120 |
|
95 | 121 | write(temp_string,'(I0)') line_num
|
@@ -120,9 +146,9 @@ subroutine file_parse_error(error, file_name, message, line_num, &
|
120 | 146 |
|
121 | 147 | error%message = error%message//new_line('a')
|
122 | 148 | error%message = error%message//' | '//repeat(' ',line_col-1)//'^'
|
123 |
| - |
| 149 | + |
124 | 150 | end if
|
125 |
| - |
| 151 | + |
126 | 152 | end if
|
127 | 153 |
|
128 | 154 | end if
|
|
0 commit comments