aboutsummaryrefslogtreecommitdiff
path: root/src/json-gram.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/json-gram.y')
-rw-r--r--src/json-gram.y76
1 files changed, 38 insertions, 38 deletions
diff --git a/src/json-gram.y b/src/json-gram.y
index fe8996b..4f7da29 100644
--- a/src/json-gram.y
+++ b/src/json-gram.y
@@ -18,12 +18,12 @@
18#ifdef HAVE_CONFIG_H 18#ifdef HAVE_CONFIG_H
19# include <config.h> 19# include <config.h>
20#endif 20#endif
21#include "grecs.h" 21#include "argot.h"
22#include <string.h> 22#include <string.h>
23#include <errno.h> 23#include <errno.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include "json-gram.h" 25#include "json-gram.h"
26#include "grecs/json.h" 26#include "argot/json.h"
27 27
28struct json_value *json_return_obj; 28struct json_value *json_return_obj;
29 29
@@ -34,7 +34,7 @@ static void
34pairfree(void *ptr) 34pairfree(void *ptr)
35{ 35{
36 struct json_pair *p = ptr; 36 struct json_pair *p = ptr;
37 grecs_free(p->k); 37 argot_free(p->k);
38 json_value_free(p->v); 38 json_value_free(p->v);
39 free(p); 39 free(p);
40} 40}
@@ -65,9 +65,9 @@ objfree(void *ptr)
65 int b; 65 int b;
66 double n; 66 double n;
67 char *s; 67 char *s;
68 struct grecs_symtab *o; 68 struct argot_symtab *o;
69 struct json_value *obj; 69 struct json_value *obj;
70 struct grecs_list *list; 70 struct argot_list *list;
71 struct json_pair *p; 71 struct json_pair *p;
72} 72}
73%% 73%%
@@ -121,32 +121,32 @@ objects : /* empty */
121 121
122objlist : object 122objlist : object
123 { 123 {
124 $$ = grecs_list_create(); 124 $$ = argot_list_create();
125 grecs_list_append($$, $1); 125 argot_list_append($$, $1);
126 } 126 }
127 | objlist ',' object 127 | objlist ',' object
128 { 128 {
129 grecs_list_append($1, $3); 129 argot_list_append($1, $3);
130 } 130 }
131 ; 131 ;
132 132
133assoc : '{' pairs '}' 133assoc : '{' pairs '}'
134 { 134 {
135 struct grecs_symtab *s; 135 struct argot_symtab *s;
136 136
137 s = json_assoc_create(); 137 s = json_assoc_create();
138 if ($2) { 138 if ($2) {
139 struct grecs_list_entry *ep; 139 struct argot_list_entry *ep;
140 for (ep = $2->head; ep; ep = ep->next) { 140 for (ep = $2->head; ep; ep = ep->next) {
141 struct json_pair *p = ep->data; 141 struct json_pair *p = ep->data;
142 int install = 1; 142 int install = 1;
143 grecs_symtab_lookup_or_install(s, p, &install); 143 argot_symtab_lookup_or_install(s, p, &install);
144 if (install) { 144 if (install) {
145 p->k = NULL; 145 p->k = NULL;
146 p->v = NULL; 146 p->v = NULL;
147 } 147 }
148 } 148 }
149 grecs_list_free($2); 149 argot_list_free($2);
150 } 150 }
151 $$ = s; 151 $$ = s;
152 } 152 }
@@ -161,19 +161,19 @@ pairs : /* empty */
161 161
162pairlist: pair 162pairlist: pair
163 { 163 {
164 $$ = grecs_list_create(); 164 $$ = argot_list_create();
165 $$->free_entry = pairfree; 165 $$->free_entry = pairfree;
166 grecs_list_append($$, $1); 166 argot_list_append($$, $1);
167 } 167 }
168 | pairlist ',' pair 168 | pairlist ',' pair
169 { 169 {
170 grecs_list_append($1, $3); 170 argot_list_append($1, $3);
171 } 171 }
172 ; 172 ;
173 173
174pair : T_STRING ':' object 174pair : T_STRING ':' object
175 { 175 {
176 struct json_pair *p = grecs_malloc(sizeof(*p)); 176 struct json_pair *p = argot_malloc(sizeof(*p));
177 p->k = $1; 177 p->k = $1;
178 p->v = $3; 178 p->v = $3;
179 $$ = p; 179 $$ = p;
@@ -191,7 +191,7 @@ yyerror(char const *s)
191struct json_value * 191struct json_value *
192json_value_create(int type) 192json_value_create(int type)
193{ 193{
194 struct json_value *obj = grecs_zalloc(sizeof(*obj)); 194 struct json_value *obj = argot_zalloc(sizeof(*obj));
195 obj->type = type; 195 obj->type = type;
196 return obj; 196 return obj;
197} 197}
@@ -210,20 +210,20 @@ json_value_free(struct json_value *obj)
210 case json_number: 210 case json_number:
211 break; 211 break;
212 case json_string: 212 case json_string:
213 grecs_free(obj->v.s); 213 argot_free(obj->v.s);
214 break; 214 break;
215 case json_arr: 215 case json_arr:
216 for (i = 0; i < obj->v.a->oc; i++) 216 for (i = 0; i < obj->v.a->oc; i++)
217 json_value_free(obj->v.a->ov[i]); 217 json_value_free(obj->v.a->ov[i]);
218 grecs_free (obj->v.a->ov); 218 argot_free (obj->v.a->ov);
219 if (obj->v.a->ol) { 219 if (obj->v.a->ol) {
220 obj->v.a->ol->free_entry = objfree; 220 obj->v.a->ol->free_entry = objfree;
221 grecs_list_free(obj->v.a->ol); 221 argot_list_free(obj->v.a->ol);
222 } 222 }
223 grecs_free(obj->v.a); 223 argot_free(obj->v.a);
224 break; 224 break;
225 case json_object: 225 case json_object:
226 grecs_symtab_free(obj->v.o); 226 argot_symtab_free(obj->v.o);
227 } 227 }
228 free(obj); 228 free(obj);
229} 229}
@@ -232,7 +232,7 @@ static unsigned
232json_st_hash(void *data, unsigned long n_buckets) 232json_st_hash(void *data, unsigned long n_buckets)
233{ 233{
234 struct json_pair *p = data; 234 struct json_pair *p = data;
235 return grecs_hash_string(p->k, n_buckets); 235 return argot_hash_string(p->k, n_buckets);
236} 236}
237 237
238static int 238static int
@@ -261,10 +261,10 @@ json_st_free(void *ptr)
261 free(p); 261 free(p);
262} 262}
263 263
264struct grecs_symtab * 264struct argot_symtab *
265json_assoc_create() 265json_assoc_create()
266{ 266{
267 return grecs_symtab_create(sizeof(struct json_pair), 267 return argot_symtab_create(sizeof(struct json_pair),
268 json_st_hash, 268 json_st_hash,
269 json_st_cmp, 269 json_st_cmp,
270 json_st_copy, 270 json_st_copy,
@@ -303,7 +303,7 @@ json_value_lookup(struct json_value *obj, const char *ident)
303 l = p - ident + 1; 303 l = p - ident + 1;
304 if (l > qlen) { 304 if (l > qlen) {
305 qlen = l; 305 qlen = l;
306 qbuf = grecs_realloc(qbuf, qlen); 306 qbuf = argot_realloc(qbuf, qlen);
307 } 307 }
308 q = qbuf; 308 q = qbuf;
309 while (*ident) { 309 while (*ident) {
@@ -349,7 +349,7 @@ struct json_value *
349json_new_string(char const *str) 349json_new_string(char const *str)
350{ 350{
351 struct json_value *j = json_value_create(json_string); 351 struct json_value *j = json_value_create(json_string);
352 j->v.s = grecs_strdup(str); 352 j->v.s = argot_strdup(str);
353 return j; 353 return j;
354} 354}
355 355
@@ -395,9 +395,9 @@ json_object_set(struct json_value *obj, char const *name,
395 } 395 }
396 pair.k = (char*) name; 396 pair.k = (char*) name;
397 pair.v = NULL; 397 pair.v = NULL;
398 ret = grecs_symtab_lookup_or_install(obj->v.o, &pair, &install); 398 ret = argot_symtab_lookup_or_install(obj->v.o, &pair, &install);
399 if (install) 399 if (install)
400 ret->k = grecs_strdup(ret->k); 400 ret->k = argot_strdup(ret->k);
401 ret->v = val; 401 ret->v = val;
402 return 0; 402 return 0;
403} 403}
@@ -413,7 +413,7 @@ json_object_get(struct json_value *obj, char const *name,
413 } 413 }
414 pair.k = (char*) name; 414 pair.k = (char*) name;
415 pair.v = NULL; 415 pair.v = NULL;
416 ret = grecs_symtab_lookup_or_install(obj->v.o, &pair, NULL); 416 ret = argot_symtab_lookup_or_install(obj->v.o, &pair, NULL);
417 if (ret) {