Skip to content

Commit d00c3cc

Browse files
author
Thomas Adam
committed
update upstream
1 parent 6ec7a28 commit d00c3cc

11 files changed

+1548
-825
lines changed

cgo_flags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ package graphqlparser
44

55
// #cgo CPPFLAGS: -Iinternal
66
// #cgo CXXFLAGS: -std=c++11 -fPIC -fno-omit-frame-pointer -momit-leaf-frame-pointer
7-
// #cgo CXXFLAGS: -W -Wextra -Wno-deprecated-register -Wno-unused-parameter -Wno-sign-compare
7+
// #cgo CXXFLAGS: -W -Wextra -Wno-deprecated-register -Wno-unused-parameter -Wno-sign-compare -Wno-backslash-newline-escape
88
import "C"

internal/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ libgraphqlparser is BSD-licensed. We also provide an additional patent grant.
6060
## Related Projects
6161

6262
- [graphql-parser (Ruby interface)](https://github.com/Shopify/graphql-parser)
63+
- [py-graphqlparser (Python interface)](https://github.com/elastic-coders/py-graphqlparser)

internal/dump_json_ast.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ int main(int argc, char **argv) {
4242
return 1;
4343
}
4444

45-
puts(graphql_ast_to_json((const struct GraphQLAstNode *)AST.get()));
45+
const char *json = graphql_ast_to_json((const struct GraphQLAstNode *)AST.get());
46+
puts(json);
47+
free((void *)json);
4648

4749
return 0;
4850
}

internal/go/gotest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
package main
1010

1111
/*
12-
#cgo CFLAGS: -I ../c
12+
#cgo CFLAGS: -I ../c -I ..
1313
#cgo LDFLAGS: -L .. -lgraphqlparser
1414
#include "GraphQLAst.h"
1515
#include "GraphQLAstNode.h"

internal/lexer.cpp

+345-246
Large diffs are not rendered by default.

internal/lexer.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ void *yyalloc (yy_size_t ,yyscan_t yyscanner );
212212
void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
213213
void yyfree (void * ,yyscan_t yyscanner );
214214

215+
/* Begin user sect3 */
216+
215217
#define yywrap(n) 1
216218
#define YY_SKIP_YYWRAP
217219

@@ -337,8 +339,9 @@ extern int yylex \
337339
#undef YY_DECL
338340
#endif
339341

340-
#line 126 "lexer.lpp"
342+
#line 155 "lexer.lpp"
343+
341344

342-
#line 343 "lexer.h"
345+
#line 346 "lexer.h"
343346
#undef yyIN_HEADER
344347
#endif /* yyHEADER_H */

internal/lexer.lpp

+125-58
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
%{
1111
#include <cassert>
12+
#include <cctype>
13+
#include <cstdio>
1214
#include <vector>
1315
#include "location.hh"
1416
#include "position.hh"
@@ -18,6 +20,8 @@
1820
// Keep track of token lengths.
1921
#define YY_USER_ACTION yyextra->loc.columns(yyleng);
2022

23+
static void escape(char c, char *buf);
24+
2125
%}
2226

2327
%option bison-bridge bison-locations
@@ -33,10 +37,12 @@ FLOAT -?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?
3337
INTEGER -?(0|[1-9][0-9]*)
3438
IDENTIFIER [_A-Za-z][_0-9A-Za-z]*
3539
VARIABLE $[_0-9A-Za-z]+
40+
BOM \xef\xbb\xbf
41+
CRLF \r\n
42+
BADCHAR [\x00-\x08\x0b\x0c\x0e-\x1f]
43+
STRINGCHAR [^\x00-\x1f\\\x22]
3644

37-
blank [ \t\v\f\xa0,]
38-
/* NOTE: When we do UTF-8, we need to add \u2028
39-
and \u2029 here. */
45+
blank [ \t,]
4046
newline [\n\r]
4147
notnewline [^\n\r]
4248

@@ -46,80 +52,141 @@ notnewline [^\n\r]
4652
yyextra->loc.step();
4753
%}
4854

49-
{blank}+ { yyextra->loc.step(); }
50-
{newline}+ { yyextra->loc.lines(yyleng); yyextra->loc.step(); }
51-
52-
# {yyextra->loc.step(); BEGIN(LINE_COMMENT_STATE); }
53-
54-
<LINE_COMMENT_STATE>{
55-
{newline} { yyextra->loc.step(); BEGIN(INITIAL); }
56-
{notnewline}+ /* eat comment character */
57-
}
58-
59-
false { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FALSE; }
60-
fragment { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FRAGMENT; }
61-
mutation { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_MUTATION; }
62-
null { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_NULL; }
63-
on { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_ON; }
64-
query { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_QUERY; }
65-
true { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_TRUE; }
66-
67-
{INTEGER} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_INTEGER; }
68-
{FLOAT} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FLOAT; }
69-
{IDENTIFIER} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_IDENTIFIER; }
70-
{VARIABLE} { yylval->str = yytext + 1; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_VARIABLE; }
71-
72-
"!" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_BANG; }
73-
"(" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LPAREN; }
74-
")" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RPAREN; }
75-
"..." { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_ELLIPSIS; }
76-
":" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_COLON; }
77-
"=" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_EQUAL; }
78-
"@" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_AT; }
79-
"[" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LBRACKET; }
80-
"]" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RBRACKET; }
81-
"{" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LBRACE; }
82-
"|" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_PIPE; }
83-
"}" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RBRACE; }
84-
85-
86-
<<EOF>> { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_EOF; }
87-
88-
\" {
89-
BEGIN(STRING_STATE);
90-
yyextra->str.clear();
91-
}
92-
9355
<STRING_STATE>{
9456
\" {
9557
BEGIN(INITIAL);
9658
yylval->str = yyextra->str.c_str();
9759
return yy::GraphQLParserImpl::token::TOK_STRING;
9860
}
9961

