Append a token, maintaining the line count and the glue state for split tokens.
| Type | Intent | Optional | 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 |
||
| integer, | intent(in) | :: | last |
last byte of the token in |
||
| integer, | intent(in), | optional | :: | sub |
sub-kind (CM_, CT_, STR_*); 0 if absent |
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