Source file manager More...
Data Types | |
type | mod_source_file::t_source_file_container |
Source file container. More... | |
Functions/Subroutines | |
subroutine | mod_source_file::source_file_initialize (source_file, filename) |
Initialize the t_source_file_container from a file. | |
subroutine | mod_source_file::source_file_initialize_from_string (source_file, string, label) |
Initialize the t_source_file_container from a string. | |
character function | mod_source_file::source_file_read_character (source_file) |
Read the next character of the source file. | |
subroutine | mod_source_file::source_file_unread_character (source_file) |
Return to the previous position in the source file. | |
subroutine | mod_source_file::source_file_finalize (source_file) |
Close a source file. | |
Source file manager
The source file manager aims to record the current position of the read cursor and provide a way to set an arbitrary position to the read cursor.
Let us recall the lexer/parser organization with the 3 main units:
!! keyword list !! v !! ┏━━━━━━━━━━┓ ┌───────────┐ ┌────────────┐ !! files ┃ ┃ characters │ │ tokens │ │ ───────> !! ─────> ┃ File ┃ ──────────>│ Lexer │ ───────> │ Parser │ tokens / actions !! ┃ ┃ │ │ │ │ <─────── !! ┗━━━━━━━━━━┛ └───────────┘ └────────────┘ !! mod_source_file mod_lexer mod_parser !! mod_identifier !! mod_scope !!
As an example, consider a file notus.txt
with the following content:
The following code opens the file and write every character preceded by the position, line and column number until the EOF is reached. It also diplays the newline flag.
Expected output:
subroutine mod_source_file::source_file_finalize | ( | type(t_source_file_container), intent(inout) | source_file | ) |
Close a source file.
Deallocate arrays but do not reset flags. They are required for the read/unread routines.
[in,out] | source_file | Source file container |
subroutine mod_source_file::source_file_initialize | ( | type(t_source_file_container), intent(out) | source_file, |
character(len=*), intent(in) | filename ) |
Initialize the t_source_file_container from a file.
Rank 0 processor reads the source file and spread its content to all processors.
[out] | source_file | Source file container |
[in] | filename | Source file name |
subroutine mod_source_file::source_file_initialize_from_string | ( | type(t_source_file_container), intent(out) | source_file, |
character(len=*), intent(in) | string, | ||
character(len=*), intent(in) | label ) |
Initialize the t_source_file_container from a string.
Rank 0 processor spreads its content to all processors.
[out] | source_file | Source file container |
[in] | string | String character |
[in] | label | Label for the string |
character function mod_source_file::source_file_read_character | ( | type(t_source_file_container), intent(inout) | source_file | ) |
Read the next character of the source file.
Behavior:
newline
flag to .true.
.eof
flag to .true.
.[in,out] | source_file | Source file container |
subroutine mod_source_file::source_file_unread_character | ( | type(t_source_file_container), intent(inout) | source_file | ) |
Return to the previous position in the source file.
[in,out] | source_file | Source file container |