stands_alone Function

private pure function stands_alone(source, k)

True if statement k of source, a code statement, can be laid out again on its own after one of its lines is split, giving what laying out the whole text would: it takes up whole lines (no ; before or after it on its lines, no byte order mark), has no statement label (which stays at the start of the line), and is not followed by a comment line that may be lined up with a comment at the end of its last line.

Arguments

Type IntentOptional Attributes Name
type(source_t), intent(in) :: source

the source

integer, intent(in) :: k

index into source%stmts

Return Value logical


Called by

proc~~stands_alone~~CalledByGraph proc~stands_alone stands_alone proc~split_long_lines split_long_lines proc~split_long_lines->proc~stands_alone proc~format_text format_text proc~format_text->proc~split_long_lines 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 logical function stands_alone(source, k)
    !! True if statement `k` of `source`, a code statement, can be laid out again on its own after
    !! one of its lines is split, giving what laying out the whole text would: it takes up whole
    !! lines (no `;` before or after it on its lines, no byte order mark), has no statement label
    !! (which stays at the start of the line), and is not followed by a comment line that may be
    !! lined up with a comment at the end of its last line.
    type(source_t), intent(in) :: source   !! the source
    integer, intent(in) :: k               !! index into `source%stmts`
    integer :: j, f

    stands_alone = .false.
    associate (s => source%stmts%s(k), tok => source%tokens%tok)
        if (s%first > 1) then
            if (tok(s%first - 1)%kind /= TK_NEWLINE) return
        end if
        if (tok(s%last)%kind /= TK_NEWLINE .and. s%last < source%tokens%n) return
        if (any(tok(s%first:s%last)%kind == TK_BOM)) return
        f = s%first
        do while (f < s%last .and. tok(f)%kind == TK_SPACE)
            f = f + 1
        end do
        if (tok(f)%kind == TK_INT) return                   ! a statement label
        if (k < source%stmts%n) then
            if (source%stmts%s(k + 1)%kind == SK_COMMENT) then
                ! a comment at the end of the last line, before its line break
                j = s%last
                if (tok(j)%kind == TK_NEWLINE) j = j - 1
                if (j >= s%first .and. tok(j)%kind == TK_COMMENT) return
            end if
        end if
    end associate
    stands_alone = .true.
end function stands_alone