Skip to content

Commit

Permalink
update upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Adam committed Oct 17, 2015
1 parent 6ec7a28 commit d00c3cc
Show file tree
Hide file tree
Showing 11 changed files with 1,548 additions and 825 deletions.
2 changes: 1 addition & 1 deletion cgo_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package graphqlparser

// #cgo CPPFLAGS: -Iinternal
// #cgo CXXFLAGS: -std=c++11 -fPIC -fno-omit-frame-pointer -momit-leaf-frame-pointer
// #cgo CXXFLAGS: -W -Wextra -Wno-deprecated-register -Wno-unused-parameter -Wno-sign-compare
// #cgo CXXFLAGS: -W -Wextra -Wno-deprecated-register -Wno-unused-parameter -Wno-sign-compare -Wno-backslash-newline-escape
import "C"
1 change: 1 addition & 0 deletions internal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ libgraphqlparser is BSD-licensed. We also provide an additional patent grant.
## Related Projects

- [graphql-parser (Ruby interface)](https://github.com/Shopify/graphql-parser)
- [py-graphqlparser (Python interface)](https://github.com/elastic-coders/py-graphqlparser)
4 changes: 3 additions & 1 deletion internal/dump_json_ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ int main(int argc, char **argv) {
return 1;
}

puts(graphql_ast_to_json((const struct GraphQLAstNode *)AST.get()));
const char *json = graphql_ast_to_json((const struct GraphQLAstNode *)AST.get());
puts(json);
free((void *)json);

return 0;
}
2 changes: 1 addition & 1 deletion internal/go/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package main

/*
#cgo CFLAGS: -I ../c
#cgo CFLAGS: -I ../c -I ..
#cgo LDFLAGS: -L .. -lgraphqlparser
#include "GraphQLAst.h"
#include "GraphQLAstNode.h"
Expand Down
591 changes: 345 additions & 246 deletions internal/lexer.cpp

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions internal/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ void *yyalloc (yy_size_t ,yyscan_t yyscanner );
void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
void yyfree (void * ,yyscan_t yyscanner );

/* Begin user sect3 */

#define yywrap(n) 1
#define YY_SKIP_YYWRAP

Expand Down Expand Up @@ -337,8 +339,9 @@ extern int yylex \
#undef YY_DECL
#endif

#line 126 "lexer.lpp"
#line 155 "lexer.lpp"


#line 343 "lexer.h"
#line 346 "lexer.h"
#undef yyIN_HEADER
#endif /* yyHEADER_H */
183 changes: 125 additions & 58 deletions internal/lexer.lpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

%{
#include <cassert>
#include <cctype>
#include <cstdio>
#include <vector>
#include "location.hh"
#include "position.hh"
Expand All @@ -18,6 +20,8 @@
// Keep track of token lengths.
#define YY_USER_ACTION yyextra->loc.columns(yyleng);

static void escape(char c, char *buf);

%}

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

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

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

{blank}+ { yyextra->loc.step(); }
{newline}+ { yyextra->loc.lines(yyleng); yyextra->loc.step(); }

# {yyextra->loc.step(); BEGIN(LINE_COMMENT_STATE); }

<LINE_COMMENT_STATE>{
{newline} { yyextra->loc.step(); BEGIN(INITIAL); }
{notnewline}+ /* eat comment character */
}

false { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FALSE; }
fragment { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FRAGMENT; }
mutation { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_MUTATION; }
null { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_NULL; }
on { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_ON; }
query { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_QUERY; }
true { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_TRUE; }

{INTEGER} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_INTEGER; }
{FLOAT} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FLOAT; }
{IDENTIFIER} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_IDENTIFIER; }
{VARIABLE} { yylval->str = yytext + 1; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_VARIABLE; }

"!" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_BANG; }
"(" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LPAREN; }
")" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RPAREN; }
"..." { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_ELLIPSIS; }
":" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_COLON; }
"=" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_EQUAL; }
"@" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_AT; }
"[" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LBRACKET; }
"]" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RBRACKET; }
"{" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LBRACE; }
"|" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_PIPE; }
"}" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RBRACE; }


<<EOF>> { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_EOF; }

\" {
BEGIN(STRING_STATE);
yyextra->str.clear();
}

<STRING_STATE>{
\" {
BEGIN(INITIAL);
yylval->str = yyextra->str.c_str();
return yy::GraphQLParserImpl::token::TOK_STRING;
}

