Skip to content

Commit a9e690b

Browse files
authored
Merge pull request #3 from Microsoft/rapidjson
Port JSON parsing/generation from cpprestsdk to RapidJSON
2 parents 880e8a7 + f4b0fbe commit a9e690b

20 files changed

+2214
-1386
lines changed

CMakeLists.txt

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,11 @@ find_package(pegtl CONFIG REQUIRED)
1818
target_include_directories(graphqlpeg INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}> $<INSTALL_INTERFACE:include>)
1919
target_link_libraries(graphqlpeg taocpp::pegtl)
2020

21-
find_package(cpprestsdk REQUIRED)
22-
set(CPPRESTSDK cpprestsdk::cpprest)
21+
find_package(RapidJSON CONFIG REQUIRED)
2322

24-
if(UNIX)
25-
find_library(BOOST_SYSTEM boost_system)
26-
list(APPEND CPPRESTSDK ${BOOST_SYSTEM})
27-
endif()
28-
29-
target_include_directories(graphqlservice INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}> $<INSTALL_INTERFACE:include>)
30-
target_link_libraries(graphqlservice ${CPPRESTSDK} graphqlpeg)
31-
target_link_libraries(schemagen ${CPPRESTSDK} graphqlpeg)
23+
target_include_directories(graphqlservice INTERFACE ${RAPIDJSON_INCLUDE_DIRS} $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}> $<INSTALL_INTERFACE:include>)
24+
target_link_libraries(graphqlservice graphqlpeg)
25+
target_link_libraries(schemagen graphqlpeg)
3226

3327
add_custom_command(
3428
OUTPUT IntrospectionSchema.cpp IntrospectionSchema.h
@@ -59,31 +53,27 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
5953
TodaySchema.cpp
6054
Today.cpp)
6155

62-
target_link_libraries(todaygraphql
63-
${CPPRESTSDK}
64-
graphqlservice)
65-
target_include_directories(todaygraphql SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
56+
target_link_libraries(todaygraphql graphqlservice)
57+
target_include_directories(todaygraphql SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
6658

6759
add_executable(test_today test_today.cpp)
6860

6961
target_link_libraries(test_today
70-
${CPPRESTSDK}
7162
graphqlpeg
7263
graphqlservice
7364
todaygraphql)
74-
target_include_directories(test_today SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
65+
target_include_directories(test_today SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
7566

7667
enable_testing()
7768
add_executable(tests tests.cpp)
7869
find_package(GTest REQUIRED)
7970
target_link_libraries(tests
80-
${CPPRESTSDK}
8171
graphqlpeg
8272
graphqlservice
8373
todaygraphql
8474
GTest::GTest
8575
GTest::Main)
86-
target_include_directories(tests SYSTEM PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
76+
target_include_directories(tests SYSTEM PUBLIC ${RAPIDJSON_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
8777
add_test(TodayServiceCase tests)
8878
add_test(ArgumentsCase tests)
8979

GraphQLGrammar.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,28 @@ namespace facebook {
1212
namespace graphql {
1313
namespace peg {
1414

15-
using namespace tao::pegtl;
15+
using namespace tao::graphqlpeg;
1616

1717
template <typename _Rule>
18-
void for_each_child(const ast_node& n, std::function<bool(const ast_node&)>&& func)
18+
void for_each_child(const ast_node& n, std::function<void(const ast_node&)>&& func)
1919
{
2020
for (const auto& child : n.children)
2121
{
22-
if (child->is<_Rule>()
23-
&& !func(*child))
22+
if (child->is<_Rule>())
2423
{
24+
func(*child);
25+
}
26+
}
27+
}
28+
29+
template <typename _Rule>
30+
void on_first_child(const ast_node& n, std::function<void(const ast_node&)>&& func)
31+
{
32+
for (const auto& child : n.children)
33+
{
34+
if (child->is<_Rule>())
35+
{
36+
func(*child);
2537
return;
2638
}
2739
}
@@ -94,13 +106,13 @@ struct string_escape_sequence
94106
};
95107

96108
struct string_quote_character
97-
: source_character
109+
: plus<seq<not_at<backslash_token>, not_at<quote_token>, not_at<ascii::eol>, source_character>>
98110
{
99111
};
100112

101113
// https://facebook.github.io/graphql/June2018/#StringCharacter
102114
struct string_quote
103-
: if_must<quote_token, star<seq<not_at<quote_token>, not_at<ascii::eol>, sor<string_escape_sequence, string_quote_character>>>, quote_token>
115+
: if_must<quote_token, star<sor<string_escape_sequence, string_quote_character>>, quote_token>
104116
{
105117
};
106118

@@ -110,18 +122,18 @@ struct block_quote_token
110122
};
111123

112124
struct block_escape_sequence
113-
: if_must<backslash_token, block_quote_token>
125+
: seq<backslash_token, block_quote_token>
114126
{
115127
};
116128

117129
struct block_quote_character
118-
: source_character
130+
: plus<seq<not_at<block_quote_token>, not_at<block_escape_sequence>, source_character>>
119131
{
120132
};
121133

122134
// https://facebook.github.io/graphql/June2018/#BlockStringCharacter
123135
struct block_quote
124-
: if_must<block_quote_token, star<seq<not_at<block_quote_token>, sor<block_escape_sequence, block_quote_character>>>, block_quote_token>
136+
: if_must<block_quote_token, star<sor<block_escape_sequence, block_quote_character>>, block_quote_token>
125137
{
126138
};
127139

@@ -804,7 +816,7 @@ struct definition
804816

805817
// https://facebook.github.io/graphql/June2018/#Document
806818
struct document
807-
: must<bof, opt<utf8::bom>, star<ignored>, list<definition, plus<ignored>>, star<ignored>, tao::pegtl::eof>
819+
: must<bof, opt<utf8::bom>, star<ignored>, list<definition, plus<ignored>>, star<ignored>, tao::graphqlpeg::eof>
808820
{
809821
};
810822

0 commit comments

Comments
 (0)