100-
[^"\\]+ {
62+
{newline} {
63+
throw make_error(yyextra->loc, "Unterminated string");
64+
}
65+
66+
<<EOF>> {
67+
throw make_error(yyextra->loc, "Unterminated string at EOF");
68+
}
69+
70+
{STRINGCHAR}+ {
10171
char *p = yytext;
10272
while (*p) {
10373
yyextra->loc.columns();
10474
yyextra->str.push_back(*p++);
10575
}
10676
}
10777

108-
\\\" { yyextra->loc.columns(); yyextra->str.push_back('"'); }
109-
\\\\ { yyextra->loc.columns(); yyextra->str.push_back('\\'); }
110-
\\\/ { yyextra->loc.columns(); yyextra->str.push_back('/'); }
111-
\\n { yyextra->loc.columns(); yyextra->str.push_back('\n'); }
112-
\\t { yyextra->loc.columns(); yyextra->str.push_back('\t'); }
113-
\\r { yyextra->loc.columns(); yyextra->str.push_back('\r'); }
114-
\\b { yyextra->loc.columns(); yyextra->str.push_back('\b'); }
115-
\\f { yyextra->loc.columns(); yyextra->str.push_back('\f'); }
78+
\\\" { yyextra->str.push_back('"'); }
79+
\\\\ { yyextra->str.push_back('\\'); }
80+
\\\/ { yyextra->str.push_back('/'); }
81+
\\n { yyextra->str.push_back('\n'); }
82+
\\t { yyextra->str.push_back('\t'); }
83+
\\r { yyextra->str.push_back('\r'); }
84+
\\b { yyextra->str.push_back('\b'); }
85+
\\f { yyextra->str.push_back('\f'); }
11686

11787
\\u[0-9A-Fa-f]{4} {
118-
yyextra->loc.columns(6);
11988
int ch;
12089
sscanf(yytext + 1, "%x", &ch);
12190
yyextra->str.push_back(ch);
12291
}
92+
93+
\\u { throw make_error(yyextra->loc, "bad Unicode escape sequence"); }
94+
\\. { throw make_error(yyextra->loc, std::string("bad escape sequence \\") + yytext[1]); }
95+
12396
}
12497

125-
. {throw make_error(yyextra->loc, std::string("unrecognized character ") + yytext[0]); }
98+
<LINE_COMMENT_STATE>{
99+
{CRLF} { yyextra->loc.step(); BEGIN(INITIAL); }
100+
{newline} { yyextra->loc.step(); BEGIN(INITIAL); }
101+
{notnewline}+ /* eat comment character */
102+
}
103+
104+
<INITIAL>{
105+
{blank}+ { yyextra->loc.step(); }
106+
{BOM}+ { yyextra->loc.step(); yyextra->loc.step(); yyextra->loc.step(); }
107+
{CRLF}+ { yyextra->loc.lines(yyleng / 2); yyextra->loc.step(); }
108+
{newline}+ { yyextra->loc.lines(yyleng); yyextra->loc.step(); }
109+
110+
# {yyextra->loc.step(); BEGIN(LINE_COMMENT_STATE); }
111+
112+
false { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FALSE; }
113+
fragment { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FRAGMENT; }
114+
mutation { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_MUTATION; }
115+
null { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_NULL; }
116+
on { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_ON; }
117+
query { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_QUERY; }
118+
true { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_TRUE; }
119+
120+
{INTEGER} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_INTEGER; }
121+
{FLOAT} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FLOAT; }
122+
{IDENTIFIER} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_IDENTIFIER; }
123+
{VARIABLE} { yylval->str = yytext + 1; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_VARIABLE; }
124+
125+
"!" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_BANG; }
126+
"(" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LPAREN; }
127+
")" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RPAREN; }
128+
"..." { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_ELLIPSIS; }
129+
":" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_COLON; }
130+
"=" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_EQUAL; }
131+
"@" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_AT; }
132+
"[" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LBRACKET; }
133+
"]" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RBRACKET; }
134+
"{" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LBRACE; }
135+
"|" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_PIPE; }
136+
"}" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RBRACE; }
137+
138+
139+
<<EOF>> { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_EOF; }
140+
141+
\" {
142+
BEGIN(STRING_STATE);
143+
yyextra->str.clear();
144+
}
145+
}
146+
147+
<INITIAL,STRING_STATE,LINE_COMMENT_STATE>. {
148+
char buf[6];
149+
escape(yytext[0], buf);
150+
throw make_error(
151+
yyextra->loc,
152+
std::string("unrecognized character ") + buf);
153+
}
154+
155+
%%
156+
157+
static void escape(char c, char *buf) {
158+
if (std::isgraph(c)) {
159+
*buf = c;
160+
buf[1] = '\0';
161+
} else {
162+
buf[0] = '\\';
163+
buf[2] = '\0';
164+
switch (c) {
165+
case '\a':
166+
buf[1] = 'a';
167+
break;
168+
case '\b':
169+
buf[1] = 'b';
170+
break;
171+
case '\f':
172+
buf[1] = 'f';
173+
break;
174+
case '\n':
175+
buf[1] = 'n';
176+
break;
177+
case '\r':
178+
buf[1] = 'r';
179+
break;
180+
case '\t':
181+
buf[1] = 't';
182+
break;
183+
case '\v':
184+
buf[1] = 'v';
185+
break;
186+
default:
187+
buf[1] = 'x';
188+
std::snprintf(buf + 2, 3, "%x", ((int)c & 0xFF));
189+
break;
190+
}
191+
}
192+
}

0 commit comments

Comments
 (0)