@@ -879,6 +879,7 @@ module json_value_module
879879 procedure :: json_value_print
880880 procedure :: string_to_int
881881 procedure :: string_to_dble
882+ procedure :: prepare_parser = > json_prepare_parser
882883 procedure :: parse_end = > json_parse_end
883884 procedure :: parse_value
884885 procedure :: parse_number
@@ -9691,6 +9692,26 @@ recursive subroutine wrap_json_get_array_by_path(json, me, path, array_callback,
96919692 end subroutine wrap_json_get_array_by_path
96929693! *****************************************************************************************
96939694
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+
96949715! *****************************************************************************************
96959716! >
96969717! Parse the JSON file and populate the [[json_value]] tree.
@@ -9736,12 +9757,7 @@ subroutine json_parse_file(json, file, p, unit)
97369757
97379758 ! clear any exceptions and initialize:
97389759 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()
97459761
97469762 if ( present (unit) ) then
97479763
@@ -9852,12 +9868,7 @@ subroutine json_parse_string(json, p, str)
98529868
98539869 ! clear any exceptions and initialize:
98549870 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()
98619872
98629873 ! create the value and associate the pointer
98639874 call json_value_create(p)
0 commit comments