Skip to content

Commit 1167209

Browse files
authored
native erlang parser done (#2)
breacking changes
1 parent 8f6526c commit 1167209

11 files changed

+429
-442
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ erl_crash.dump
1515
logs
1616
_build
1717
.idea
18+
19+
src/graphql_parser_yecc.erl
20+
src/graphql_lexer.erl

Makefile

Lines changed: 0 additions & 9 deletions
This file was deleted.

c_src/graphqlparser.c

Lines changed: 0 additions & 45 deletions
This file was deleted.

c_src/graphqlparser_nif.c

Lines changed: 0 additions & 67 deletions
This file was deleted.

priv/.keep

Whitespace-only changes.

rebar.config

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@
22
{deps, [
33
{jsx, "2.8.1"}
44
]}.
5-
6-
{pre_hooks, [
7-
{"(linux|darwin|solaris)", compile, "make priv/graphql_parser.so"}
8-
]}.

src/graphql_lexer.xrl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
% GraphQL Lexer
2+
%
3+
% See the spec reference http://facebook.github.io/graphql/#sec-Appendix-Grammar-Summary
4+
% The relevant version is also copied into this repo
5+
6+
Definitions.
7+
8+
% Ignored tokens
9+
WhiteSpace = [\x{0009}\x{000B}\x{000C}\x{0020}\x{00A0}]
10+
_LineTerminator = \x{000A}\x{000D}\x{2028}\x{2029}
11+
LineTerminator = [{_LineTerminator}]
12+
Comment = #[^{_LineTerminator}]*
13+
Comma = ,
14+
Ignored = {WhiteSpace}|{LineTerminator}|{Comment}|{Comma}
15+
16+
% Lexical tokens
17+
Punctuator = [!$():=@\[\]{|}]|\.\.\.
18+
Name = [_A-Za-z][_0-9A-Za-z]*
19+
20+
% Int Value
21+
Digit = [0-9]
22+
NonZeroDigit = [1-9]
23+
NegativeSign = -
24+
IntegerPart = {NegativeSign}?(0|{NonZeroDigit}{Digit}*)
25+
IntValue = {IntegerPart}
26+
27+
% Float Value
28+
FractionalPart = \.{Digit}+
29+
Sign = [+\-]
30+
ExponentIndicator = [eE]
31+
ExponentPart = {ExponentIndicator}{Sign}?{Digit}+
32+
FloatValue = {IntegerPart}{FractionalPart}|{IntegerPart}{ExponentPart}|{IntegerPart}{FractionalPart}{ExponentPart}
33+
34+
% String Value
35+
HexDigit = [0-9A-Fa-f]
36+
EscapedUnicode = u{HexDigit}{HexDigit}{HexDigit}{HexDigit}
37+
EscapedCharacter = ["\\\/bfnrt]
38+
StringCharacter = ([^\"{_LineTerminator}]|\\{EscapedUnicode}|\\{EscapedCharacter})
39+
StringValue = "{StringCharacter}*"
40+
41+
% Boolean Value
42+
BooleanValue = true|false
43+
44+
% Reserved words
45+
ReservedWord = query|mutation|fragment|on|type|implements|interface|union|scalar|enum|input|extend|null
46+
47+
Rules.
48+
49+
{Ignored} : skip_token.
50+
{Punctuator} : {token, {list_to_atom(TokenChars), TokenLine}}.
51+
{ReservedWord} : {token, {list_to_atom(TokenChars), TokenLine}}.
52+
{IntValue} : {token, {int_value, TokenLine, TokenChars}}.
53+
{FloatValue} : {token, {float_value, TokenLine, TokenChars}}.
54+
{StringValue} : {token, {string_value, TokenLine, TokenChars}}.
55+
{BooleanValue} : {token, {boolean_value, TokenLine, TokenChars}}.
56+
{Name} : {token, {name, TokenLine, TokenChars}}.
57+
58+
Erlang code.

src/graphql_parser.erl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
]).
88

99

10-
-spec parse(binary()) -> map().
11-
parse(RawGraphqlQuery)->
12-
case graphql_parser_nif:parse(RawGraphqlQuery) of
13-
{ok, Json} -> {ok, jsx:decode(Json, [return_maps])};
14-
{error, Error}-> {error, Error}
15-
end.
10+
-spec parse(binary() | list()) -> map().
11+
parse(Q) when is_binary(Q) ->
12+
ListQ = binary_to_list(Q),
13+
parse_list(ListQ);
14+
parse(Q) when is_list(Q)->
15+
parse_list(Q).
16+
17+
-spec parse_list(list()) -> map().
18+
parse_list(Document)->
19+
{ok, Tokens, _} = graphql_lexer:string(Document),
20+
graphql_parser_yecc:parse(Tokens).

src/graphql_parser_nif.erl

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)