Skip to content
Open
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
17 changes: 15 additions & 2 deletions json5_parser/json5_parser_reader_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
#include "json5_parser_value.h"
#include "json5_parser_error_position.h"

// emscripten threads are complicated to use and experimental
#ifndef __EMSCRIPTEN__
#define BOOST_SPIRIT_THREADSAFE // uncomment for multithreaded use, requires linking to boost.thread
#endif

#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>
#include <boost/function.hpp>
#include <boost/version.hpp>

Expand All @@ -37,6 +40,7 @@

namespace json5_parser
{
using namespace boost::placeholders;
const spirit_namespace::int_parser < boost::int64_t > int64_p = spirit_namespace::int_parser < boost::int64_t >();
const spirit_namespace::uint_parser< boost::uint64_t > uint64_p = spirit_namespace::uint_parser< boost::uint64_t >();

Expand Down Expand Up @@ -312,6 +316,13 @@ namespace json5_parser

add_to_current( -std::numeric_limits<double>::infinity() );
}

void new_nan( Iter_type begin, Iter_type end )
{
assert( is_eq( begin, end, "NaN" ) );

add_to_current( -std::numeric_limits<double>::quiet_NaN() );
}

private:

Expand Down Expand Up @@ -474,6 +485,7 @@ namespace json5_parser
Real_action new_real ( boost::bind( &Semantic_actions_t::new_real, &self.actions_, _1 ) );
Str_action new_infinity ( boost::bind( &Semantic_actions_t::new_infinity, &self.actions_, _1, _2 ) );
Str_action new_minus_infinity ( boost::bind( &Semantic_actions_t::new_minus_infinity, &self.actions_, _1, _2 ) );
Str_action new_nan ( boost::bind( &Semantic_actions_t::new_nan, &self.actions_, _1, _2 ) );
Int_action new_int ( boost::bind( &Semantic_actions_t::new_int, &self.actions_, _1 ) );
Uint64_action new_uint64 ( boost::bind( &Semantic_actions_t::new_uint64, &self.actions_, _1 ) );

Expand All @@ -494,6 +506,7 @@ namespace json5_parser
| str_p( "null" ) [ new_null ]
| (!ch_p('+') >> str_p( "Infinity" ) [ new_infinity ])
| str_p( "-Infinity" ) [ new_minus_infinity ]
| str_p( "NaN" ) [ new_nan ]
;

object_
Expand All @@ -507,7 +520,7 @@ namespace json5_parser
;

pair_
= (double_quoted_string_[ new_name ] | identifier_[ new_identifier ])
= (single_quoted_string_[ new_name ] | double_quoted_string_[ new_name ] | identifier_[ new_identifier ])
>> ( ':' | eps_p[ &throw_not_colon ] )
>> ( value_ | eps_p[ &throw_not_value ] )
;
Expand Down
5 changes: 5 additions & 0 deletions json5_parser/json5_parser_writer_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ namespace json5_parser

void output( double d )
{
if (std::isfinite(d))
os_ << std::setprecision( precision_of_doubles_ ) << d;
else if (std::isnan(d))
os_<<"NaN";
else // is infinite
os_<<(d<0?"-":"")<<"Infinity";
}

static bool contains_composite_elements( const Array_type& arr )
Expand Down