Skip to content

Commit dde8101

Browse files
authored
Merge pull request #71 from graphql/block-strings
Block strings
2 parents 9d55a3c + c69e3b0 commit dde8101

13 files changed

+1533
-1051
lines changed

GraphQLParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace graphql {
1919
// Given properly-configured yylex, run the parser and return the
2020
// result.
2121
static std::unique_ptr<ast::Node> doParse(const char **outError, yyscan_t scanner, bool enableSchema) {
22-
Node *outAST = NULL;
22+
Node *outAST = nullptr;
2323
yy::GraphQLParserImpl parser(enableSchema, &outAST, outError, scanner);
2424
int failure = parser.parse();
2525
if (failure) {

JsonVisitor.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ namespace graphql {
1616
namespace ast {
1717
namespace visitor {
1818

19+
static std::string escape(const char *s) {
20+
static char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
21+
std::string result;
22+
while (unsigned char ch = *s++) {
23+
if (ch >= '\0' && ch <= '\x1f') {
24+
result.push_back('\\');
25+
result.push_back('u');
26+
result.push_back('0');
27+
result.push_back('0');
28+
result.push_back(ch >= 16 ? '1' : '0');
29+
result.push_back(hex[ch % 16]);
30+
} else if (ch == '"') {
31+
result.push_back('\\');
32+
result.push_back('"');
33+
} else if (ch == '\\') {
34+
result.push_back('\\');
35+
result.push_back('\\');
36+
} else {
37+
result.push_back(ch);
38+
}
39+
}
40+
return result;
41+
}
1942

2043
JsonVisitor::NodeFieldPrinter::NodeFieldPrinter(
2144
JsonVisitor &visitor,
@@ -54,7 +77,7 @@ void JsonVisitor::NodeFieldPrinter::printSingularPrimitiveField(
5477
const char *value) {
5578
printFieldSeparator();
5679
out_ << '"' << fieldName << R"(":)";
57-
out_ << '"' << value << '"';
80+
out_ << '"' << escape(value) << '"';
5881
}
5982

6083
void JsonVisitor::NodeFieldPrinter::printSingularBooleanField(

lexer.cpp

Lines changed: 491 additions & 309 deletions
Large diffs are not rendered by default.

lexer.h

Lines changed: 182 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,35 @@
1313
#define FLEX_SCANNER
1414
#define YY_FLEX_MAJOR_VERSION 2
1515
#define YY_FLEX_MINOR_VERSION 6
16-
#define YY_FLEX_SUBMINOR_VERSION 2
16+
#define YY_FLEX_SUBMINOR_VERSION 4
1717
#if YY_FLEX_SUBMINOR_VERSION > 0
1818
#define FLEX_BETA
1919
#endif
2020

21+
#ifdef yyget_lval
22+
#define yyget_lval_ALREADY_DEFINED
23+
#else
24+
#define yyget_lval yyget_lval
25+
#endif
26+
27+
#ifdef yyset_lval
28+
#define yyset_lval_ALREADY_DEFINED
29+
#else
30+
#define yyset_lval yyset_lval
31+
#endif
32+
33+
#ifdef yyget_lloc
34+
#define yyget_lloc_ALREADY_DEFINED
35+
#else
36+
#define yyget_lloc yyget_lloc
37+
#endif
38+
39+
#ifdef yyset_lloc
40+
#define yyset_lloc_ALREADY_DEFINED
41+
#else
42+
#define yyset_lloc yyset_lloc
43+
#endif
44+
2145
/* First, we deal with platform-specific or compiler-specific issues. */
2246

2347
/* begin standard C headers. */
@@ -88,10 +112,16 @@ typedef unsigned int flex_uint32_t;
88112
#define UINT32_MAX (4294967295U)
89113
#endif
90114

115+
#ifndef SIZE_MAX
116+
#define SIZE_MAX (~(size_t)0)
117+
#endif
118+
91119
#endif /* ! C99 */
92120

93121
#endif /* ! FLEXINT_H */
94122

123+
/* begin standard C++ headers. */
124+
95125
/* TODO: this is always defined, so inline it */
96126
#define yyconst const
97127

@@ -181,7 +211,7 @@ struct yy_buffer_state
181211

182212
int yy_bs_lineno; /**< The line count. */
183213
int yy_bs_column; /**< The column count. */
184-
214+
185215
/* Whether to try to fill the input buffer when we reach the
186216
* end of it.
187217
*/
@@ -218,8 +248,9 @@ void yyfree ( void * , yyscan_t yyscanner );
218248
#ifdef YY_HEADER_EXPORT_START_CONDITIONS
219249
#define INITIAL 0
220250
#define STRING_STATE 1
221-
#define C_COMMENT_STATE 2
222-
#define LINE_COMMENT_STATE 3
251+
#define BLOCK_STRING_STATE 2
252+
#define C_COMMENT_STATE 3
253+
#define LINE_COMMENT_STATE 4
223254

224255
#endif
225256

@@ -344,9 +375,154 @@ extern int yylex \
344375
#undef YY_DECL
345376
#endif
346377

347-
#line 167 "lexer.lpp"
378+
#ifndef yy_create_buffer_ALREADY_DEFINED
379+
#undef yy_create_buffer
380+
#endif
381+
#ifndef yy_delete_buffer_ALREADY_DEFINED
382+
#undef yy_delete_buffer
383+
#endif
384+
#ifndef yy_scan_buffer_ALREADY_DEFINED
385+
#undef yy_scan_buffer
386+
#endif
387+
#ifndef yy_scan_string_ALREADY_DEFINED
388+
#undef yy_scan_string
389+
#endif
390+
#ifndef yy_scan_bytes_ALREADY_DEFINED
391+
#undef yy_scan_bytes
392+
#endif
393+
#ifndef yy_init_buffer_ALREADY_DEFINED
394+
#undef yy_init_buffer
395+
#endif
396+
#ifndef yy_flush_buffer_ALREADY_DEFINED
397+
#undef yy_flush_buffer
398+
#endif
399+
#ifndef yy_load_buffer_state_ALREADY_DEFINED
400+
#undef yy_load_buffer_state
401+
#endif
402+
#ifndef yy_switch_to_buffer_ALREADY_DEFINED
403+
#undef yy_switch_to_buffer
404+
#endif
405+
#ifndef yypush_buffer_state_ALREADY_DEFINED
406+
#undef yypush_buffer_state
407+
#endif
408+
#ifndef yypop_buffer_state_ALREADY_DEFINED
409+
#undef yypop_buffer_state
410+
#endif
411+
#ifndef yyensure_buffer_stack_ALREADY_DEFINED
412+
#undef yyensure_buffer_stack
413+
#endif
414+
#ifndef yylex_ALREADY_DEFINED
415+
#undef yylex
416+
#endif
417+
#ifndef yyrestart_ALREADY_DEFINED
418+
#undef yyrestart
419+
#endif
420+
#ifndef yylex_init_ALREADY_DEFINED
421+
#undef yylex_init
422+
#endif
423+
#ifndef yylex_init_extra_ALREADY_DEFINED
424+
#undef yylex_init_extra
425+
#endif
426+
#ifndef yylex_destroy_ALREADY_DEFINED
427+
#undef yylex_destroy
428+
#endif
429+
#ifndef yyget_debug_ALREADY_DEFINED
430+
#undef yyget_debug
431+
#endif
432+
#ifndef yyset_debug_ALREADY_DEFINED
433+
#undef yyset_debug
434+
#endif
435+
#ifndef yyget_extra_ALREADY_DEFINED
436+
#undef yyget_extra
437+
#endif
438+
#ifndef yyset_extra_ALREADY_DEFINED
439+
#undef yyset_extra
440+
#endif
441+
#ifndef yyget_in_ALREADY_DEFINED
442+
#undef yyget_in
443+
#endif
444+
#ifndef yyset_in_ALREADY_DEFINED
445+
#undef yyset_in
446+
#endif
447+
#ifndef yyget_out_ALREADY_DEFINED
448+
#undef yyget_out
449+
#endif
450+
#ifndef yyset_out_ALREADY_DEFINED
451+
#undef yyset_out
452+
#endif
453+
#ifndef yyget_leng_ALREADY_DEFINED
454+
#undef yyget_leng
455+
#endif
456+
#ifndef yyget_text_ALREADY_DEFINED
457+
#undef yyget_text
458+
#endif
459+
#ifndef yyget_lineno_ALREADY_DEFINED
460+
#undef yyget_lineno
461+
#endif
462+
#ifndef yyset_lineno_ALREADY_DEFINED
463+
#undef yyset_lineno
464+
#endif
465+
#ifndef yyget_column_ALREADY_DEFINED
466+
#undef yyget_column
467+
#endif
468+
#ifndef yyset_column_ALREADY_DEFINED
469+
#undef yyset_column
470+
#endif
471+
#ifndef yywrap_ALREADY_DEFINED
472+
#undef yywrap
473+
#endif
474+
#ifndef yyget_lval_ALREADY_DEFINED
475+
#undef yyget_lval
476+
#endif
477+
#ifndef yyset_lval_ALREADY_DEFINED
478+
#undef yyset_lval
479+
#endif
480+
#ifndef yyget_lloc_ALREADY_DEFINED
481+
#undef yyget_lloc
482+
#endif
483+
#ifndef yyset_lloc_ALREADY_DEFINED
484+
#undef yyset_lloc
485+
#endif
486+
#ifndef yyalloc_ALREADY_DEFINED
487+
#undef yyalloc
488+
#endif
489+
#ifndef yyrealloc_ALREADY_DEFINED
490+
#undef yyrealloc
491+
#endif
492+
#ifndef yyfree_ALREADY_DEFINED
493+
#undef yyfree
494+
#endif
495+
#ifndef yytext_ALREADY_DEFINED
496+
#undef yytext
497+
#endif
498+
#ifndef yyleng_ALREADY_DEFINED
499+
#undef yyleng
500+
#endif
501+
#ifndef yyin_ALREADY_DEFINED
502+
#undef yyin
503+
#endif
504+
#ifndef yyout_ALREADY_DEFINED
505+
#undef yyout
506+
#endif
507+
#ifndef yy_flex_debug_ALREADY_DEFINED
508+
#undef yy_flex_debug
509+
#endif
510+
#ifndef yylineno_ALREADY_DEFINED
511+
#undef yylineno
512+
#endif
513+
#ifndef yytables_fload_ALREADY_DEFINED
514+
#undef yytables_fload
515+
#endif
516+
#ifndef yytables_destroy_ALREADY_DEFINED
517+
#undef yytables_destroy
518+
#endif
519+
#ifndef yyTABLES_NAME_ALREADY_DEFINED
520+
#undef yyTABLES_NAME
521+
#endif
522+
523+
#line 205 "lexer.lpp"
348524

349525

350-
#line 350 "lexer.h"
526+
#line 526 "lexer.h"
351527
#undef yyIN_HEADER
352528
#endif /* yyHEADER_H */

0 commit comments

Comments
 (0)