Skip to content

Allow the parser to work with some nonstandard real value representat… #418

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/json_value_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10110,16 +10110,16 @@ recursive subroutine parse_value(json, unit, str, value)
call json%parse_for_chars(unit, str, null_str(2:))
if (.not. json%exception_thrown) call json%to_null(value) ! allocate class

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

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

case default

call json%throw_exception('Error in parse_value:'//&
' Unexpected character while parsing value. "'//&
c//'"')
' Unexpected character while parsing value. "'//&
c//'"')

end select
end if
Expand Down Expand Up @@ -11132,7 +11132,7 @@ subroutine parse_number(json, unit, str, value)
tmp(ip:ip) = c
ip = ip + 1

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

if (is_integer) is_integer = .false.

Expand Down
5 changes: 4 additions & 1 deletion src/tests/jf_test_42.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ subroutine test_42(error_cnt)
type(json_file) :: json !! the JSON structure read from the file
integer,intent(out) :: error_cnt !! error counter

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

real(rk),dimension(:),allocatable :: bad_reals
logical(lk) :: found
Expand Down