aboutsummaryrefslogtreecommitdiff
path: root/include/argot/json.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/argot/json.h')
-rw-r--r--include/argot/json.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/include/argot/json.h b/include/argot/json.h
new file mode 100644
index 0000000..f453ecf
--- /dev/null
+++ b/include/argot/json.h
@@ -0,0 +1,99 @@
1/* This file is part of Grecs.
2 Copyright (C) 2012-2016 Sergey Poznyakoff.
3
4 Grecs is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Grecs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Grecs. If not, see <http://www.gnu.org/licenses/>. */
16
17#include <argot.h>
18
19enum json_value_type
20{
21 json_null,
22 json_bool,
23 json_number,
24 json_string,
25 json_arr,
26 json_object
27};
28
29struct json_value;
30struct json_array {
31 size_t oc;
32 struct json_value **ov;
33 struct argot_list *ol;
34};
35
36struct json_value {
37 enum json_value_type type;
38 union {
39 int b; /* json_bool */
40 double n; /* json_number */
41 char *s; /* json_string */
42 struct json_array *a; /* json_arr */
43 struct argot_symtab *o; /* json_object */
44 } v;
45};
46
47struct json_pair {
48 char *k;
49 struct json_value *v;
50};
51
52extern char const *json_err_diag;
53extern struct argot_locus json_err_locus;
54extern struct json_value *json_return_obj;
55
56void jsonlex_setup(char const *s, size_t l);
57void jsonlex_diag(const char *s);
58int json_unescape(char c, char *o);
59
60struct json_value *json_value_create(int type);
61struct argot_symtab *json_assoc_create(void);
62void json_value_free(struct json_value *obj);
63
64struct json_value *json_parse_string(char const *input, size_t len);
65
66struct json_value *json_value_lookup(struct json_value *obj,
67 const char *ident);
68
69
70struct json_format
71{
72 size_t indent;
73 int precision;
74 void (*write) (void *, char const *, size_t);
75 void *data;
76};
77
78void json_format_value(struct json_value *obj, struct json_format *fmt);
79
80struct json_value *json_new_null(void);
81struct json_value *json_new_bool(int b);
82struct json_value *json_new_number(double n);
83struct json_value *json_new_string(char const *str);
84
85struct json_value *json_new_object(void);
86int json_object_set(struct json_value *obj, char const *name,
87 struct json_value *val);
88int json_object_get(struct json_value *obj, char const *name,
89 struct json_value **retval);
90
91struct json_value *json_new_array(void);
92size_t json_array_size(struct json_value *j);
93void json_array_flatten(struct json_value *j);
94int json_array_insert(struct json_value *j, size_t idx, struct json_value *v);
95int json_array_append(struct json_value *j, struct json_value *v);
96int json_array_set(struct json_value *j, size_t idx, struct json_value *v);
97int json_array_get(struct json_value *j, size_t idx,
98 struct json_value **retval);
99

Return to:

Send suggestions and report system problems to the System administrator.