parse_object Subroutine

private recursivesubroutine parse_object(unit, str, parent)

Arguments

Type IntentOptional AttributesName
integer(kind=IK), intent(in) :: unit

file unit number (if parsing from a file)

character(kind=CK,len=*), intent(in) :: str

JSON string (if parsing from a string)

type(json_value), , pointer:: parent

the parsed object will be added as a child of this

Description

Core parsing routine.

Calls

proc~~parse_object~~CallsGraph proc~parse_object parse_object proc~parse_object->proc~parse_object interface~throw_exception throw_exception proc~parse_object->interface~throw_exception proc~pop_char pop_char proc~parse_object->proc~pop_char interface~json_destroy json_destroy proc~parse_object->interface~json_destroy proc~parse_string parse_string proc~parse_object->proc~parse_string proc~json_value_create json_value_create proc~parse_object->proc~json_value_create proc~parse_value parse_value proc~parse_object->proc~parse_value interface~json_add json_add proc~parse_object->interface~json_add proc~json_throw_exception json_throw_exception interface~throw_exception->proc~json_throw_exception proc~json_value_destroy json_value_destroy interface~json_destroy->proc~json_value_destroy proc~parse_string->interface~throw_exception proc~parse_string->proc~pop_char proc~valid_json_hex valid_json_hex proc~parse_string->proc~valid_json_hex proc~parse_value->proc~parse_object proc~parse_value->interface~throw_exception proc~parse_value->proc~pop_char proc~parse_value->proc~parse_string proc~to_string to_string proc~parse_value->proc~to_string proc~parse_array parse_array proc~parse_value->proc~parse_array proc~parse_number parse_number proc~parse_value->proc~parse_number proc~to_logical to_logical proc~parse_value->proc~to_logical proc~push_char push_char proc~parse_value->proc~push_char proc~to_object to_object proc~parse_value->proc~to_object proc~to_array to_array proc~parse_value->proc~to_array proc~parse_for_chars parse_for_chars proc~parse_value->proc~parse_for_chars proc~to_null to_null proc~parse_value->proc~to_null proc~json_value_add_logical json_value_add_logical interface~json_add->proc~json_value_add_logical proc~json_value_add_double json_value_add_double interface~json_add->proc~json_value_add_double proc~json_value_add_member json_value_add_member interface~json_add->proc~json_value_add_member proc~json_value_add_integer json_value_add_integer interface~json_add->proc~json_value_add_integer proc~json_value_add_double_vec json_value_add_double_vec interface~json_add->proc~json_value_add_double_vec proc~json_value_add_logical_vec json_value_add_logical_vec interface~json_add->proc~json_value_add_logical_vec proc~json_value_add_integer_vec json_value_add_integer_vec interface~json_add->proc~json_value_add_integer_vec proc~json_value_add_string_vec json_value_add_string_vec interface~json_add->proc~json_value_add_string_vec proc~json_value_add_string json_value_add_string interface~json_add->proc~json_value_add_string proc~json_value_destroy->proc~json_value_destroy proc~destroy_json_data destroy_json_data proc~json_value_destroy->proc~destroy_json_data proc~to_string->proc~destroy_json_data proc~parse_array->interface~throw_exception proc~parse_array->proc~pop_char proc~parse_array->interface~json_destroy proc~parse_array->proc~json_value_create proc~parse_array->proc~parse_value proc~parse_array->interface~json_add proc~parse_number->interface~throw_exception proc~parse_number->proc~pop_char proc~parse_number->proc~push_char proc~string_to_integer string_to_integer proc~parse_number->proc~string_to_integer proc~to_double to_double proc~parse_number->proc~to_double proc~string_to_double string_to_double proc~parse_number->proc~string_to_double proc~to_integer to_integer proc~parse_number->proc~to_integer proc~to_logical->proc~destroy_json_data proc~push_char->interface~throw_exception proc~integer_to_string integer_to_string proc~push_char->proc~integer_to_string proc~to_object->proc~destroy_json_data proc~to_array->proc~destroy_json_data proc~parse_for_chars->interface~throw_exception proc~parse_for_chars->proc~pop_char proc~to_null->proc~destroy_json_data proc~string_to_integer->interface~throw_exception proc~to_double->proc~destroy_json_data proc~string_to_double->interface~throw_exception proc~to_integer->proc~destroy_json_data proc~json_value_add_logical->proc~json_value_create proc~json_value_add_logical->interface~json_add proc~json_value_add_logical->proc~to_logical proc~json_value_add_double->proc~json_value_create proc~json_value_add_double->interface~json_add proc~json_value_add_double->proc~to_double proc~json_value_add_integer->proc~json_value_create proc~json_value_add_integer->interface~json_add proc~json_value_add_integer->proc~to_integer proc~json_value_add_double_vec->proc~json_value_create proc~json_value_add_double_vec->interface~json_add proc~json_value_add_double_vec->proc~to_array proc~json_value_add_logical_vec->proc~json_value_create proc~json_value_add_logical_vec->interface~json_add proc~json_value_add_logical_vec->proc~to_array proc~json_value_add_integer_vec->proc~json_value_create proc~json_value_add_integer_vec->interface~json_add proc~json_value_add_integer_vec->proc~to_array proc~json_value_add_string_vec->proc~json_value_create proc~json_value_add_string_vec->interface~json_add proc~json_value_add_string_vec->proc~to_array proc~json_value_add_string->proc~json_value_create proc~json_value_add_string->interface~json_add proc~json_value_add_string->proc~to_string proc~escape_string escape_string proc~json_value_add_string->proc~escape_string
Help

