Positions in v%code where the items of a use statement's only: list start. Each item
ends before the comma in front of the next one, the last at the end of the statement. Empty
if there is no only: list, the list is empty, or it has an empty item.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(statement_view_t), | intent(in) | :: | v |
the |
function only_items(v) result(starts) !! Positions in `v%code` where the items of a `use` statement's `only:` list start. Each item !! ends before the comma in front of the next one, the last at the end of the statement. Empty !! if there is no `only:` list, the list is empty, or it has an empty item. type(statement_view_t), intent(in) :: v !! the `use` statement integer, allocatable :: starts(:) integer :: p, q, n, depth allocate (starts(0)) n = v%n do p = 3, n - 1 if (is_op(p - 1, ',') .and. is_op(p + 1, ':') .and. v%is(p, 'only')) exit end do if (p >= n .or. p + 2 > n) return starts = [p + 2] depth = 0 do q = p + 2, n if (v%kinds(q) /= TK_OP) cycle if (v%is(q, '(') .or. v%is(q, '[')) then depth = depth + 1 else if (v%is(q, ')') .or. v%is(q, ']')) then depth = depth - 1 else if (v%is(q, ',') .and. depth == 0) then if (q == n .or. q == starts(size(starts))) then ! an empty item deallocate (starts) allocate (starts(0)) return end if starts = [starts, q + 1] end if end do contains logical function is_op(j, text) !! True if code token `j` is the operator `text`. integer, intent(in) :: j !! index into `v%code(:)` character(len=*), intent(in) :: text !! the operator, e.g. `,` is_op = v%kinds(j) == TK_OP .and. v%is(j, text) end function is_op end function only_items