input_parser_mod Module

A module for parsing input files.

Oskar Weser, 2022



Contents


Variables

Type Visibility Attributes Name Initial
integer, private, parameter :: max_line_length = 1028
character(len=*), private, parameter :: delimiter = ' '
character(len=*), private, parameter :: comment = '#'
character(len=*), private, parameter :: alt_comment = '('
character(len=*), private, parameter :: concat = '\'
character(len=*), private, parameter :: alt_concat = '+++'

Interfaces

public interface ManagingFileReader_t

  • public function construct_ManagingFileReader_t(file_name, echo_lines, err) result(res)

    Construct a ManagingFileReader_t

    If the argument echo_lines is present, then the read lines are echoed to the unit echo_lines. If the argument is not present, the echoing is switched off.

    If err is not present, all errors will lead to a stop of the program. Otherwise this argument contains the error code.

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: file_name
    integer, intent(in), optional :: echo_lines
    integer, intent(out), optional :: err

    Return Value type(ManagingFileReader_t)

public interface AttachedFileReader_t

  • private function construct_AttachedFileReader_t(file_id, echo_lines, file_name, current_line) result(res)

    Construct an AttachedFileReader_t

    If the argument echo_lines is present, then the read lines are echoed to the unit echo_lines. If the argument is not present, the echoing is switched off.

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(in) :: file_id
    integer, intent(in), optional :: echo_lines
    character(len=*), intent(in), optional :: file_name
    integer, intent(in), optional :: current_line

    Return Value type(AttachedFileReader_t)


Derived Types

type, public ::  FileReader_t

An abstract class that supports tokenized reading of lines.

Components

Type Visibility Attributes Name Initial
integer, private :: file_id
integer, private, allocatable :: echo_lines
character(len=:), private, allocatable :: file_name

The file name of the open file (if available).

integer, private, allocatable :: current_line

The current line (if available). The number refers to the line just returned from raw_nextline.

Type-Bound Procedures

procedure , private , :: raw_nextline Function
procedure , public :: close => my_close Subroutine
procedure , public :: nextline Function
procedure , public :: rewind => my_rewind Subroutine
procedure , public :: set_echo_lines Subroutine
procedure , public :: get_current_line Function
procedure , public :: get_file_name Function

type, public, extends(FileReader_t) ::  ManagingFileReader_t

A class for tokenized reading of lines, that manages the file access.

Read more…

Constructor

public function construct_ManagingFileReader_t (file_name, echo_lines, err)

Construct a ManagingFileReader_t

Read more…

Type-Bound Procedures

procedure , public :: close => my_close Subroutine
procedure , public :: nextline Function
procedure , public :: rewind => my_rewind Subroutine
procedure , public :: set_echo_lines Subroutine
procedure , public :: get_current_line Function
procedure , public :: get_file_name Function
procedure , public :: is_open Function

type, public, extends(FileReader_t) ::  AttachedFileReader_t

A class for tokenized reading of lines, that can be attached to open file handles.

Read more…

Constructor

private function construct_AttachedFileReader_t (file_id, echo_lines, file_name, current_line)

Construct an AttachedFileReader_t

Read more…

Type-Bound Procedures

procedure , public :: close => my_close Subroutine
procedure , public :: nextline Function
procedure , public :: rewind => my_rewind Subroutine
procedure , public :: set_echo_lines Subroutine
procedure , public :: get_current_line Function
procedure , public :: get_file_name Function

type, public ::  TokenIterator_t

A class for looping over tokens parsed from semantic lines.

Read more…

Components

Type Visibility Attributes Name Initial
type(Token_t), public, allocatable :: tokens(:)
integer, private :: i_curr_token = 1
character(len=:), private, allocatable :: file_name

The name of file where the line came from (if available).

integer, private, allocatable :: current_line

The current line (if available).

Type-Bound Procedures

