Skip to content

Commit 7d2ee68

Browse files
committed
Allow the parser to work with some nonstandard real value representations (leading +, no leading digit before decimal, D/d format). Fixes #417
1 parent ca99a2d commit 7d2ee68

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Diff for: src/json_value_module.F90

+4-4
Original file line numberDiff line numberDiff line change
@@ -10110,16 +10110,16 @@ recursive subroutine parse_value(json, unit, str, value)
1011010110
call json%parse_for_chars(unit, str, null_str(2:))
1011110111
if (.not. json%exception_thrown) call json%to_null(value) ! allocate class
1011210112

10113-
case(CK_'-', CK_'0': CK_'9')
10113+
case(CK_'-', CK_'0': CK_'9', CK_'.', CK_'+')
1011410114

1011510115
call json%push_char(c)
1011610116
call json%parse_number(unit, str, value)
1011710117

1011810118
case default
1011910119

1012010120
call json%throw_exception('Error in parse_value:'//&
10121-
' Unexpected character while parsing value. "'//&
10122-
c//'"')
10121+
' Unexpected character while parsing value. "'//&
10122+
c//'"')
1012310123

1012410124
end select
1012510125
end if
@@ -11132,7 +11132,7 @@ subroutine parse_number(json, unit, str, value)
1113211132
tmp(ip:ip) = c
1113311133
ip = ip + 1
1113411134

11135-
case(CK_'.',CK_'E',CK_'e') !can be present in real numbers
11135+
case(CK_'.',CK_'E',CK_'e',CK_'D',CK_'d') !can be present in real numbers
1113611136

1113711137
if (is_integer) is_integer = .false.
1113811138

Diff for: src/tests/jf_test_42.F90

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ subroutine test_42(error_cnt)
2323
type(json_file) :: json !! the JSON structure read from the file
2424
integer,intent(out) :: error_cnt !! error counter
2525

26-
character(kind=CK,len=*),parameter :: str = CK_'{"bad_reals": [1.0, null, "NaN", "+Infinity", "-Infinity", 4.0]}'
26+
character(kind=CK,len=*),parameter :: str = CK_'{'//&
27+
'"bad_reals": [1.0, null, "NaN", "+Infinity", "-Infinity", 4.0],'//&
28+
'"nonstandard_json": [.1e1, .1D1, .1d+1, +.1d1, +.1D1, +1.0, +1.0d0, +1.0D0]'//&
29+
'}'
2730

2831
real(rk),dimension(:),allocatable :: bad_reals
2932
logical(lk) :: found

0 commit comments

Comments
 (0)