]> git.ozlabs.org Git - ccan/blob - ccan/graphql/_info
efdb6a1395d78d7500c4bfaf52b82b000ee47520
[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  *      #include <stdio.h>
17  *      #include "ccan/graphql/graphql.h"
18  *      
19  *      int main(int argc, char *argv[])
20  *      
21  *              const char *input_string = "{ fieldName }";
22  *              struct list_head *output_tokens;
23  *              struct graphql_executable_document *output_document;
24  *      
25  *              const char *errmsg = graphql_lexparse(
26  *                      input_string,
27  *                      NULL, // tal context
28  *                      &output_tokens, // variable to receive tokens
29  *                      &output_document); // variable to receive AST
30  *      
31  *              if (errmsg) {
32  *                      struct graphql_token *last_token;
33  *                      last_token = list_tail(output_tokens, struct graphql_token, list);
34  *                      printf("Line %d, col %d: %s",
35  *                              last_token->source_line,
36  *                              last_token->source_column + last_token->source_len,
37  *                              errmsg);
38  *              } else {
39  *                      // Normally you would check every indirection in the resulting AST for null
40  *                      // pointers, but for simplicity of example:
41  *                      printf("A field from the parsed string: %s\n",
42  *                              output_document->first_def->op_def->sel_set->
43  *                              first->field->name->token_string);
44  *              }
45  *      
46  *              output_tokens = tal_free(output_tokens);
47  *      }
48  *
49  * License: BSD-MIT
50  */
51 int main(int argc, char *argv[])
52 {
53         /* Expect exactly one argument */
54         if (argc != 2)
55                 return 1;
56
57         if (strcmp(argv[1], "depends") == 0) {
58                 printf("ccan/list\n");
59                 printf("ccan/take\n");
60                 printf("ccan/tal\n");
61                 printf("ccan/tal/str\n");
62                 printf("ccan/utf8\n");
63                 return 0;
64         }
65
66         return 1;
67 }
68