Core parsing routine.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
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 | :: | array |
recursive subroutine parse_array(json, unit, str, array) implicit none class(json_core),intent(inout) :: json 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 :: array type(json_value),pointer :: element !! temp variable for array element logical(LK) :: eof !! end of file flag character(kind=CK,len=1) :: c !! character returned by [[pop_char]] logical(LK) :: expecting_next_element !! to check for trailing delimiters expecting_next_element = .false. do if (json%exception_thrown) exit ! try to parse an element value nullify(element) call json_value_create(element) call json%parse_value(unit, str, element) if (json%exception_thrown) then if (associated(element)) call json%destroy(element) exit end if ! parse value will deallocate an empty array value if (associated(element)) then expecting_next_element = .false. call json%add(array, element) end if ! popped the next character call json%pop_char(unit, str=str, eof=eof, skip_ws=.true., & skip_comments=json%allow_comments, popped=c) if (eof) then ! The file ended before array was finished: call json%throw_exception('Error in parse_array: '//& 'End of file encountered when parsing an array.') exit else if (delimiter == c) then ! parse the next element expecting_next_element = .true. cycle else if (end_array == c) then ! end of array if (expecting_next_element .and. .not. json%allow_trailing_comma) then ! this is a dangling comma. call json%throw_exception('Error in parse_array: '//& 'Dangling comma when parsing an array.') end if exit else call json%throw_exception('Error in parse_array: '//& 'Unexpected character encountered when parsing array.') exit end if end do end subroutine parse_array