parse_array Subroutine

private recursive subroutine parse_array(unit, array)

Arguments

Type IntentOptional AttributesName
integer, intent(inout) :: unit
type(fson_value), pointer:: array

Contents

Source Code


Source Code

  recursive subroutine parse_array(unit, array)
    use fson_value_m, only: fson_value_create, fson_value_add
    implicit none

    integer, intent(inout) :: unit
    type(fson_value), pointer :: array, element

    logical :: eof
    character :: c

    ! try to parse an element value
    element => fson_value_create()
    call parse_value(unit, element)

    ! parse value will disassociate an empty array value
    if (associated(element)) then
       call fson_value_add(array, element)
    end if

    ! popped the next character
    c = pop_char(unit, eof=eof, skip_ws=.true.)

    if (eof) then
       return
    else if ("," == c) then
       ! parse the next element
       call parse_array(unit, array)
    else if ("]" == c) then
       ! end of array
       return
    end if

  end subroutine parse_array