diff --git a/Makefile.am b/Makefile.am index f2976975..e71c8013 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,7 +14,7 @@ json_unit_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/test -Dprivate=public # -i do not create #line information # --no-generation-date suppress generation date output src/json.hpp: src/json.hpp.re2c - $(AM_V_GEN)$(RE2C) -b -s -i --no-generation-date $< | $(SED) '1d' > $@ + $(AM_V_GEN)$(RE2C) -b -s --no-generation-date $< | $(SED) '1d' > $@ cppcheck: cppcheck --enable=all --inconclusive --std=c++11 src/json.hpp diff --git a/src/json.hpp b/src/json.hpp index dfd78e58..d666c699 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -1,3 +1,4 @@ +#line 1 "src/json.hpp.re2c" #ifndef _NLOHMANN_JSON #define _NLOHMANN_JSON @@ -2601,6 +2602,7 @@ class basic_json const lexer_char_t* marker; // set up RE2C +#line 2612 "src/json.hpp.re2c" for (;;) @@ -2609,6 +2611,7 @@ class basic_json current_re2c = buffer_re2c; +#line 2616 "" { lexer_char_t yych; unsigned int yyaccept = 0; @@ -2768,15 +2771,19 @@ class basic_json } } json_parser_2: +#line 2622 "src/json.hpp.re2c" { continue; } +#line 2705 "" json_parser_3: ++buffer_re2c; json_parser_4: +#line 2661 "src/json.hpp.re2c" { return last_token = token_type::parse_error; } +#line 2711 "" json_parser_5: yych = *++buffer_re2c; goto json_parser_60; @@ -2786,9 +2793,11 @@ json_parser_6: goto json_parser_51; json_parser_7: ++buffer_re2c; +#line 2629 "src/json.hpp.re2c" { return last_token = token_type::value_separator; } +#line 2723 "" json_parser_9: yych = *++buffer_re2c; if (yych <= '/') @@ -2826,28 +2835,36 @@ json_parser_10: } } json_parser_11: +#line 2649 "src/json.hpp.re2c" { return last_token = token_type::value_number; } +#line 2742 "" json_parser_12: yyaccept = 1; yych = *(marker = ++buffer_re2c); goto json_parser_41; json_parser_13: ++buffer_re2c; +#line 2630 "src/json.hpp.re2c" { return last_token = token_type::name_separator; } +#line 2751 "" json_parser_15: ++buffer_re2c; +#line 2625 "src/json.hpp.re2c" { return last_token = token_type::begin_array; } +#line 2756 "" json_parser_17: ++buffer_re2c; +#line 2626 "src/json.hpp.re2c" { return last_token = token_type::end_array; } +#line 2761 "" json_parser_19: yyaccept = 0; yych = *(marker = ++buffer_re2c); @@ -2874,14 +2891,18 @@ json_parser_21: goto json_parser_4; json_parser_22: ++buffer_re2c; +#line 2627 "src/json.hpp.re2c" { return last_token = token_type::begin_object; } +#line 2781 "" json_parser_24: ++buffer_re2c; +#line 2628 "src/json.hpp.re2c" { return last_token = token_type::end_object; } +#line 2786 "" json_parser_26: yych = *++buffer_re2c; if (yych == 'u') @@ -2905,9 +2926,11 @@ json_parser_28: goto json_parser_27; } ++buffer_re2c; +#line 2634 "src/json.hpp.re2c" { return last_token = token_type::literal_true; } +#line 2803 "" json_parser_31: yych = *++buffer_re2c; if (yych != 'l') @@ -2920,9 +2943,11 @@ json_parser_31: goto json_parser_27; } ++buffer_re2c; +#line 2633 "src/json.hpp.re2c" { return last_token = token_type::literal_null; } +#line 2812 "" json_parser_35: yych = *++buffer_re2c; if (yych != 'l') @@ -2940,9 +2965,11 @@ json_parser_35: goto json_parser_27; } ++buffer_re2c; +#line 2635 "src/json.hpp.re2c" { return last_token = token_type::literal_false; } +#line 2823 "" json_parser_40: yyaccept = 1; marker = ++buffer_re2c; @@ -3168,9 +3195,11 @@ json_parser_51: } json_parser_53: ++buffer_re2c; +#line 2658 "src/json.hpp.re2c" { return last_token = token_type::value_string; } +#line 2932 "" json_parser_55: ++buffer_re2c; yych = *buffer_re2c; @@ -3299,6 +3328,7 @@ json_parser_60: } goto json_parser_2; } +#line 2662 "src/json.hpp.re2c" } } diff --git a/test/unit.cpp b/test/unit.cpp index 4112b375..3cf82f16 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -3940,36 +3940,59 @@ TEST_CASE("convenience functions") CHECK(json::escape_string("\r") == "\\r"); CHECK(json::escape_string("\t") == "\\t"); - CHECK(json::escape_string( "\x01" ) == "\\u0001"); - CHECK(json::escape_string( "\x02" ) == "\\u0002"); - CHECK(json::escape_string( "\x03" ) == "\\u0003"); - CHECK(json::escape_string( "\x04" ) == "\\u0004"); - CHECK(json::escape_string( "\x05" ) == "\\u0005"); - CHECK(json::escape_string( "\x06" ) == "\\u0006"); - CHECK(json::escape_string( "\x07" ) == "\\u0007"); - CHECK(json::escape_string( "\x08" ) == "\\b"); - CHECK(json::escape_string( "\x09" ) == "\\t"); - CHECK(json::escape_string( "\x0a" ) == "\\n"); - CHECK(json::escape_string( "\x0b" ) == "\\u000b"); - CHECK(json::escape_string( "\x0c" ) == "\\f"); - CHECK(json::escape_string( "\x0d" ) == "\\r"); - CHECK(json::escape_string( "\x0e" ) == "\\u000e"); - CHECK(json::escape_string( "\x0f" ) == "\\u000f"); - CHECK(json::escape_string( "\x10" ) == "\\u0010"); - CHECK(json::escape_string( "\x11" ) == "\\u0011"); - CHECK(json::escape_string( "\x12" ) == "\\u0012"); - CHECK(json::escape_string( "\x13" ) == "\\u0013"); - CHECK(json::escape_string( "\x14" ) == "\\u0014"); - CHECK(json::escape_string( "\x15" ) == "\\u0015"); - CHECK(json::escape_string( "\x16" ) == "\\u0016"); - CHECK(json::escape_string( "\x17" ) == "\\u0017"); - CHECK(json::escape_string( "\x18" ) == "\\u0018"); - CHECK(json::escape_string( "\x19" ) == "\\u0019"); - CHECK(json::escape_string( "\x1a" ) == "\\u001a"); - CHECK(json::escape_string( "\x1b" ) == "\\u001b"); - CHECK(json::escape_string( "\x1c" ) == "\\u001c"); - CHECK(json::escape_string( "\x1d" ) == "\\u001d"); - CHECK(json::escape_string( "\x1e" ) == "\\u001e"); - CHECK(json::escape_string( "\x1f" ) == "\\u001f"); + CHECK(json::escape_string("\x01") == "\\u0001"); + CHECK(json::escape_string("\x02") == "\\u0002"); + CHECK(json::escape_string("\x03") == "\\u0003"); + CHECK(json::escape_string("\x04") == "\\u0004"); + CHECK(json::escape_string("\x05") == "\\u0005"); + CHECK(json::escape_string("\x06") == "\\u0006"); + CHECK(json::escape_string("\x07") == "\\u0007"); + CHECK(json::escape_string("\x08") == "\\b"); + CHECK(json::escape_string("\x09") == "\\t"); + CHECK(json::escape_string("\x0a") == "\\n"); + CHECK(json::escape_string("\x0b") == "\\u000b"); + CHECK(json::escape_string("\x0c") == "\\f"); + CHECK(json::escape_string("\x0d") == "\\r"); + CHECK(json::escape_string("\x0e") == "\\u000e"); + CHECK(json::escape_string("\x0f") == "\\u000f"); + CHECK(json::escape_string("\x10") == "\\u0010"); + CHECK(json::escape_string("\x11") == "\\u0011"); + CHECK(json::escape_string("\x12") == "\\u0012"); + CHECK(json::escape_string("\x13") == "\\u0013"); + CHECK(json::escape_string("\x14") == "\\u0014"); + CHECK(json::escape_string("\x15") == "\\u0015"); + CHECK(json::escape_string("\x16") == "\\u0016"); + CHECK(json::escape_string("\x17") == "\\u0017"); + CHECK(json::escape_string("\x18") == "\\u0018"); + CHECK(json::escape_string("\x19") == "\\u0019"); + CHECK(json::escape_string("\x1a") == "\\u001a"); + CHECK(json::escape_string("\x1b") == "\\u001b"); + CHECK(json::escape_string("\x1c") == "\\u001c"); + CHECK(json::escape_string("\x1d") == "\\u001d"); + CHECK(json::escape_string("\x1e") == "\\u001e"); + CHECK(json::escape_string("\x1f") == "\\u001f"); } } + +TEST_CASE("parser class") +{ + SECTION("get_token") + { + SECTION("structural characters") + { + CHECK(json::parser("[").last_token == json::parser::token_type::begin_array); + CHECK(json::parser("]").last_token == json::parser::token_type::end_array); + CHECK(json::parser("{").last_token == json::parser::token_type::begin_object); + CHECK(json::parser("}").last_token == json::parser::token_type::end_object); + CHECK(json::parser(",").last_token == json::parser::token_type::value_separator); + CHECK(json::parser(":").last_token == json::parser::token_type::name_separator); + } + + SECTION("literal names") + { + CHECK(json::parser("null").last_token == json::parser::token_type::literal_null); + CHECK(json::parser("true").last_token == json::parser::token_type::literal_true); + CHECK(json::parser("false").last_token == json::parser::token_type::literal_false); + } + } +} \ No newline at end of file