Testing building json objects in C
This commit is contained in:
parent
c4caa1bb84
commit
3ded1d2708
@ -118,12 +118,12 @@
|
|||||||
"-x",
|
"-x",
|
||||||
"c",
|
"c",
|
||||||
"-o",
|
"-o",
|
||||||
"/tmp/main-4f432a.o",
|
"/tmp/main-fcfd2b.o",
|
||||||
"src/main.c"
|
"src/main.c"
|
||||||
],
|
],
|
||||||
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
||||||
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/main.c",
|
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/main.c",
|
||||||
"output": "/tmp/main-4f432a.o"
|
"output": "/tmp/main-fcfd2b.o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"arguments": [
|
"arguments": [
|
||||||
@ -187,12 +187,12 @@
|
|||||||
"-x",
|
"-x",
|
||||||
"c",
|
"c",
|
||||||
"-o",
|
"-o",
|
||||||
"/tmp/dstring-841d2e.o",
|
"/tmp/dstring-46186e.o",
|
||||||
"src/dstring/dstring.c"
|
"src/dstring/dstring.c"
|
||||||
],
|
],
|
||||||
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
||||||
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/dstring/dstring.c",
|
"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": [
|
"arguments": [
|
||||||
@ -256,11 +256,11 @@
|
|||||||
"-x",
|
"-x",
|
||||||
"c",
|
"c",
|
||||||
"-o",
|
"-o",
|
||||||
"/tmp/lexer-5cd579.o",
|
"/tmp/lexer-b37823.o",
|
||||||
"src/lexer/lexer.c"
|
"src/lexer/lexer.c"
|
||||||
],
|
],
|
||||||
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
||||||
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/lexer/lexer.c",
|
"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
51
include/json_test.h
Normal 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
|
13
src/main.c
13
src/main.c
@ -35,17 +35,14 @@ int main(int argc, char *argv[]) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
token_t token = get_next_token(lexer, json);
|
token_t token = get_next_token(lexer, json);
|
||||||
while (token.type != TK_NO_TOKEN) {
|
while (token.type != TK_NO_TOKEN) {
|
||||||
print_token(token);
|
print_token(token);
|
||||||
|
|
||||||
token = get_next_token(lexer, NULL);
|
token = get_next_token(lexer, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer_free(&lexer);
|
lexer_free(&lexer);
|
||||||
|
|
||||||
// printf("\n%35s: %s\n", filename, validate_json(json) ? "VALID" :
|
|
||||||
// "INVALID");
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user