]> git.ozlabs.org Git - ccan/blob - ccan/graphql/_info
fix warnings
[ccan] / ccan / graphql / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * graphql - Routines to lex and parse GraphQL.
7  *
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>
14  * 
15  * Example:
16  *      
17  *      int main(int argc, char *argv[]) {
18  *      
19  *              const char *input_string = "{ fieldName }";
20  *              struct list_head *output_tokens;
21  *              struct graphql_executable_document *output_document;
22  *      
23  *              const char *errmsg = graphql_lexparse(
24  *                      input_string,
25  *                      NULL, // tal context
26  *                      &output_tokens, // variable to receive tokens
27  *                      &output_document); // variable to receive AST
28  *      
29  *              if (errmsg) {
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,
35  *                              errmsg);
36  *              } else {
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);
42  *              }
43  *      
44  *              output_tokens = tal_free(output_tokens);
45  *      }
46  *
47  * License: BSD-MIT
48  */
49 int main(int argc, char *argv[])
50 {
51         /* Expect exactly one argument */
52         if (argc != 2)
53                 return 1;
54
55         if (strcmp(argv[1], "depends") == 0) {
56                 printf("ccan/list\n");
57                 printf("ccan/str\n");
58                 printf("ccan/tal\n");
59                 printf("ccan/tal/str\n");
60                 printf("ccan/utf8\n");
61                 return 0;
62         }
63
64         return 1;
65 }
66