True if code token s of sa matches code token t of sb, as their keys in
code_signature would: same kind (operators all alike), same glue, and the same text,
ignoring case where Fortran does (see folded_length), with relational operators in their
symbol spelling.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | sa |
source text of |
||
| type(token_t), | intent(in) | :: | s |
a code token of |
||
| character(len=*), | intent(in) | :: | sb |
source text of |
||
| type(token_t), | intent(in) | :: | t |
a code token of |
pure logical function same_token(sa, s, sb, t) !! True if code token `s` of `sa` matches code token `t` of `sb`, as their keys in !! [[code_signature]] would: same kind (operators all alike), same glue, and the same text, !! ignoring case where Fortran does (see [[folded_length]]), with relational operators in their !! symbol spelling. character(len=*), intent(in) :: sa !! source text of `s` character(len=*), intent(in) :: sb !! source text of `t` type(token_t), intent(in) :: s !! a code token of `sa` type(token_t), intent(in) :: t !! a code token of `sb` integer :: ks, kt, k, nfold character(len=:), allocatable :: ca, cb ks = s%kind kt = t%kind if (ks == TK_DOTOP) ks = TK_OP if (kt == TK_DOTOP) kt = TK_OP same_token = .false. if (ks /= kt .or. (s%glued .neqv. t%glued)) return if (s%last - s%first == t%last - t%first) then nfold = folded_length(sa(s%first:s%last), s%kind) same_token = .true. do k = 0, s%last - s%first if (k < nfold) then if (lower_char(sa(s%first + k:s%first + k)) == lower_char(sb(t%first + k:t%first + k))) cycle else if (sa(s%first + k:s%first + k) == sb(t%first + k:t%first + k)) cycle end if same_token = .false. exit end do if (same_token) return end if ! `.lt.` and `<`: rare, so the allocating comparison is fine here if (ks == TK_OP) then ca = canonical_relational(token_lower(sa, s)) cb = canonical_relational(token_lower(sb, t)) same_token = len(ca) == len(cb) .and. ca == cb end if end function same_token