[^"\\]+ {
{newline} {
throw make_error(yyextra->loc, "Unterminated string");
}

<<EOF>> {
throw make_error(yyextra->loc, "Unterminated string at EOF");
}

{STRINGCHAR}+ {
char *p = yytext;
while (*p) {
yyextra->loc.columns();
yyextra->str.push_back(*p++);
}
}

\\\" { yyextra->loc.columns(); yyextra->str.push_back('"'); }
\\\\ { yyextra->loc.columns(); yyextra->str.push_back('\\'); }
\\\/ { yyextra->loc.columns(); yyextra->str.push_back('/'); }
\\n { yyextra->loc.columns(); yyextra->str.push_back('\n'); }
\\t { yyextra->loc.columns(); yyextra->str.push_back('\t'); }
\\r { yyextra->loc.columns(); yyextra->str.push_back('\r'); }
\\b { yyextra->loc.columns(); yyextra->str.push_back('\b'); }
\\f { yyextra->loc.columns(); yyextra->str.push_back('\f'); }
\\\" { yyextra->str.push_back('"'); }
\\\\ { yyextra->str.push_back('\\'); }
\\\/ { yyextra->str.push_back('/'); }
\\n { yyextra->str.push_back('\n'); }
\\t { yyextra->str.push_back('\t'); }
\\r { yyextra->str.push_back('\r'); }
\\b { yyextra->str.push_back('\b'); }
\\f { yyextra->str.push_back('\f'); }

\\u[0-9A-Fa-f]{4} {
yyextra->loc.columns(6);
int ch;
sscanf(yytext + 1, "%x", &ch);
yyextra->str.push_back(ch);
}

\\u { throw make_error(yyextra->loc, "bad Unicode escape sequence"); }
\\. { throw make_error(yyextra->loc, std::string("bad escape sequence \\") + yytext[1]); }

}

. {throw make_error(yyextra->loc, std::string("unrecognized character ") + yytext[0]); }
<LINE_COMMENT_STATE>{
{CRLF} { yyextra->loc.step(); BEGIN(INITIAL); }
{newline} { yyextra->loc.step(); BEGIN(INITIAL); }
{notnewline}+ /* eat comment character */
}

<INITIAL>{
{blank}+ { yyextra->loc.step(); }
{BOM}+ { yyextra->loc.step(); yyextra->loc.step(); yyextra->loc.step(); }
{CRLF}+ { yyextra->loc.lines(yyleng / 2); yyextra->loc.step(); }
{newline}+ { yyextra->loc.lines(yyleng); yyextra->loc.step(); }

# {yyextra->loc.step(); BEGIN(LINE_COMMENT_STATE); }

false { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FALSE; }
fragment { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FRAGMENT; }
mutation { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_MUTATION; }
null { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_NULL; }
on { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_ON; }
query { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_QUERY; }
true { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_TRUE; }

{INTEGER} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_INTEGER; }
{FLOAT} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_FLOAT; }
{IDENTIFIER} { yylval->str = yytext; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_IDENTIFIER; }
{VARIABLE} { yylval->str = yytext + 1; *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_VARIABLE; }

"!" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_BANG; }
"(" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LPAREN; }
")" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RPAREN; }
"..." { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_ELLIPSIS; }
":" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_COLON; }
"=" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_EQUAL; }
"@" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_AT; }
"[" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LBRACKET; }
"]" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RBRACKET; }
"{" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_LBRACE; }
"|" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_PIPE; }
"}" { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_RBRACE; }


<<EOF>> { *yylloc = yyextra->loc; return yy::GraphQLParserImpl::token::TOK_EOF; }

\" {
BEGIN(STRING_STATE);
yyextra->str.clear();
}
}

<INITIAL,STRING_STATE,LINE_COMMENT_STATE>. {
char buf[6];
escape(yytext[0], buf);
throw make_error(
yyextra->loc,
std::string("unrecognized character ") + buf);
}

%%

static void escape(char c, char *buf) {
if (std::isgraph(c)) {
*buf = c;
buf[1] = '\0';
} else {
buf[0] = '\\';
buf[2] = '\0';
switch (c) {
case '\a':
buf[1] = 'a';
break;
case '\b':
buf[1] = 'b';
break;
case '\f':
buf[1] = 'f';
break;
case '\n':
buf[1] = 'n';
break;
case '\r':
buf[1] = 'r';
break;
case '\t':
buf[1] = 't';
break;
case '\v':
buf[1] = 'v';
break;
default:
buf[1] = 'x';
std::snprintf(buf + 2, 3, "%x", ((int)c & 0xFF));
break;
}
}
}
Loading

0 comments on commit d00c3cc

Please sign in to comment.