add Subroutine

private subroutine add(tokens, lx, src, kind, first, last, sub)

Append a token, maintaining the line count and the glue state for split tokens.

Arguments

Type IntentOptional Attributes Name
type(token_list_t), intent(inout) :: tokens

token list to append to

type(lexer_t), intent(inout) :: lx

lexer state

character(len=*), intent(in) :: src

source text

integer, intent(in) :: kind

token kind, one of the TK_* constants

integer, intent(in) :: first

first byte of the token in src

integer, intent(in) :: last

last byte of the token in src

integer, intent(in), optional :: sub

sub-kind (CM_, CT_, STR_*); 0 if absent


Calls

proc~~add~~CallsGraph proc~add add proc~is_blank is_blank proc~add->proc~is_blank proc~is_code_char is_code_char proc~add->proc~is_code_char proc~peek peek proc~add->proc~peek proc~push~2 token_list_t%push proc~add->proc~push~2 proc~is_code_char->proc~is_blank

Called by

proc~~add~~CalledByGraph proc~add add proc~tokenize tokenize proc~tokenize->proc~add proc~format_text format_text proc~format_text->proc~tokenize proc~convert_relational convert_relational proc~format_text->proc~convert_relational proc~format_pass format_pass proc~format_text->proc~format_pass proc~limit_diagnostics limit_diagnostics proc~format_text->proc~limit_diagnostics proc~long_code_lines long_code_lines proc~format_text->proc~long_code_lines proc~sort_use sort_use proc~format_text->proc~sort_use proc~split_long_lines split_long_lines proc~format_text->proc~split_long_lines proc~relayout relayout proc~format_text->proc~relayout proc~parse_source parse_source proc~parse_source->proc~tokenize proc~same_code same_code proc~same_code->proc~tokenize proc~code_signature code_signature proc~same_code->proc~code_signature proc~code_signature->proc~parse_source proc~convert_relational->proc~parse_source proc~format_pass->proc~parse_source proc~limit_diagnostics->proc~parse_source proc~long_code_lines->proc~parse_source proc~process_text process_text proc~process_text->proc~format_text proc~sort_use->proc~parse_source proc~split_long_lines->proc~parse_source proc~process_file process_file proc~process_file->proc~process_text proc~process_stdin process_stdin proc~process_stdin->proc~process_text proc~relayout->proc~format_pass proc~run run proc~run->proc~process_file proc~run->proc~process_stdin

Source Code

subroutine add(tokens, lx, src, kind, first, last, sub)
    !! Append a token, maintaining the line count and the glue state for split tokens.
    type(token_list_t), intent(inout) :: tokens   !! token list to append to
    type(lexer_t), intent(inout) :: lx            !! lexer state
    character(len=*), intent(in) :: src           !! source text
    integer, intent(in) :: kind                   !! token kind, one of the TK_* constants
    integer, intent(in) :: first                  !! first byte of the token in `src`
    integer, intent(in) :: last                   !! last byte of the token in `src`
    integer, intent(in), optional :: sub          !! sub-kind (CM_*, CT_*, STR_*); 0 if absent
    type(token_t) :: t
    integer :: k

    t%kind = kind
    t%first = first
    t%last = last
    t%line = lx%line
    if (present(sub)) t%sub = sub

    if (kind == TK_CONT) then
        if (t%sub == CT_TRAILING) then
            lx%glue_pending = first > 1 .and. .not. is_blank(peek(src, first - 1))
        else
            ! a leading `&` directly followed by code joins it to the end of the previous line
            lx%glue_next = lx%glue_pending .and. is_code_char(peek(src, last + 1))
            lx%glue_pending = .false.
        end if
    else if (is_code_kind(kind)) then
        t%glued = lx%glue_next
        lx%glue_next = .false.
        lx%glue_pending = .false.
    end if

    do k = first, last
        if (src(k:k) == LF) then
            lx%line = lx%line + 1
        else if (src(k:k) == CR .and. peek(src, k + 1) /= LF) then
            lx%line = lx%line + 1
        end if
    end do
    call tokens%push(t)
end subroutine add