statement_view_t Derived Type

type, public :: statement_view_t

The code tokens of one statement, with their lowercase text and bracket depth: what the rules that read a statement word by word need. The procedures take an index j into code(:); outside 1:n a word is '' and its kind 0, so a rule can look before and after a token without checking the bounds.


Components

Type Visibility Attributes Name Initial
integer, public, allocatable :: code(:)

indices into the token list of the code tokens (see code_tokens)

integer, public, allocatable :: depth(:)

open ( and [ around each code token; a bracket is outside its own pair

integer, public :: first = 1

first code token after a statement label (10 continue)

integer, public, allocatable :: hi(:)

where it ends

integer, public, allocatable :: kinds(:)

kind of each code token (TK_*)

integer, public, allocatable :: lo(:)

where the text of each code token starts in low

character(len=:), public, allocatable :: low

lowercase text of the code tokens, one after another

integer, public :: n = 0

number of code tokens


Type-Bound Procedures

procedure, public :: closing => view_closing

the ) that closes a (

  • private pure function view_closing(v, j) result(c)

    Index of the ) that closes the ( at code token j (counting only parentheses), or 0 if token j is not ( or it is not closed.

    Arguments

    Type IntentOptional Attributes Name
    class(statement_view_t), intent(in) :: v

    the statement

    integer, intent(in) :: j

    index into v%code(:)

    Return Value integer

procedure, public :: is => view_is

whether a code token's lowercase text is a given one

  • private pure function view_is(v, j, text)

    True if the lowercase text of code token j is text, without making a copy of it. Outside the statement only '' matches.

    Arguments

    Type IntentOptional Attributes Name
    class(statement_view_t), intent(in) :: v

    the statement

    integer, intent(in) :: j

    index into v%code(:)

    character(len=*), intent(in) :: text

    the text, in lowercase

    Return Value logical

procedure, public :: kind_of => view_kind_of

kind of a code token

  • private pure function view_kind_of(v, j) result(kind)

    Kind (TK_*) of code token j, or 0 outside the statement.

    Arguments

    Type IntentOptional Attributes Name
    class(statement_view_t), intent(in) :: v

    the statement

    integer, intent(in) :: j

    index into v%code(:)

    Return Value integer

procedure, public :: word => view_word

lowercase text of a code token

  • private pure function view_word(v, j) result(w)

    Lowercase text of code token j, or '' outside the statement.

    Arguments

    Type IntentOptional Attributes Name
    class(statement_view_t), intent(in) :: v

    the statement

    integer, intent(in) :: j

    index into v%code(:)

    Return Value character(len=:), allocatable

Source Code

type, public :: statement_view_t
    !! The code tokens of one statement, with their lowercase text and bracket depth: what the rules
    !! that read a statement word by word need. The procedures take an index `j` into `code(:)`;
    !! outside `1:n` a word is `''` and its kind 0, so a rule can look before and after a token
    !! without checking the bounds.
    integer, allocatable :: code(:)         !! indices into the token list of the code tokens
                                            !! (see [[code_tokens]])
    integer :: n = 0                        !! number of code tokens
    integer :: first = 1                    !! first code token after a statement label (`10 continue`)
    integer, allocatable :: kinds(:)        !! kind of each code token (`TK_*`)
    integer, allocatable :: depth(:)        !! open `(` and `[` around each code token; a bracket is
                                            !! outside its own pair
    character(len=:), allocatable :: low    !! lowercase text of the code tokens, one after another
    integer, allocatable :: lo(:)           !! where the text of each code token starts in `low`
    integer, allocatable :: hi(:)           !! where it ends
contains
    procedure :: word => view_word          !! lowercase text of a code token
    procedure :: is => view_is              !! whether a code token's lowercase text is a given one
    procedure :: kind_of => view_kind_of    !! kind of a code token
    procedure :: closing => view_closing    !! the `)` that closes a `(`
end type statement_view_t