@@ -879,6 +879,7 @@ module json_value_module
879
879
procedure :: json_value_print
880
880
procedure :: string_to_int
881
881
procedure :: string_to_dble
882
+ procedure :: prepare_parser = > json_prepare_parser
882
883
procedure :: parse_end = > json_parse_end
883
884
procedure :: parse_value
884
885
procedure :: parse_number
@@ -9691,6 +9692,26 @@ recursive subroutine wrap_json_get_array_by_path(json, me, path, array_callback,
9691
9692
end subroutine wrap_json_get_array_by_path
9692
9693
! *****************************************************************************************
9693
9694
9695
+ ! *****************************************************************************************
9696
+ ! >
9697
+ ! Internal routine to be called before parsing JSON.
9698
+ ! Currently, all this does it allocate the `comment_char` if none was specified.
9699
+
9700
+ subroutine json_prepare_parser (json )
9701
+
9702
+ implicit none
9703
+
9704
+ class(json_core),intent (inout ) :: json
9705
+
9706
+ if (json% allow_comments .and. .not. allocated (json% comment_char)) then
9707
+ ! comments are enabled, but user hasn't set the comment char,
9708
+ ! so in this case use the default:
9709
+ json% comment_char = CK_' /!#'
9710
+ end if
9711
+
9712
+ end subroutine json_prepare_parser
9713
+ ! *****************************************************************************************
9714
+
9694
9715
! *****************************************************************************************
9695
9716
! >
9696
9717
! Parse the JSON file and populate the [[json_value]] tree.
@@ -9736,12 +9757,7 @@ subroutine json_parse_file(json, file, p, unit)
9736
9757
9737
9758
! clear any exceptions and initialize:
9738
9759
call json% initialize()
9739
-
9740
- if (json% allow_comments .and. .not. allocated (json% comment_char)) then
9741
- ! comments are enabled, but user hasn't set the comment char,
9742
- ! so in this case use the default:
9743
- json% comment_char = CK_' /!#'
9744
- end if
9760
+ call json% prepare_parser()
9745
9761
9746
9762
if ( present (unit) ) then
9747
9763
@@ -9852,12 +9868,7 @@ subroutine json_parse_string(json, p, str)
9852
9868
9853
9869
! clear any exceptions and initialize:
9854
9870
call json% initialize()
9855
-
9856
- if (json% allow_comments .and. .not. allocated (json% comment_char)) then
9857
- ! comments are enabled, but user hasn't set the comment char,
9858
- ! so in this case use the default:
9859
- json% comment_char = CK_' /!#'
9860
- end if
9871
+ call json% prepare_parser()
9861
9872
9862
9873
! create the value and associate the pointer
9863
9874
call json_value_create(p)
0 commit comments