Skip to content

Commit 088b802

Browse files
Merge pull request #240 from jacobwilliams/comments
Comments
2 parents 799936b + b80c58d commit 088b802

File tree

6 files changed

+256
-39
lines changed

6 files changed

+256
-39
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ doc/
1111
.sconsign.*
1212
files/*.json
1313
.cflags.*
14-
src/tests/jf_test_example[12].f90
15-
documentation/
1614
visual_studio_2010/*.suo
1715
visual_studio_2010/*.u2d
1816
visual_studio_2010/Debug/
1917
visual_studio_2010/Release/
20-
visual_studio_2010/x64
21-
FoBiS.py
22-
robodoc
18+
visual_studio_2010/x64/

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ if ( ENABLE_TESTS )
246246
# Validate input
247247
if ( JSONLINT )
248248
file ( GLOB JSON_INPUTS "${DATA_DIR}/inputs/*.json" )
249-
file ( GLOB INVALID_JSON "${DATA_DIR}/inputs/*invalid*.json" )
249+
file ( GLOB INVALID_JSON "${DATA_DIR}/inputs/*invalid*.json" "${DATA_DIR}/inputs/comments.json")
250250

251251
list ( REMOVE_ITEM JSON_INPUTS ${INVALID_JSON} )
252252
list ( REMOVE_ITEM JSON_INPUTS "${DATA_DIR}/inputs/big.json" ) # This takes too long and is valid

files/inputs/comments.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
!
2+
! This is a JSON file with comments
3+
!
4+
! The comments are lines beginning with the `!` character.
5+
! Here is an example of multiple comment lines
6+
7+
{
8+
! this is an object
9+
"version": {
10+
"major": 2,
11+
"minor": 2,
12+
"patch": 1,
13+
"string": "2.2.1", ! this is a string
14+
"svn": 7191
15+
}
16+
!the next line is a comma
17+
,
18+
!the previous line was a comma
19+
"files": [
20+
"..\\path\\to\\files\\file1.txt",
21+
"..\\path\\to\\files\\file2.txt",
22+
"..\\path\\to\\files\\file3.txt",
23+
"test \u2FA4 \uABCD \uABCD\uABCDtest",! this is an array element
24+
! another comment line.
25+
" test \\u \" blah\\\" test test",
26+
"..\\path\\to\\files\\",
27+
" this string has ! comment characters !"
28+
],
29+
"empty_array": [
30+
!an empty array
31+
],
32+
"empty_object": {
33+
},
34+
"empty_string": "",
35+
"data": [
36+
{
37+
"number": 1,
38+
"tf1": true,
39+
"tf2": false,
40+
"empty": null,
41+
"name": "Horatio",
42+
"array": [
43+
"1",
44+
"2",
45+
"3"
46+
]
47+
},
48+
! blah blah
49+
{
50+
"number": 2,
51+
"integer": 33,
52+
"real": 0.2333000000000000E+003 ! how about a comment after a real
53+
,
54+
"name": "Nelson"
55+
}
56+
]
57+
} ! and we're done

src/json_file_module.F90

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ subroutine initialize_json_core_in_file(me,verbose,compact_reals,&
273273
trailing_spaces_significant,&
274274
case_sensitive_keys,&
275275
no_whitespace,&
276-
unescape_strings)
276+
unescape_strings,&
277+
comment_char)
277278

278279
implicit none
279280

@@ -298,14 +299,19 @@ subroutine initialize_json_core_in_file(me,verbose,compact_reals,&
298299
!! string is returned from [[json_get_string]]
299300
!! and similar routines. If true [default],
300301
!! then the string is returned unescaped.
302+
character(kind=CK,len=1),intent(in),optional :: comment_char !! If present, this character is used
303+
!! to denote comments in the JSON file,
304+
!! which will be ignored if present.
305+
!! Example: `!` or `#`.
301306

302307
call me%core%initialize(verbose,compact_reals,&
303308
print_signs,real_format,spaces_per_tab,&
304309
strict_type_checking,&
305310
trailing_spaces_significant,&
306311
case_sensitive_keys,&
307312
no_whitespace,&
308-
unescape_strings)
313+
unescape_strings,&
314+
comment_char)
309315

310316
end subroutine initialize_json_core_in_file
311317
!*****************************************************************************************
@@ -365,7 +371,8 @@ function initialize_json_file(p,verbose,compact_reals,&
365371
trailing_spaces_significant,&
366372
case_sensitive_keys,&
367373
no_whitespace,&
368-
unescape_strings) result(file_object)
374+
unescape_strings,&
375+
comment_char) result(file_object)
369376

370377
implicit none
371378

@@ -392,14 +399,19 @@ function initialize_json_file(p,verbose,compact_reals,&
392399
!! string is returned from [[json_get_string]]
393400
!! and similar routines. If true [default],
394401
!! then the string is returned unescaped.
402+
character(kind=CK,len=1),intent(in),optional :: comment_char !! If present, this character is used
403+
!! to denote comments in the JSON file,
404+
!! which will be ignored if present.
405+
!! Example: `!` or `#`.
395406

396407
call file_object%initialize(verbose,compact_reals,&
397408
print_signs,real_format,spaces_per_tab,&
398409
strict_type_checking,&
399410
trailing_spaces_significant,&
400411
case_sensitive_keys,&
401412
no_whitespace,&
402-
unescape_strings)
413+
unescape_strings,&
414+
comment_char)
403415

404416
if (present(p)) file_object%p => p
405417

0 commit comments

Comments
 (0)