parse_node_section_line Subroutine

subroutine parse_node_section_line(line, state, parsed, section)

Parse one line from the node section.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: line

Current JSON line to parse

type(json_node_state_type), intent(inout) :: state

Mutable node parser state

type(json_parse_result_type), intent(inout) :: parsed

Parsed ONNX content accumulated so far

character(len=32), intent(inout) :: section

Current top-level JSON section name


Source Code

  subroutine parse_node_section_line(line, state, parsed, section)
    !! Parse one line from the node section.
    implicit none

    ! Arguments
    character(*), intent(in) :: line
    !! Current JSON line to parse
    type(json_node_state_type), intent(inout) :: state
    !! Mutable node parser state
    type(json_parse_result_type), intent(inout) :: parsed
    !! Parsed ONNX content accumulated so far
    character(32), intent(inout) :: section
    !! Current top-level JSON section name

    if(.not.state%in_object .and. is_json_object_start(line))then
       call reset_node_state(state)
       state%in_object = .true.
       return
    end if

    if(state%in_object)then
       if(len_trim(state%active_string_array) .gt. 0)then
          if(index(line, ']') .gt. 0) state%active_string_array = ''
          call append_json_string_array_item(line, state%active_string_array, &
               state%inputs, state%num_inputs, state%outputs, &
               state%num_outputs)
          return
       end if

       if(state%in_attribute)then
          call update_array_bracket_depth(line, state%attribute_bracket_depth)
          if(state%attribute_bracket_depth .le. 0)then
             state%in_attribute = .false.
          end if
          if(index(line, '{') .gt. 0)then
             call parse_json_attribute(line, state%attrs, state%num_attrs)
          end if
          return
       end if

       if(index(line, '"attribute"') .gt. 0 .and. index(line, '[') .gt. 0)then
          state%in_attribute = .true.
          state%attribute_bracket_depth = 1
          if(index(line, ']') .gt. 0)then
             call parse_json_attribute(line, state%attrs, state%num_attrs)
             state%in_attribute = .false.
             state%attribute_bracket_depth = 0
          end if
          return
       end if

       if(index(line, '}') .gt. 0 .and. index(line, '"') .eq. 0 .and. &
            .not.state%in_attribute)then
          call store_node_state(state, parsed)
          state%in_object = .false.
          return
       end if

       if(index(line, '"input"') .gt. 0)then
          call parse_json_string_array(line, '"input"', state%inputs, &
               state%num_inputs)
          if(index(line, '[') .gt. 0 .and. index(line, ']') .eq. 0)then
             state%active_string_array = 'input'
          end if
          return
       end if

       if(index(line, '"output"') .gt. 0)then
          call parse_json_string_array(line, '"output"', state%outputs, &
               state%num_outputs)
          if(index(line, '[') .gt. 0 .and. index(line, ']') .eq. 0)then
             state%active_string_array = 'output'
          end if
          return
       end if

       if(index(line, '"name"') .gt. 0)then
          call extract_json_string(line, '"name"', state%name)
          return
       end if

       if(index(line, '"opType"') .gt. 0)then
          call extract_json_string(line, '"opType"', state%op_type)
          return
       end if
    end if

    if(index(line, ']') .gt. 0 .and. .not.state%in_object) section = ''

  end subroutine parse_node_section_line