|
| 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. |
0 commit comments