@@ -216,11 +216,12 @@ module json_value_module
216216 ! ! then the string is returned unescaped.
217217
218218 logical (LK) :: allow_comments = .true. ! ! if true, any comments will be ignored when
219- ! ! parsing a file. The comment token is defined
219+ ! ! parsing a file. The comment tokens are defined
220220 ! ! by the `comment_char` character variable.
221- character (kind= CK,len= 1 ) :: comment_char = CK_' !' ! ! comment token when
222- ! ! `allow_comments` is true.
223- ! ! Examples: '`!`' or '`#`'.
221+ character (kind= CK,len= :),allocatable :: comment_char ! ! comment tokens when
222+ ! ! `allow_comments` is true.
223+ ! ! Examples: '`!`' or '`#`'.
224+ ! ! Default is `CK_'/!#'`.
224225
225226 integer (IK) :: path_mode = 1_IK ! ! How the path strings are interpreted in the
226227 ! ! `get_by_path` routines:
@@ -1081,7 +1082,7 @@ subroutine json_initialize(me,&
10811082 ! [an empty string disables comments]
10821083 if (present (comment_char)) then
10831084 me% allow_comments = comment_char/= CK_' '
1084- me% comment_char = comment_char
1085+ me% comment_char = trim ( adjustl ( comment_char))
10851086 end if
10861087
10871088 ! path separator:
@@ -9736,6 +9737,12 @@ subroutine json_parse_file(json, file, p, unit)
97369737 ! clear any exceptions and initialize:
97379738 call json% initialize()
97389739
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
9745+
97399746 if ( present (unit) ) then
97409747
97419748 if (unit== 0 ) then
@@ -9846,6 +9853,12 @@ subroutine json_parse_string(json, p, str)
98469853 ! clear any exceptions and initialize:
98479854 call json% initialize()
98489855
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
9861+
98499862 ! create the value and associate the pointer
98509863 call json_value_create(p)
98519864
@@ -11435,7 +11448,7 @@ subroutine pop_char(json,unit,str,skip_ws,skip_comments,eof,popped)
1143511448
1143611449 end if
1143711450
11438- if (ignore_comments .and. (parsing_comment .or. c == json% comment_char) ) then
11451+ if (ignore_comments .and. (parsing_comment .or. scan (c, json% comment_char,kind = IK)> 0_IK ) ) then
1143911452
1144011453 ! skipping the comment
1144111454 parsing_comment = .true.
0 commit comments