subroutinesubscriptprivate
subroutine subscript(c, a, index, v)
Item index of a, counting from 0, and from the end if negative.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| a | type(value_t) | in | the value | |
| index | integer | in | the index | |
| v | type(value_t) | out | the item |
Calls
Source
Show the code
subroutine subscript(c, a, index, v)
type(fypp_t), intent(inout) :: c !! the state
type(value_t), intent(in) :: a !! the value
integer, intent(in) :: index !! the index
type(value_t), intent(out) :: v !! the item
integer :: n, at
select case (a%kind)
case (V_STR); n = len(a%text)
case (V_LIST, V_TUPLE); n = size(a%items)
case default
call fail(c, 'a value cannot be subscripted')
return
end select
at = merge(index + n, index, index < 0) + 1
if (at < 1 .or. at > n) then
call fail(c, 'an index is out of range')
else if (a%kind == V_STR) then
call make_string(a%text(at:at), v)
else
v = a%items(at)
end if
end subroutine subscript