TokenIterator_t Derived Type

type, public :: TokenIterator_t

A class for looping over tokens parsed from semantic lines.

Note that a semantic line may stretch over several “raw” lines, if line continuation is used.


Contents


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

  • 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

procedure, public :: remaining_items

  • 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

procedure, public :: next

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

    Return the next Token and increment the iterator.

    If the iterator is exhausted, this function throws an error unless the argument if_exhausted is present, which is then returned instead.

    To view the next Token without incrementing the iterator use glimpse.

    Arguments

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

    Return Value character(len=:), allocatable

procedure, public :: glimpse

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

    Return the next Token.

    If the iterator is exhausted, this function throws an error unless the argument if_exhausted is present, which is then returned instead.

    To view the next Token and incrementing the iterator use next.

    Arguments

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

    Return Value character(len=:), allocatable

procedure, public :: reset

  • private elemental subroutine reset(this, k)

    Reset the iterator

    If k is not present, the iterator is reset to the beginning. If k is present, it has to be smaller 0 and resets the iterator by this amount of steps. In particular call tokens%reset(-1) resets the iterator one element and allows to reread the previous element.

    Arguments

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