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 | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(source_t), | intent(in) | :: | source |
the source |
||
| integer, | intent(in) | :: | k |
index into |
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