convert_relational Function

public function convert_relational(src, style) result(out)

src with every relational operator written in style (REL_SYMBOLS or REL_LETTERS).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: src

source text

integer, intent(in) :: style

one of the REL_* constants; REL_KEEP returns src

Return Value character(len=:), allocatable


Calls

proc~~convert_relational~~CallsGraph proc~convert_relational convert_relational proc~builder_append string_builder_t%builder_append proc~convert_relational->proc~builder_append proc~builder_get string_builder_t%builder_get proc~convert_relational->proc~builder_get proc~is_chevron is_chevron proc~convert_relational->proc~is_chevron proc~parse_source parse_source proc~convert_relational->proc~parse_source proc~token_lower token_lower proc~convert_relational->proc~token_lower proc~token_text token_text proc~convert_relational->proc~token_text proc~protected_items protected_items proc~parse_source->proc~protected_items proc~split_statements split_statements proc~parse_source->proc~split_statements proc~tokenize tokenize proc~parse_source->proc~tokenize proc~make_lowercase make_lowercase proc~token_lower->proc~make_lowercase proc~directive directive proc~protected_items->proc~directive proc~ends_with_continuation ends_with_continuation proc~split_statements->proc~ends_with_continuation proc~find_semicolon find_semicolon proc~split_statements->proc~find_semicolon proc~line_end_token line_end_token proc~split_statements->proc~line_end_token proc~line_kind line_kind proc~split_statements->proc~line_kind proc~push statement_list_t%push proc~split_statements->proc~push proc~add add proc~tokenize->proc~add proc~comment_kind comment_kind proc~tokenize->proc~comment_kind proc~dotop_at dotop_at proc~tokenize->proc~dotop_at proc~dotop_end dotop_end proc~tokenize->proc~dotop_end proc~fypp_inline_end fypp_inline_end proc~tokenize->proc~fypp_inline_end proc~is_blank is_blank proc~tokenize->proc~is_blank proc~is_digit is_digit proc~tokenize->proc~is_digit proc~is_preproc_start is_preproc_start proc~tokenize->proc~is_preproc_start proc~is_quote is_quote proc~tokenize->proc~is_quote proc~lex_number lex_number proc~tokenize->proc~lex_number proc~line_end line_end proc~tokenize->proc~line_end proc~name_end name_end proc~tokenize->proc~name_end proc~operator_end operator_end proc~tokenize->proc~operator_end proc~peek peek proc~tokenize->proc~peek proc~preproc_end preproc_end proc~tokenize->proc~preproc_end proc~string_end string_end proc~tokenize->proc~string_end proc~add->proc~is_blank proc~add->proc~peek proc~is_code_char is_code_char proc~add->proc~is_code_char proc~push~2 token_list_t%push proc~add->proc~push~2 proc~comment_kind->proc~peek proc~is_letter is_letter proc~comment_kind->proc~is_letter proc~lowercase lowercase proc~comment_kind->proc~lowercase proc~directive->proc~token_text proc~dotop_at->proc~peek proc~dotop_at->proc~is_letter proc~dotop_end->proc~name_end proc~dotop_end->proc~peek proc~is_name_char is_name_char proc~dotop_end->proc~is_name_char proc~dotop_end->proc~lowercase proc~fypp_inline_end->proc~peek proc~is_preproc_start->proc~peek proc~lex_number->proc~dotop_at proc~lex_number->proc~is_digit proc~lex_number->proc~name_end proc~lex_number->proc~peek proc~digits_end digits_end proc~lex_number->proc~digits_end proc~lex_number->proc~is_name_char proc~lower_char lower_char proc~lex_number->proc~lower_char proc~name_end->proc~peek proc~name_end->proc~is_name_char proc~preproc_end->proc~line_end proc~preproc_end->proc~peek proc~last_nonblank last_nonblank proc~preproc_end->proc~last_nonblank proc~string_end->proc~is_blank proc~string_end->proc~line_end proc~string_end->proc~peek proc~only_blanks_to_eol only_blanks_to_eol proc~string_end->proc~only_blanks_to_eol proc~digits_end->proc~is_digit proc~digits_end->proc~peek proc~is_code_char->proc~is_blank proc~is_name_char->proc~is_digit proc~is_name_char->proc~is_letter proc~last_nonblank->proc~is_blank proc~lowercase->proc~lower_char proc~only_blanks_to_eol->proc~line_end proc~only_blanks_to_eol->proc~last_nonblank

Called by

proc~~convert_relational~~CalledByGraph proc~convert_relational convert_relational proc~format_text format_text proc~format_text->proc~convert_relational proc~process_text process_text proc~process_text->proc~format_text proc~process_file process_file proc~process_file->proc~process_text proc~process_stdin process_stdin proc~process_stdin->proc~process_text proc~run run proc~run->proc~process_file proc~run->proc~process_stdin

Source Code

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