]> git.ozlabs.org Git - ccan/blob - ccan/graphql/graphql.h
fix warnings
[ccan] / ccan / graphql / graphql.h
1 /* MIT (BSD) license - see LICENSE file for details */
2 #ifndef __GRAPHQL_H__
3 #define __GRAPHQL_H__ 1
4
5 #include <stdio.h>
6
7 #include <ccan/list/list.h>
8 #include <ccan/tal/tal.h>
9
10 // Coding constants
11 #define GRAPHQL_SUCCESS 0
12
13 // The following structures constitute the AST returned by the parser.
14
15 struct graphql_directive {
16         struct graphql_directive *next;
17         struct graphql_token *name;
18         struct graphql_arguments *args;
19 };
20
21 struct graphql_directives {
22         struct graphql_directive *first;
23 };
24
25 struct graphql_named_type {
26         struct graphql_token *name;
27 };
28
29 struct graphql_type {
30         struct graphql_named_type *named;
31 //      struct graphql_list_type *list;
32 //      struct graphql_non_null_type *non_null;
33 };
34
35 struct graphql_default_value {
36         struct graphql_value *val;
37 };
38
39 struct graphql_variable_definition {
40         struct graphql_variable_definition *next;
41         struct graphql_variable *var;
42         struct graphql_type *type;
43         struct graphql_default_value *default_val;
44         struct graphql_directives *directives;
45 };
46
47 struct graphql_variable_definitions {
48         struct graphql_variable_definition *first;
49 };
50
51 struct graphql_variable {
52         struct graphql_token *name;
53 };
54
55 struct graphql_object_field {
56         struct graphql_object_field *next;
57         struct graphql_token *name;
58         struct graphql_value *val;
59 };
60
61 struct graphql_object_value {
62         struct graphql_object_field *first;
63 };
64
65 struct graphql_list_value {
66         struct graphql_token *val;
67 };
68
69 struct graphql_enum_value {
70         struct graphql_token *val;
71 };
72
73 struct graphql_null_value {
74         struct graphql_token *val;
75 };
76
77 struct graphql_string_value {
78         struct graphql_token *val;
79 };
80
81 struct graphql_boolean_value {
82         struct graphql_token *val;
83 };
84
85 struct graphql_float_value {
86         struct graphql_token *val;
87 };
88
89 struct graphql_int_value {
90         struct graphql_token *val;
91 };
92
93 struct graphql_value {
94         struct graphql_variable *var;
95         struct graphql_int_value *int_val;
96         struct graphql_float_value *float_val;
97         struct graphql_boolean_value *bool_val;
98         struct graphql_string_value *str_val;
99         struct graphql_null_value *null_val;
100         struct graphql_enum_value *enum_val;
101         struct graphql_list_value *list_val;
102         struct graphql_object_value *obj_val;
103 };
104
105 struct graphql_inline_fragment {
106         struct graphql_type_condition *type_cond;
107         struct graphql_directives *directives;
108         struct graphql_selection_set *sel_set;
109 };
110
111 struct graphql_type_condition {
112         struct graphql_named_type *named_type;
113 };
114
115 struct graphql_fragment_name {
116         struct graphql_token *name;
117 };
118
119 struct graphql_fragment_definition {
120         struct graphql_fragment_name *name;
121         struct graphql_type_condition *type_cond;
122         struct graphql_directives *directives;
123         struct graphql_selection_set *sel_set;
124 };
125
126 struct graphql_fragment_spread {
127         struct graphql_fragment_name *name;
128         struct graphql_directives *directives;
129 };
130
131 struct graphql_alias {
132         struct graphql_token *name;
133 };
134
135 struct graphql_argument {
136         struct graphql_argument *next;
137         struct graphql_token *name;
138         struct graphql_value *val;
139 };
140
141 struct graphql_arguments {
142         struct graphql_argument *first;
143 };
144
145 struct graphql_field {
146         struct graphql_alias *alias;
147         struct graphql_token *name;
148         struct graphql_arguments *args;
149         struct graphql_directives *directives;
150         struct graphql_selection_set *sel_set;
151 };
152
153 struct graphql_selection {
154         struct graphql_selection *next;
155         struct graphql_field *field;
156         struct graphql_fragment_spread *frag_spread;
157         struct graphql_inline_fragment *inline_frag;
158 };
159
160 struct graphql_selection_set {
161         struct graphql_selection *first;
162 };
163
164 struct graphql_operation_type {
165         struct graphql_token *op_type;
166 };
167
168 struct graphql_operation_definition {
169         struct graphql_operation_type *op_type;
170         struct graphql_token *op_name;
171         struct graphql_variable_definitions *vars;
172         struct graphql_directives *directives;
173         struct graphql_selection_set *sel_set;
174 };
175
176 struct graphql_executable_definition {
177         struct graphql_executable_definition *next_def;
178         struct graphql_operation_definition *op_def;
179         struct graphql_fragment_definition *frag_def;
180 };
181
182 struct graphql_executable_document {
183         struct graphql_executable_definition *first_def;
184 };
185
186 struct graphql_definition {
187         struct graphql_definition *next_def;
188         struct graphql_executable_definition *executable_def;
189         struct graphql_type_system_definition_or_extension *type_system_def;
190 };
191
192 struct graphql_document {
193         struct graphql_definition *first_def;
194 };
195
196
197 struct graphql_token {
198         struct list_node list;
199         unsigned int token_type;
200         unsigned int token_specific;
201         char *token_string;
202         unsigned int source_line;
203         unsigned int source_column;
204         unsigned int source_len;
205 };
206
207 /* The lexer.
208  * INPUTS:
209  *      input - string to parse
210  *      ctx - parent tal context or NULL
211  *      tokens - a variable to receive the resulting token list
212  * RETURN:
213  *      GRAPHQL_SUCCESS or an error string.
214  */
215 const char *graphql_lex(const char *input, const tal_t *ctx, struct list_head **tokens);
216
217 /* The parser.
218  * INPUTS:
219  *      tokens - the list produced by the lexer
220  *      doc - a variable to receive the resulting abstract syntax tree (AST)
221  * RETURN:
222  *      GRAPHQL_SUCCESS or an error string.
223  */
224 const char *graphql_parse(struct list_head *tokens, struct graphql_executable_document **doc);
225
226 /* The lexer and parser in one function, for convenience. */
227 const char *graphql_lexparse(const char *input, const tal_t *ctx, struct list_head **tokens, struct graphql_executable_document **doc);
228
229 #endif
230