emit_continuation Subroutine

private subroutine emit_continuation(w, src, tokens, f, lend, aligned, indented)

A continuation line whose first non-blank token is f, with its code starting at the column aligned, or at indented or its original column if that would make the line too long.

Arguments

Type IntentOptional Attributes Name
type(writer_t), intent(inout) :: 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) :: f

first non-blank token of the line

integer, intent(in) :: lend

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

integer, intent(in) :: aligned

preferred column for the code (see continuation_target)

integer, intent(in) :: indented

column for the code with a fixed continuation indent


Calls

proc~~emit_continuation~~CallsGraph proc~emit_continuation emit_continuation proc~emit_body emit_body proc~emit_continuation->proc~emit_body proc~first_non_blank first_non_blank proc~emit_continuation->proc~first_non_blank proc~fitting_column fitting_column proc~emit_continuation->proc~fitting_column proc~input_column input_column proc~emit_continuation->proc~input_column proc~put put proc~emit_continuation->proc~put proc~emit_body->proc~input_column proc~emit_body->proc~put proc~kind_part kind_part proc~emit_body->proc~kind_part proc~line_pieces line_pieces proc~emit_body->proc~line_pieces proc~to_case to_case proc~emit_body->proc~to_case proc~token_lower token_lower proc~emit_body->proc~token_lower proc~first_piece_width first_piece_width proc~fitting_column->proc~first_piece_width proc~line_width line_width proc~fitting_column->proc~line_width proc~utf8_width utf8_width proc~input_column->proc~utf8_width proc~builder_append string_builder_t%builder_append proc~put->proc~builder_append proc~put->proc~utf8_width proc~first_piece_width->proc~line_pieces proc~first_piece_width->proc~utf8_width proc~line_width->proc~line_pieces proc~line_width->proc~utf8_width proc~make_lowercase make_lowercase proc~token_lower->proc~make_lowercase

Called by

proc~~emit_continuation~~CalledByGraph proc~emit_continuation emit_continuation proc~emit_statement emit_statement proc~emit_statement->proc~emit_continuation proc~layout layout proc~layout->proc~emit_statement 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

subroutine emit_continuation(w, src, tokens, f, lend, aligned, indented)
    !! A continuation line whose first non-blank token is `f`, with its code starting at the column
    !! `aligned`, or at `indented` or its original column if that would make the line too long.
    type(writer_t), intent(inout) :: 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) :: f                   !! first non-blank token of the line
    integer, intent(in) :: lend                !! last token of the line, its line break if it has one
    integer, intent(in) :: aligned             !! preferred column for the code (see [[continuation_target]])
    integer, intent(in) :: indented            !! column for the code with a fixed continuation indent
    integer :: g, target, orig

    if (tokens%tok(f)%kind /= TK_CONT) then
        target = fitting_column(w, src, tokens, f, lend, [aligned, indented, input_column(src, tokens%tok(f))])
        call put(w, repeat(' ', target))
        call emit_body(w, src, tokens, f, lend)
        return
    end if
    ! a leading `&`, placed so that the code after it starts at the target column
    orig = input_column(src, tokens%tok(f))
    g = f + 1
    if (g <= lend) then
        if (is_code_kind(tokens%tok(g)%kind)) then
            ! `&code`: keep them together
            target = fitting_column(w, src, tokens, f, lend, [aligned - 1, indented - 1, orig], g, 1)
            call put(w, repeat(' ', target)//'&')
            call emit_body(w, src, tokens, g, lend)
            return
        end if
    end if
    g = first_non_blank(tokens, g, lend)
    target = fitting_column(w, src, tokens, f, lend, [aligned - 2, indented - 2, orig], g, 2)
    call put(w, repeat(' ', target)//'&')
    if (g <= lend) then
        if (tokens%tok(g)%kind /= TK_NEWLINE) call put(w, ' ')
    end if
    call emit_body(w, src, tokens, g, lend)
end subroutine emit_continuation