Writes the formatted text of a tokenized file: statements indented by their nesting depth, continuation lines aligned or indented by a fixed amount, comment lines indented like the code around them, and within each line the blanks and letter case that compute_gaps and compute_case ask for. Trailing blanks are removed.
Items protected by formatter directives (see ffmt_directives) are written as they are.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | parameter | :: | ANCHOR_ASSIGN | = | 1 | |
| integer, | private, | parameter | :: | ANCHOR_DECL | = | 3 | |
| integer, | private, | parameter | :: | ANCHOR_ONLY | = | 2 |
A piece of an output line: a token, or the blanks before one. Its text is src(first:last)
(with the token's letter case applied), or blanks blanks if that is positive; it is not
copied, so that measuring a line allocates nothing.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | blanks | = | 0 |
if positive, the piece is this many blanks instead |
|
| integer, | public | :: | first | = | 1 |
first byte of the text in the source |
|
| integer, | public | :: | last | = | 0 |
last byte of the text in the source |
|
| integer, | public | :: | tok | = | 0 |
token index, or 0 for blanks |
Output being built, and the alignment state of the current statement.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | anchor_col(3) | = | -1 |
column of the first item after an assignment |
|
| integer, | public, | allocatable | :: | bracket_first(:) |
column of the first item after each open bracket, or -1;
only |
||
| type(string_builder_t), | public | :: | buf |
the output text |
|||
| type(case_marks_t), | public | :: | cases |
letter case wanted for each token (see compute_case) |
|||
| integer, | public | :: | col | = | 0 |
output column: characters since the last line break |
|
| integer, | public | :: | comment_in | = | -1 |
input column of the comment on the previous line, or -1 |
|
| integer, | public | :: | comment_out | = | -1 |
output column of that comment |
|
| logical, | public | :: | declaration | = | .false. |
a top-level |
|
| integer, | public, | allocatable | :: | gap(:) |
blanks wanted before each token (see compute_gaps) |
||
| logical, | public | :: | generic | = | .false. |
the current statement is a |
|
| logical, | public | :: | keep_original | = | .true. |
fall back to a code line's original indentation when the new one would make it too long (when lines are not split) |
|
| logical, | public | :: | line_comment | = | .false. |
a comment has been written on the current line |
|
| integer, | public | :: | line_length | = | 0 |
maximum line length, or 0 |
|
| integer, | public, | allocatable | :: | long_lines(:) |
input lines that kept their indentation to stay within the line length |
||
| integer, | public | :: | nbrackets | = | 0 |
open brackets in the current statement |
|
| integer, | public | :: | pending_anchor | = | 0 |
the next code token is the first item after this anchor |
|
| logical, | public | :: | pending_bracket | = | .false. |
the next code token is the first item after a bracket |
|
| integer, | public | :: | prev | = | 0 |
the previous code token of the statement (index into the token list), or 0 |
|
| logical, | public | :: | separated | = | .false. |
a top-level |
|
| integer, | public | :: | stmt_in | = | -1 |
input column of the last statement, while comment lines directly follow it, or -1 |
|
| integer, | public | :: | stmt_out | = | -1 |
output column of that statement |
Output column for the comment-only line with comment token j: lined up with the comment on
the line above if it was lined up with it in the input, otherwise default. Records the
comment for the next line.
| 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 |
||
| integer, | intent(in) | :: | j |
the comment token |
||
| integer, | intent(in) | :: | default |
column to use if it is not lined up with the comment above |
Column for the code of a continuation line: the first item after the innermost open
bracket; outside brackets, the first item after an assignment, a use statement's only:
or a declaration's ::; otherwise a fixed indent.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(writer_t), | intent(in) | :: | w |
the output and the alignment state |
||
| integer, | intent(in) | :: | ind |
indentation of the statement, in blanks |
||
| type(format_options_t), | intent(in) | :: | opts |
the formatting options |
First token in first:last that is not a blank, or last + 1.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(token_list_t), | intent(in) | :: | tokens |
the token list |
||
| integer, | intent(in) | :: | first |
the token range to search |
||
| integer, | intent(in) | :: | last |
the token range to search |
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 | Intent | Optional | 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 |
The first of the candidates columns at which the output line fits within the line length, or
the smallest if none fits. The last candidate is the line's original column: if only that one
fits, the line is recorded in long_lines. When lines are split (w%keep_original false), the
original column is not a candidate for code, since splitting will make the line fit; it is
still used if always_original is true (for comments, which are not split). Also when lines are
split, a candidate other than the last is accepted if the line can be split to fit there: if
its first piece up to a possible break fits.
| 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 |
||
| integer, | intent(in) | :: | f |
first non-blank token of the input line |
||
| integer, | intent(in) | :: | lend |
last token of the line, its line break if it has one |
||
| integer, | intent(in) | :: | candidates(:) |
columns to try, best first; negative ones are skipped |
||
| integer, | intent(in), | optional | :: | from |
first token written after the prefix; requires |
|
| integer, | intent(in), | optional | :: | prefix |
width of the text written before token |
|
| logical, | intent(in), | optional | :: | always_original |
try the original column even when lines are split |
Column of token t in the input (characters before it on its line).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
the source text |
||
| type(token_t), | intent(in) | :: | t |
a token of |
The formatted text of source, from its structure (analyze_structure), the gaps
(compute_gaps) and the letter case (compute_case) wanted.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(source_t), | intent(in) | :: | source |
the source |
||
| type(structure_t), | intent(in) | :: | st |
its block structure |
||
| integer, | intent(in) | :: | gap(:) |
blanks wanted before each token |
||
| type(case_marks_t), | intent(in) | :: | cases |
letter case wanted for each token |
||
| type(format_options_t), | intent(in) | :: | opts |
the formatting options |
||
| integer, | intent(out), | optional, | allocatable | :: | long_lines(:) |
input lines that kept their indentation
because the new one would make them longer
than |
Width of tokens first:lend as they will be written on one line, without the line break and
without a trailing comment (compilers only limit the length of the code). A comment on a line
of its own counts.
| Type | Intent | Optional | 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 |
text in ASCII upper or lower case.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | text |
the text to convert |
||
| logical, | intent(in) | :: | upper |
true for upper case, false for lower case |
text without trailing blanks and tabs.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | text |
the text to trim |
A blank line: only its line break (and a byte order mark) is kept.
| 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 blank line item |
Tokens first:lend of a line (see line_pieces), while tracking open brackets and the
anchors for aligning continuation lines.
| 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 |
||
| integer, | intent(in) | :: | first |
first token to write |
||
| integer, | intent(in) | :: | lend |
last token of the line, its line break if it has one |
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 |
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 | 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 |
||
| 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 |
A preprocessor line: a fypp directive (#:, #!, $:, @:) is indented by ind; a cpp line
is written as it is. Continuation lines of the directive are not changed.
| 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 line, a preprocessor item |
||
| integer, | intent(in) | :: | ind |
indentation, in blanks |
Append tokens unchanged.
| 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 |
||
| integer, | intent(in) | :: | first |
the tokens |
||
| integer, | intent(in) | :: | last |
the tokens |
A code statement, with its continuation lines and the comment, blank and preprocessor lines
between them. The first line is indented to ind; a statement label stays at the start of
the line.
| 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 code statement |
||
| logical, | intent(in) | :: | labeled |
the statement has a statement label |
||
| integer, | intent(in) | :: | ind |
indentation of the statement, in blanks |
||
| type(format_options_t), | intent(in) | :: | opts |
the formatting options |
The pieces of output for tokens first:lend of a line: the tokens, with the blanks between them
adjusted by the whitespace rules and trailing blanks removed.
| Type | Intent | Optional | 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 |
||
| integer, | intent(in) | :: | lend |
last token of the line, its line break if it has one |
||
| type(piece_t), | intent(out), | allocatable | :: | pieces(:) |
the pieces, in order |