A comment line, re-indented to ind. A comment that lines up with the comment on the line
above (a continued trailing comment) stays lined up with it. Comment lines directly after a
statement that are indented more than it keep their extra indentation. With keep_column1_comments, a
comment that starts in column 1 stays there.
| Type | Intent | Optional | 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 |
||
| type(statement_t), | intent(in) | :: | s |
the comment line item |
||
| integer, | intent(in) | :: | ind |
indentation of the code around it, in blanks |
||
| type(format_options_t), | intent(in) | :: | opts |
the formatting options |
subroutine emit_comment_line(w, src, tokens, s, ind, opts) !! A comment line, re-indented to `ind`. A comment that lines up with the comment on the line !! above (a continued trailing comment) stays lined up with it. Comment lines directly after a !! statement that are indented more than it keep their extra indentation. With `keep_column1_comments`, a !! comment that starts in column 1 stays there. 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 type(statement_t), intent(in) :: s !! the comment line item integer, intent(in) :: ind !! indentation of the code around it, in blanks type(format_options_t), intent(in) :: opts !! the formatting options integer :: j, col if (.not. opts%indent_comments) then call emit_range(w, src, tokens, s%first, s%last) w%comment_in = -1 return end if do j = s%first, s%last select case (tokens%tok(j)%kind) case (TK_BOM, TK_NEWLINE) call put(w, token_text(src, tokens%tok(j))) case (TK_COMMENT) if (opts%keep_column1_comments .and. input_column(src, tokens%tok(j)) == 0) then col = 0 ! a comment in column 1 stays there w%comment_in = -1 else col = ind ! comments directly after a statement and indented deeper than it (such as FORD ! `!!` documentation) keep their extra indentation if (w%stmt_in >= 0) col = max(ind, w%stmt_out + input_column(src, tokens%tok(j)) - w%stmt_in) col = comment_column(w, src, tokens, j, col) end if call put(w, repeat(' ', col)) call put(w, trim_blanks(token_text(src, tokens%tok(j)))) end select end do end subroutine emit_comment_line