subroutinewrite_valuepurerecursiveprivate
pure recursive subroutine write_value(v, quoted, b)
Write v as str() does, or as repr() does if quoted.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| v | type(value_t) | in | the value | |
| quoted | logical | in | true for | |
| b | type(buffer_t) | inout | where it goes |
Calls
Source
Show the code
pure recursive subroutine write_value(v, quoted, b)
type(value_t), intent(in) :: v !! the value
logical, intent(in) :: quoted !! true for `repr()`
type(buffer_t), intent(inout) :: b !! where it goes
integer :: k, step
select case (v%kind)
case (V_NONE)
call add(b, 'None')
case (V_BOOL)
call add(b, merge('True ', 'False', v%number /= 0))
if (v%number /= 0) b%n = b%n - 1
case (V_INT)
call add(b, trim(int_text(v%number)))
case (V_STR)
if (quoted) call add(b, "'")
call add(b, v%text)
if (quoted) call add(b, "'")
case (V_MACRO)
call add(b, '<macro>')
case default
step = merge(2, 1, v%kind == V_DICT)
call add(b, merge('[', '(', v%kind == V_LIST))
do k = 1, size(v%items), step
if (k > 1) call add(b, ', ')
call write_value(v%items(k), .true., b)
end do
if (v%kind == V_TUPLE .and. size(v%items) == 1) call add(b, ',')
call add(b, merge(']', ')', v%kind == V_LIST))
end select
end subroutine write_value