Called By

proc~~parse_object~~CalledByGraph proc~parse_object parse_object proc~parse_object->proc~parse_object proc~parse_value parse_value proc~parse_object->proc~parse_value proc~parse_value->proc~parse_object proc~parse_array parse_array proc~parse_value->proc~parse_array proc~json_parse_string json_parse_string proc~json_parse_string->proc~parse_value proc~json_parse_file json_parse_file proc~json_parse_file->proc~parse_value proc~parse_array->proc~parse_value proc~wrap_json_parse_string wrap_json_parse_string proc~wrap_json_parse_string->proc~json_parse_string interface~json_parse json_parse interface~json_parse->proc~json_parse_string interface~json_parse->proc~json_parse_file proc~test_14 test_14 proc~test_14->interface~json_parse proc~test_8 test_8 proc~test_8->interface~json_parse proc~json_file_load json_file_load proc~json_file_load->interface~json_parse proc~json_file_load_from_string json_file_load_from_string proc~json_file_load_from_string->interface~json_parse program~jf_test_14 jf_test_14 program~jf_test_14->proc~test_14 program~jf_test_8 jf_test_8 program~jf_test_8->proc~test_8 proc~wrap_json_file_load_from_string wrap_json_file_load_from_string proc~wrap_json_file_load_from_string->proc~json_file_load_from_string
Help

Variables

TypeVisibility AttributesNameInitial
type(json_value), public, pointer:: pair
logical(kind=LK), public :: eof
character(kind=CK,len=1), public :: c
character(kind=CK,len=:), public, allocatable:: tmp

this is a work-around for a bug in the gfortran 4.9 compiler.


Source Code

    recursive subroutine parse_object(unit, str, parent)

    implicit none

    integer(IK),intent(in)              :: unit    !! file unit number (if parsing from a file)
    character(kind=CK,len=*),intent(in) :: str     !! JSON string (if parsing from a string)
    type(json_value),pointer            :: parent  !! the parsed object will be added as a child of this

    type(json_value),pointer :: pair
    logical(LK) :: eof
    character(kind=CK,len=1) :: c
    character(kind=CK,len=:),allocatable :: tmp  !! this is a work-around for a bug
                                                 !! in the gfortran 4.9 compiler.

    if (.not. exception_thrown) then

        !the routine is being called incorrectly.
        if (.not. associated(parent)) then
            call throw_exception('Error in parse_object: parent pointer not associated.')
        end if

        nullify(pair)    !probably not necessary

        ! pair name
        c = pop_char(unit, str=str, eof = eof, skip_ws = .true.)
        if (eof) then
            call throw_exception('Error in parse_object:'//&
                                 ' Unexpected end of file while parsing start of object.')
            return
        else if (end_object == c) then
            ! end of an empty object
            return
        else if (quotation_mark == c) then
            call json_value_create(pair)
            call parse_string(unit, str, tmp)   !write to a tmp variable because of
            pair % name = tmp                   ! a bug in 4.9 gfortran compiler.
            deallocate(tmp)
            if (exception_thrown) then
                call json_destroy(pair)
                return
            end if
        else
            call throw_exception('Error in parse_object: Expecting string: "'//c//'"')
            return
        end if

        ! pair value
        c = pop_char(unit, str=str, eof = eof, skip_ws = .true.)
        if (eof) then
            call throw_exception('Error in parse_object:'//&
                                 ' Unexpected end of file while parsing object member.')
            return
        else if (colon_char == c) then
            ! parse the value
            call parse_value(unit, str, pair)
            if (exception_thrown) then
                call json_destroy(pair)
                return
            else
                call json_add(parent, pair)
            end if
        else
            call throw_exception('Error in parse_object:'//&
                                 ' Expecting : and then a value: '//c)
            return
        end if

        ! another possible pair
        c = pop_char(unit, str=str, eof = eof, skip_ws = .true.)
        if (eof) then
            call throw_exception('Error in parse_object: '//&
                                 'End of file encountered when parsing an object')
            return
        else if (delimiter == c) then
            ! read the next member
            call parse_object(unit = unit, str=str, parent = parent)
        else if (end_object == c) then
            ! end of object
            return
        else
            call throw_exception('Error in parse_object: Expecting end of object: '//c)
            return
        end if

    end if

    end subroutine parse_object