Testing building json objects in C

This commit is contained in:
Abdelrahman Said 2023-06-25 23:52:45 +01:00
parent c4caa1bb84
commit 3ded1d2708
3 changed files with 62 additions and 14 deletions

View File

@ -118,12 +118,12 @@
"-x",
"c",
"-o",
"/tmp/main-4f432a.o",
"/tmp/main-fcfd2b.o",
"src/main.c"
],
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/main.c",
"output": "/tmp/main-4f432a.o"
"output": "/tmp/main-fcfd2b.o"
},
{
"arguments": [
@ -187,12 +187,12 @@
"-x",
"c",
"-o",
"/tmp/dstring-841d2e.o",
"/tmp/dstring-46186e.o",
"src/dstring/dstring.c"
],
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/dstring/dstring.c",
"output": "/tmp/dstring-841d2e.o"
"output": "/tmp/dstring-46186e.o"
},
{
"arguments": [
@ -256,11 +256,11 @@
"-x",
"c",
"-o",
"/tmp/lexer-5cd579.o",
"/tmp/lexer-b37823.o",
"src/lexer/lexer.c"
],
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/lexer/lexer.c",
"output": "/tmp/lexer-5cd579.o"
"output": "/tmp/lexer-b37823.o"
}
]

51
include/json_test.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef JSON_TEST_H
#define JSON_TEST_H
#include "aliases.h"
#include <stdbool.h>
typedef struct json_obj_pair jobj_pair_t;
typedef struct json_coll jcoll_t;
typedef struct json_val jval_t;
typedef enum {
JSON_OBJECT,
JSON_ARRAY,
} jcoll_type_t;
typedef enum {
JSON_COLLECTION,
JSON_STRING,
JSON_INTEGER,
JSON_DOUBLE,
JSON_TRUE,
JSON_FALSE,
JSON_NULL,
} jval_type_t;
struct json_val {
jval_type_t type;
union {
jcoll_t *collection;
const char *string;
i64 num_int;
f64 num_dbl;
bool boolean;
};
};
struct json_obj_pair {
const char *key;
jval_t value;
};
struct json_coll {
jcoll_type_t type;
u64 size;
union {
jobj_pair_t pairs[50];
jval_t items[50];
};
};
#endif // !JSON_TEST_H

View File

@ -35,17 +35,14 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
token_t token = get_next_token(lexer, json);
while (token.type != TK_NO_TOKEN) {
print_token(token);
token_t token = get_next_token(lexer, json);
while (token.type != TK_NO_TOKEN) {
print_token(token);
token = get_next_token(lexer, NULL);
}
token = get_next_token(lexer, NULL);
}
lexer_free(&lexer);
// printf("\n%35s: %s\n", filename, validate_json(json) ? "VALID" :
// "INVALID");
return EXIT_SUCCESS;
}