The token after which to split tokens a:lend of a line that starts at token a in column
start_col, or 0 if the code fits or cannot be split.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(token_list_t), | intent(in) | :: | tokens |
the tokens of |
||
| character(len=*), | intent(in) | :: | src |
the source text |
||
| integer, | intent(in) | :: | a |
first token of the line |
||
| integer, | intent(in) | :: | lend |
last token of the line, its line break if it has one |
||
| integer, | intent(in) | :: | start_col |
column of token |
||
| integer, | intent(in) | :: | line_length |
maximum line width, in characters |
integer function break_point(tokens, src, a, lend, start_col, line_length) result(best) !! The token after which to split tokens `a:lend` of a line that starts at token `a` in column !! `start_col`, or 0 if the code fits or cannot be split. type(token_list_t), intent(in) :: tokens !! the tokens of `src` character(len=*), intent(in) :: src !! the source text integer, intent(in) :: a !! first token of the line integer, intent(in) :: lend !! last token of the line, its line break if it has one integer, intent(in) :: start_col !! column of token `a` integer, intent(in) :: line_length !! maximum line width, in characters integer :: t, cend, p, q, prio, best_prio, end_col best = 0 cend = 0 do t = a, lend if (scan(token_text(src, tokens%tok(t)), achar(10)//achar(13)) > 0 .and. tokens%tok(t)%kind /= TK_NEWLINE) & return ! a token continued on the next line if (tokens%tok(t)%kind == TK_COMMENT) exit if (is_code_kind(tokens%tok(t)%kind) .or. tokens%tok(t)%kind == TK_CONT) cend = t end do if (cend == 0) return if (end_column(cend) <= line_length) return best_prio = huge(1) do p = a, cend - 1 if (.not. is_code_kind(tokens%tok(p)%kind)) cycle if (p == a .and. tokens%tok(p)%kind == TK_INT) cycle ! a statement label q = p + 1 do while (q <= cend) if (tokens%tok(q)%kind /= TK_SPACE) exit q = q + 1 end do if (q > cend) cycle if (.not. is_code_kind(tokens%tok(q)%kind) .or. tokens%tok(q)%glued) cycle end_col = end_column(p) if (end_col + 2 > line_length) exit ! ` &` would not fit prio = priority(token_lower(src, tokens%tok(p)), tokens%tok(p)%kind) if (prio <= best_prio) then best_prio = prio best = p end if end do contains integer function end_column(t) !! Column just after token `t`, for a line starting at token `a` in column `start_col`. integer, intent(in) :: t !! index into the token list end_column = start_col + utf8_width(src(tokens%tok(a)%first:tokens%tok(t)%last)) end function end_column end function break_point