@@ -20,36 +20,56 @@ namespace graphql {
2020
2121// Given properly-configured yylex, run the parser and return the
2222// result.
23- static std::unique_ptr<ast::Node> doParse (const char **outError, yyscan_t scanner) {
23+ static std::unique_ptr<ast::Node> doParse (const char **outError, yyscan_t scanner, bool enableSchema ) {
2424 Node *outAST;
25- yy::GraphQLParserImpl parser (&outAST, outError, scanner);
25+ yy::GraphQLParserImpl parser (enableSchema, &outAST, outError, scanner);
2626 int failure = parser.parse ();
2727 return !failure ? std::unique_ptr<ast::Node>(outAST) : nullptr ;
2828}
2929
30- std::unique_ptr<ast::Node> parseString (const char *text, const char **error) {
30+ static std::unique_ptr<ast::Node> parseStringImpl (const char *text, const char **error, bool enableSchema ) {
3131 yyscan_t scanner;
3232 struct LexerExtra extra;
3333 yylex_init_extra (&extra, &scanner);
3434 YY_BUFFER_STATE buffer = yy_scan_string (text, scanner);
3535 yy_switch_to_buffer (buffer, scanner);
3636
37- auto result = doParse (error, scanner);
37+ auto result = doParse (error, scanner, enableSchema );
3838 yylex_destroy (scanner);
3939 return result;
4040}
4141
42- std::unique_ptr<ast::Node> parseFile (FILE *file, const char **error) {
42+ std::unique_ptr<ast::Node> parseString (const char *text, const char **error) {
43+ return parseStringImpl (text, error, false );
44+ }
45+
46+ std::unique_ptr<ast::Node> parseStringWithExperimentalSchemaSupport (
47+ const char *text, const char **error) {
48+ return parseStringImpl (text, error, true );
49+ }
50+
51+ static std::unique_ptr<ast::Node> parseFileImpl (
52+ FILE *file, const char **error, bool enableSchema) {
4353 yyscan_t scanner;
4454 struct LexerExtra extra;
4555 yylex_init_extra (&extra, &scanner);
4656 yyset_in (file, scanner);
4757
48- auto result = doParse (error, scanner);
58+ auto result = doParse (error, scanner, enableSchema );
4959 yylex_destroy (scanner);
5060
5161 return result;
5262}
5363
64+ std::unique_ptr<ast::Node> parseFile (FILE *file, const char **error) {
65+ return parseFileImpl (file, error, false );
66+ }
67+
68+ std::unique_ptr<ast::Node> parseFileWithExperimentalSchemaSupport (
69+ FILE *file, const char **error) {
70+ return parseFileImpl (file, error, true );
71+ }
72+
73+
5474}
5575}
0 commit comments