detokenize Function

public function detokenize(src, tokens) result(text)

Join the text of all tokens.

Arguments

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

the source the tokens were read from

type(token_list_t), intent(in) :: tokens

tokens of src

Return Value character(len=:), allocatable


Source Code

function detokenize(src, tokens) result(text)
    !! Join the text of all tokens.
    character(len=*), intent(in) :: src          !! the source the tokens were read from
    type(token_list_t), intent(in) :: tokens     !! tokens of `src`
    character(len=:), allocatable :: text
    integer :: k, n, total

    total = 0
    do k = 1, tokens%n
        total = total + tokens%tok(k)%last - tokens%tok(k)%first + 1
    end do
    allocate (character(len=total) :: text)
    n = 0
    do k = 1, tokens%n
        associate (t => tokens%tok(k))
            text(n + 1:n + t%last - t%first + 1) = src(t%first:t%last)
            n = n + t%last - t%first + 1
        end associate
    end do
end function detokenize