procedure , public :: size => size_TokenIterator_t Function
procedure , public :: remaining_items Function
procedure , public :: next Function
procedure , public :: glimpse Function
procedure , public :: reset Subroutine

Functions

public function construct_ManagingFileReader_t(file_name, echo_lines, err) result(res)

Construct a ManagingFileReader_t

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: file_name
integer, intent(in), optional :: echo_lines
integer, intent(out), optional :: err

Return Value type(ManagingFileReader_t)

private function construct_AttachedFileReader_t(file_id, echo_lines, file_name, current_line) result(res)

Construct an AttachedFileReader_t

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: file_id
integer, intent(in), optional :: echo_lines
character(len=*), intent(in), optional :: file_name
integer, intent(in), optional :: current_line

Return Value type(AttachedFileReader_t)

private elemental function is_open(this)

Return if a file is open.

Arguments

Type IntentOptional Attributes Name
class(ManagingFileReader_t), intent(in) :: this

Return Value logical

private function raw_nextline(this, line)

Return if the next line can be read and return it

Read more…

Arguments

Type IntentOptional Attributes Name
class(FileReader_t), intent(inout) :: this
character(len=:), intent(out), allocatable :: line

Return Value logical

private function nextline(this, tokenized_line, skip_empty) result(can_still_read)

Return if the next line can be read. It is written to the out-argument.

Read more…

Arguments

Type IntentOptional Attributes Name
class(FileReader_t), intent(inout) :: this
type(TokenIterator_t), intent(out) :: tokenized_line
logical, intent(in) :: skip_empty

Return Value logical

public function tokenize(line) result(res)

Tokenize a line.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: line

Return Value type(Token_t), allocatable, (:)

private elemental function remaining_items(this)

Return the number of remaining items in this Iterator.

Arguments

Type IntentOptional Attributes Name
class(TokenIterator_t), intent(in) :: this

Return Value integer

private elemental function size_TokenIterator_t(this)

Return the number of tokens in this Iterator.

Arguments

Type IntentOptional Attributes Name
class(TokenIterator_t), intent(in) :: this

Return Value integer

private function next(this, if_exhausted) result(res)

Return the next Token and increment the iterator.

Read more…

Arguments

Type IntentOptional Attributes Name
class(TokenIterator_t), intent(inout) :: this
character(len=*), intent(in), optional :: if_exhausted

Return Value character(len=:), allocatable

private function glimpse(this, if_exhausted) result(res)

Return the next Token.

Read more…

Arguments

Type IntentOptional Attributes Name
class(TokenIterator_t), intent(inout) :: this
character(len=*), intent(in), optional :: if_exhausted

Return Value character(len=:), allocatable

public pure function get_range(str_range) result(res)

Parse a string into a range of integers.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str_range

Return Value integer, allocatable, (:)

private pure function get_file_name(this) result(res)

Return the file name (if defined)

Arguments

Type IntentOptional Attributes Name
class(FileReader_t), intent(in) :: this

Return Value character(len=:), allocatable

private elemental function get_current_line(this) result(res)

Return the current line (if defined)

Read more…

Arguments

Type IntentOptional Attributes Name
class(FileReader_t), intent(in) :: this

Return Value integer


Subroutines

private impure elemental subroutine my_close(this, delete)

Close the file.

Arguments

Type IntentOptional Attributes Name
class(FileReader_t), intent(inout) :: this
logical, intent(in), optional :: delete

private subroutine my_rewind(this)

Rewind the file

Arguments

Type IntentOptional Attributes Name
class(FileReader_t), intent(inout) :: this

private subroutine set_echo_lines(this, echo_lines)

Set the unit where to echo lines.

Read more…

Arguments

Type IntentOptional Attributes Name
class(FileReader_t), intent(inout) :: this
integer, intent(in), optional :: echo_lines

private elemental subroutine reset(this, k)

Reset the iterator

Read more…

Arguments

Type IntentOptional Attributes Name
class(TokenIterator_t), intent(inout) :: this
integer, intent(in), optional :: k