2 #define __GRAPHQL_H__ 1
6 #include <ccan/list/list.h>
7 #include <ccan/tal/tal.h>
10 #define GRAPHQL_SUCCESS 0
12 // The following structures constitute the AST returned by the parser.
14 struct graphql_directive {
15 struct graphql_directive *next;
16 struct graphql_token *name;
17 struct graphql_arguments *args;
20 struct graphql_directives {
21 struct graphql_directive *first;
24 struct graphql_named_type {
25 struct graphql_token *name;
29 struct graphql_named_type *named;
30 // struct graphql_list_type *list;
31 // struct graphql_non_null_type *non_null;
34 struct graphql_default_value {
35 struct graphql_value *val;
38 struct graphql_variable_definition {
39 struct graphql_variable_definition *next;
40 struct graphql_variable *var;
41 struct graphql_type *type;
42 struct graphql_default_value *default_val;
43 struct graphql_directives *directives;
46 struct graphql_variable_definitions {
47 struct graphql_variable_definition *first;
50 struct graphql_variable {
51 struct graphql_token *name;
54 struct graphql_object_field {
55 struct graphql_object_field *next;
56 struct graphql_token *name;
57 struct graphql_value *val;
60 struct graphql_object_value {
61 struct graphql_object_field *first;
64 struct graphql_list_value {
65 struct graphql_token *val;
68 struct graphql_enum_value {
69 struct graphql_token *val;
72 struct graphql_null_value {
73 struct graphql_token *val;
76 struct graphql_string_value {
77 struct graphql_token *val;
80 struct graphql_boolean_value {
81 struct graphql_token *val;
84 struct graphql_float_value {
85 struct graphql_token *val;
88 struct graphql_int_value {
89 struct graphql_token *val;
92 struct graphql_value {
93 struct graphql_variable *var;
94 struct graphql_int_value *int_val;
95 struct graphql_float_value *float_val;
96 struct graphql_boolean_value *bool_val;
97 struct graphql_string_value *str_val;
98 struct graphql_null_value *null_val;
99 struct graphql_enum_value *enum_val;
100 struct graphql_list_value *list_val;
101 struct graphql_object_value *obj_val;
104 struct graphql_inline_fragment {
105 struct graphql_type_condition *type_cond;
106 struct graphql_directives *directives;
107 struct graphql_selection_set *sel_set;
110 struct graphql_type_condition {
111 struct graphql_named_type *named_type;
114 struct graphql_fragment_name {
115 struct graphql_token *name;
118 struct graphql_fragment_definition {
119 struct graphql_fragment_name *name;
120 struct graphql_type_condition *type_cond;
121 struct graphql_directives *directives;
122 struct graphql_selection_set *sel_set;
125 struct graphql_fragment_spread {
126 struct graphql_fragment_name *name;
127 struct graphql_directives *directives;
130 struct graphql_alias {
131 struct graphql_token *name;
134 struct graphql_argument {
135 struct graphql_argument *next;
136 struct graphql_token *name;
137 struct graphql_value *val;
140 struct graphql_arguments {
141 struct graphql_argument *first;
144 struct graphql_field {
145 struct graphql_alias *alias;
146 struct graphql_token *name;
147 struct graphql_arguments *args;
148 struct graphql_directives *directives;
149 struct graphql_selection_set *sel_set;
152 struct graphql_selection {
153 struct graphql_selection *next;
154 struct graphql_field *field;
155 struct graphql_fragment_spread *frag_spread;
156 struct graphql_inline_fragment *inline_frag;
159 struct graphql_selection_set {
160 struct graphql_selection *first;
163 struct graphql_operation_type {
164 struct graphql_token *op_type;
167 struct graphql_operation_definition {
168 struct graphql_operation_type *op_type;
169 struct graphql_token *op_name;
170 struct graphql_variable_definitions *vars;
171 struct graphql_directives *directives;
172 struct graphql_selection_set *sel_set;
175 struct graphql_executable_definition {
176 struct graphql_executable_definition *next_def;
177 struct graphql_operation_definition *op_def;
178 struct graphql_fragment_definition *frag_def;
181 struct graphql_executable_document {
182 struct graphql_executable_definition *first_def;
185 struct graphql_definition {
186 struct graphql_definition *next_def;
187 struct graphql_executable_definition *executable_def;
188 struct graphql_type_system_definition_or_extension *type_system_def;
191 struct graphql_document {
192 struct graphql_definition *first_def;
196 struct graphql_token {
197 struct list_node list;
198 unsigned int token_type;
199 unsigned int token_specific;
201 unsigned int source_line;
202 unsigned int source_column;
203 unsigned int source_len;
208 * input - string to parse
209 * ctx - parent tal context or NULL
210 * tokens - a variable to receive the resulting token list
212 * GRAPHQL_SUCCESS or an error string.
214 const char *graphql_lex(const char *input, const tal_t *ctx, struct list_head **tokens);
218 * tokens - the list produced by the lexer
219 * doc - a variable to receive the resulting abstract syntax tree (AST)
221 * GRAPHQL_SUCCESS or an error string.
223 const char *graphql_parse(struct list_head *tokens, struct graphql_executable_document **doc);
225 /* The lexer and parser in one function, for convenience. */
226 const char *graphql_lexparse(const char *input, const tal_t *ctx, struct list_head **tokens, struct graphql_executable_document **doc);