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