expand_keyword Function

private pure function expand_keyword(w) result(parts)

Split a keyword that may be written as one word (endif, elseif, selectcase, endblockdata, ...) into its parts. Other words are returned unchanged.

Arguments

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

the word, in lowercase

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


Called by

proc~~expand_keyword~~CalledByGraph proc~expand_keyword expand_keyword proc~classify_statement classify_statement proc~classify_statement->proc~expand_keyword proc~analyze_structure analyze_structure proc~analyze_structure->proc~classify_statement proc~format_pass format_pass proc~format_pass->proc~analyze_structure proc~format_text format_text proc~format_text->proc~format_pass proc~relayout relayout proc~format_text->proc~relayout proc~relayout->proc~format_pass proc~process_text process_text proc~process_text->proc~format_text proc~process_file process_file proc~process_file->proc~process_text proc~process_stdin process_stdin proc~process_stdin->proc~process_text proc~run run proc~run->proc~process_file proc~run->proc~process_stdin

Source Code

pure function expand_keyword(w) result(parts)
    !! Split a keyword that may be written as one word (`endif`, `elseif`, `selectcase`,
    !! `endblockdata`, ...) into its parts. Other words are returned unchanged.
    character(len=*), intent(in) :: w   !! the word, in lowercase
    type(string_t), allocatable :: parts(:)
    character(len=*), parameter :: ends(*) = [character(len=11) :: &
                                              'associate', 'blockdata', 'block', 'critical', 'do', 'enum', 'forall', 'function', &
                                              'if', &
                                              'interface', 'module', 'procedure', 'program', 'select', 'submodule', 'subroutine', &
                                              'team', &
                                              'type', 'where']
    integer :: k

    if (len(w) > 3 .and. w(1:min(3, len(w))) == 'end') then
        do k = 1, size(ends)
            if (w(4:) == trim(ends(k))) then
                if (w(4:) == 'blockdata') then
                    parts = [string_t('end'), string_t('block'), string_t('data')]
                else
                    parts = [string_t('end'), string_t(w(4:))]
                end if
                return
            end if
        end do
    end if
    select case (w)
    case ('elseif')
        parts = [string_t('else'), string_t('if')]
    case ('elsewhere')
        parts = [string_t('else'), string_t('where')]
    case ('selectcase')
        parts = [string_t('select'), string_t('case')]
    case ('selecttype')
        parts = [string_t('select'), string_t('type')]
    case ('selectrank')
        parts = [string_t('select'), string_t('rank')]
    case ('blockdata')
        parts = [string_t('block'), string_t('data')]
    case ('changeteam')
        parts = [string_t('change'), string_t('team')]
    case ('doubleprecision')
        parts = [string_t('double'), string_t('precision')]
    case default
        parts = [string_t(w)]
    end select
end function expand_keyword