forked from async-graphql/async-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.pest
51 lines (43 loc) · 2.13 KB
/
query.pest
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
WHITESPACE = _{ " " | "," | "\t" | "\u{feff}" | NEWLINE }
COMMENT = _{ "#" ~ (!"\n" ~ ANY)* }
// value
int = @{ "-"? ~ ("0" | (ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*)) }
float = @{ "-"? ~ int ~ "." ~ ASCII_DIGIT+ ~ exp? }
exp = @{ ("E" | "e") ~ ("+" | "-")? ~ ASCII_DIGIT+ }
singleline_string = @{ "\"" ~ singleline_inner ~ "\"" }
singleline_inner = @{ (!("\"" | "\\") ~ ANY)* ~ (escape ~ singleline_inner)? }
multiline_inner = @{ (!("\"\"\"" | "\\") ~ ANY)* ~ (escape ~ multiline_inner)? }
multiline_string = @{ "\"\"\"" ~ multiline_inner ~ "\"\"\"" }
string = @{ multiline_string | singleline_string }
escape = @{ "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t" | unicode) }
unicode = @{ "u" ~ ASCII_HEX_DIGIT{4} }
boolean = { "true" | "false" }
null = { "null" }
name = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHA | ASCII_DIGIT | "_")* }
variable = { "$" ~ name }
array = { "[" ~ value* ~ "]" }
pair = { name ~ ":" ~ value }
object = { "{" ~ pair* ~ "}" }
value = { object | array | variable | float | int | string | null | boolean | name }
// type
list_type = { "[" ~ type_ ~ "]" }
nonnull_type = { (list_type | name) ~ "!" }
type_ = { nonnull_type | list_type | name }
// query
arguments = { "(" ~ pair* ~ ")" }
directive = { "@" ~ name ~ arguments? }
directives = { directive* }
alias = { name ~ ":" }
field = { alias? ~ name ~ arguments? ~ directives? ~ selection_set? }
fragment_spread = { "..." ~ name ~ directives? }
type_condition = { "on" ~ name }
inline_fragment = { "..." ~ type_condition? ~ directives? ~ selection_set }
selection = { field | inline_fragment | fragment_spread }
selection_set = { "{" ~ selection+ ~ "}" }
operation_type = { "query" | "mutation" | "subscription" }
default_value = { "=" ~ value }
variable_definition = { variable ~ ":" ~ type_ ~ default_value? }
variable_definitions = { "(" ~ variable_definition* ~ ")" }
named_operation_definition = { operation_type ~ name? ~ variable_definitions? ~ directives? ~ selection_set }
fragment_definition = { "fragment" ~ name ~ type_condition ~ directives? ~ selection_set }
document = { SOI ~ (named_operation_definition | selection_set | fragment_definition)+ ~ EOI}