first_piece_width Function

private function first_piece_width(w, src, tokens, first, lend) result(width)

Width of tokens first:lend up to the end of the first code token that has another code token after it on the line (the shortest first part of a split), or a huge value if there is none.

Arguments

Type IntentOptional Attributes Name
type(writer_t), intent(in) :: w

the output and the alignment state

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

the source text

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

its tokens

integer, intent(in) :: first

first token of the part of the line to measure

integer, intent(in) :: lend

last token of the line, its line break if it has one

Return Value integer


Calls

proc~~first_piece_width~~CallsGraph proc~first_piece_width first_piece_width proc~line_pieces line_pieces proc~first_piece_width->proc~line_pieces proc~utf8_width utf8_width proc~first_piece_width->proc~utf8_width

Called by

proc~~first_piece_width~~CalledByGraph proc~first_piece_width first_piece_width proc~fitting_column fitting_column proc~fitting_column->proc~first_piece_width proc~comment_column comment_column proc~comment_column->proc~fitting_column proc~emit_continuation emit_continuation proc~emit_continuation->proc~fitting_column proc~emit_statement emit_statement proc~emit_statement->proc~fitting_column proc~emit_statement->proc~comment_column proc~emit_statement->proc~emit_continuation proc~emit_comment_line emit_comment_line proc~emit_comment_line->proc~comment_column proc~layout layout proc~layout->proc~emit_statement proc~layout->proc~emit_comment_line proc~format_pass format_pass proc~format_pass->proc~layout 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

integer function first_piece_width(w, src, tokens, first, lend) result(width)
    !! Width of tokens `first:lend` up to the end of the first code token that has another code token
    !! after it on the line (the shortest first part of a split), or a huge value if there is none.
    type(writer_t), intent(in) :: w            !! the output and the alignment state
    character(len=*), intent(in) :: src        !! the source text
    type(token_list_t), intent(in) :: tokens   !! its tokens
    integer, intent(in) :: first               !! first token of the part of the line to measure
    integer, intent(in) :: lend                !! last token of the line, its line break if it has one
    type(piece_t), allocatable :: pieces(:)
    integer :: k, m, total

    width = huge(1)/2
    call line_pieces(w, src, tokens, first, lend, pieces)
    total = 0
    do k = 1, size(pieces)
        associate (text => src(pieces(k)%first:pieces(k)%last))
            if (pieces(k)%blanks > 0) then
                total = total + pieces(k)%blanks
            else
                if (scan(text, achar(10)//achar(13)) > 0) return
                total = total + utf8_width(text)
            end if
        end associate
        if (pieces(k)%tok == 0) cycle
        if (.not. is_code_kind(tokens%tok(pieces(k)%tok)%kind)) cycle
        if (pieces(k)%tok == first .and. tokens%tok(first)%kind == TK_INT) cycle   ! a statement label
        do m = k + 1, size(pieces)
            if (pieces(m)%tok == 0) cycle
            if (is_code_kind(tokens%tok(pieces(m)%tok)%kind) .and. .not. tokens%tok(pieces(m)%tok)%glued) then
                width = total
                return
            end if
            exit
        end do
    end do
end function first_piece_width