parse_value Subroutine

private recursive subroutine parse_value(unit, value)

Arguments

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

Contents

Source Code


Source Code

  recursive subroutine parse_value(unit, value)
    use fson_value_m, only: TYPE_ARRAY, TYPE_LOGICAL, TYPE_NULL, TYPE_OBJECT, &
      TYPE_STRING
    implicit none

    integer, intent(inout) :: unit
    type(fson_value), pointer :: value
    logical :: eof
    character :: c

    ! for some unknown reason the next pointer is getting messed with the pop
    type(fson_value), pointer :: hack

    ! start the hack
    hack => value % next

    ! pop the next non whitespace character off the file
    c = pop_char(unit, eof=eof, skip_ws=.true.)

    ! finish the hack; set the next pointer to whatever it was before the pop
    value % next => hack

    if (eof) then
       return
    else
       select case (c)
       case ("{")
          ! start object
          value % value_type = TYPE_OBJECT
          call parse_object(unit, value)
       case ("[")
          ! start array
          value % value_type = TYPE_ARRAY
          call parse_array(unit, value)
       case ("]")
          ! end an empty array
          nullify(value)
       case ('"')
          ! string
          value % value_type = TYPE_STRING
          value % value_string => parse_string(unit)
       case ("t")
          ! true
          value % value_type = TYPE_LOGICAL
          call parse_for_chars(unit, "rue")
          value % value_logical = .true.
       case ("f")
          ! false
          value % value_type = TYPE_LOGICAL
          value % value_logical = .false.
          call parse_for_chars(unit, "alse")
       case ("n")
          value % value_type = TYPE_NULL
          call parse_for_chars(unit, "ull")
       case("-", "0": "9")
          call push_char(c)
          call parse_number(unit, value)
       case default
          print *, "ERROR: Unexpected character while parsing value. '", c, "' ASCII=", iachar(c)
          call exit (1)
       end select
    end if

  end subroutine parse_value