6 * graphql - Routines to lex and parse GraphQL.
8 * This code contains routines to lex and parse GraphQL code.
9 * This code was written per the spec at:
10 * https://spec.graphql.org/draft/
11 * ...dated Fri, May 21, 2021 at the time of writing.
12 * Copyright (c) 2021 WhiteCloudFarm.org <robert.lee.dickinson@gmail.com>
13 * <https://github.com/rl-d/ccan>
17 * int main(int argc, char *argv[]) {
19 * const char *input_string = "{ fieldName }";
20 * struct list_head *output_tokens;
21 * struct graphql_executable_document *output_document;
23 * const char *errmsg = graphql_lexparse(
25 * NULL, // tal context
26 * &output_tokens, // variable to receive tokens
27 * &output_document); // variable to receive AST
30 * struct graphql_token *last_token;
31 * last_token = list_tail(output_tokens, struct graphql_token, list);
32 * printf("Line %d, col %d: %s",
33 * last_token->source_line,
34 * last_token->source_column + last_token->source_len,
37 * // Normally you would check every indirection in the resulting AST for null
38 * // pointers, but for simplicity of example:
39 * printf("A field from the parsed string: %s\n",
40 * output_document->first_def->op_def->sel_set->
41 * first->field->name->token_string);
44 * output_tokens = tal_free(output_tokens);
49 int main(int argc, char *argv[])
51 /* Expect exactly one argument */
55 if (strcmp(argv[1], "depends") == 0) {
56 printf("ccan/list\n");
59 printf("ccan/tal/str\n");
60 printf("ccan/utf8\n");