src with every relational operator written in style (REL_SYMBOLS or REL_LETTERS).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| integer, | intent(in) | :: | style |
one of the REL_* constants; |
function convert_relational(src, style) result(out) !! `src` with every relational operator written in `style` (`REL_SYMBOLS` or `REL_LETTERS`). character(len=*), intent(in) :: src !! source text integer, intent(in) :: style !! one of the REL_* constants; `REL_KEEP` returns `src` character(len=:), allocatable :: out type(source_t) :: source type(string_builder_t) :: buf integer :: k, j, r if (style == REL_KEEP) then out = src return end if call parse_source(src, source) do k = 1, source%stmts%n do j = source%stmts%s(k)%first, source%stmts%s(k)%last r = 0 if (.not. source%keep(k) .and. source%stmts%s(k)%kind == SK_CODE) r = operator_index(j) if (r == 0) then call buf%append(token_text(src, source%tokens%tok(j))) else if (style == REL_SYMBOLS) then call buf%append(trim(SYMBOLS(r))) else call buf%append(trim(LETTERS(r))) end if end do end do out = buf%get() contains integer function operator_index(j) !! Index of token `j` in the operator tables, or 0 if it is not a relational operator. integer, intent(in) :: j !! index into the token list character(len=:), allocatable :: t operator_index = 0 if (source%tokens%tok(j)%kind /= TK_OP .and. source%tokens%tok(j)%kind /= TK_DOTOP) return t = token_lower(src, source%tokens%tok(j)) if (source%tokens%tok(j)%kind == TK_OP) then operator_index = findloc(SYMBOLS, t, dim=1) if (is_chevron(src, source%tokens, j)) operator_index = 0 else operator_index = findloc(LETTERS, t, dim=1) end if end function operator_index end function convert_relational