Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 207e405d34 | |||
| 6b2fe4089e | |||
| 148dde19a6 | |||
| ead04f9c08 |
@@ -17,3 +17,4 @@ jobs:
|
|||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y gcc make libcriterion-dev valgrind
|
sudo apt-get install -y gcc make libcriterion-dev valgrind
|
||||||
- run: make test
|
- run: make test
|
||||||
|
# TODO: fucking run the test...
|
||||||
|
|||||||
@@ -327,6 +327,62 @@ bool scanner_print_errors(scanner_t *s, FILE *fp);
|
|||||||
bool looks_like_float(scanner_t *s);
|
bool looks_like_float(scanner_t *s);
|
||||||
bool looks_like_int(scanner_t *s);
|
bool looks_like_int(scanner_t *s);
|
||||||
|
|
||||||
|
// json parser /////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
typedef enum json_type {
|
||||||
|
json_type_array,
|
||||||
|
json_type_boolean,
|
||||||
|
json_type_null,
|
||||||
|
json_type_number,
|
||||||
|
json_type_object,
|
||||||
|
json_type_string,
|
||||||
|
count_json_type_t
|
||||||
|
} json_type_t;
|
||||||
|
|
||||||
|
typedef struct json_string {
|
||||||
|
const char *buffer;
|
||||||
|
size_t length;
|
||||||
|
} json_string_t;
|
||||||
|
|
||||||
|
struct json_pair;
|
||||||
|
|
||||||
|
typedef struct json_object {
|
||||||
|
struct json_pair *pairs;
|
||||||
|
size_t length;
|
||||||
|
} json_object_t;
|
||||||
|
|
||||||
|
struct json_value;
|
||||||
|
|
||||||
|
typedef struct json_array {
|
||||||
|
struct json_value *values;
|
||||||
|
size_t length;
|
||||||
|
} json_array_t;
|
||||||
|
|
||||||
|
typedef struct json_value {
|
||||||
|
json_type_t type;
|
||||||
|
union {
|
||||||
|
bool boolean;
|
||||||
|
double number;
|
||||||
|
json_object_t object;
|
||||||
|
json_array_t array;
|
||||||
|
json_string_t string;
|
||||||
|
};
|
||||||
|
} json_value_t;
|
||||||
|
|
||||||
|
typedef struct json_pair {
|
||||||
|
json_string_t key;
|
||||||
|
json_value_t value;
|
||||||
|
} json_pair_t;
|
||||||
|
|
||||||
|
bool json_as_array(json_value_t *value, json_array_t *array);
|
||||||
|
bool json_as_boolean(json_value_t *value, bool *out_bool);
|
||||||
|
bool json_as_null(json_value_t *value);
|
||||||
|
bool json_as_number(json_value_t *value, double *out_double);
|
||||||
|
bool json_as_object(json_value_t *value, json_object_t *out_object);
|
||||||
|
bool json_as_string(json_value_t *value, json_string_t *out_string);
|
||||||
|
bool json_obj_get(json_object_t *obj, json_string_t key, json_value_t *out_value);
|
||||||
|
json_value_t json_parse(scanner_t *scanner, allocator_t allocator);
|
||||||
|
|
||||||
// string builder //////////////////////////////////////////////////////////////
|
// string builder //////////////////////////////////////////////////////////////
|
||||||
typedef struct string_builder_node {
|
typedef struct string_builder_node {
|
||||||
struct string_builder_node *next;
|
struct string_builder_node *next;
|
||||||
@@ -388,6 +444,7 @@ void allocator_reset(allocator_t this) {
|
|||||||
#include "dyn_array.c"
|
#include "dyn_array.c"
|
||||||
#include "cli.c"
|
#include "cli.c"
|
||||||
#include "scanner.c"
|
#include "scanner.c"
|
||||||
|
#include "json.c"
|
||||||
#include "string_builder.c"
|
#include "string_builder.c"
|
||||||
#include "file_io.c"
|
#include "file_io.c"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#include "cig.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
bool json_as_array(json_value_t *value, json_array_t *array) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool json_as_boolean(json_value_t *value, bool *out_bool) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool json_as_null(json_value_t *value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool json_as_number(json_value_t *value, double *out_double) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool json_as_object(json_value_t *value, json_object_t *out_object) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool json_as_string(json_value_t *value, json_string_t *out_string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool json_obj_get(json_object_t *obj, json_string_t key, json_value_t *out_value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
json_value_t json_parse(scanner_t *scanner, allocator_t allocator) {
|
||||||
|
scan_whitespace(scanner);
|
||||||
|
if (scan_string_literal(scanner)) {
|
||||||
|
const char *buffer = scanner->value.string_literal;
|
||||||
|
size_t length = strlen(buffer);
|
||||||
|
char *buff_copy = allocator_alloc(allocator, length+1);
|
||||||
|
strncpy(buff_copy, buffer, length+1);
|
||||||
|
buff_copy[length] = '\0';
|
||||||
|
return (json_value_t) {
|
||||||
|
.type=json_type_string,
|
||||||
|
.string=(json_string_t) { .length=length, .buffer=buff_copy }
|
||||||
|
};
|
||||||
|
} else if (scan_f64(scanner)) {
|
||||||
|
return (json_value_t) {
|
||||||
|
.type=json_type_number,
|
||||||
|
.number=scanner->value.f64
|
||||||
|
};
|
||||||
|
} else if (scan_i64(scanner)) {
|
||||||
|
// TODO: is this needed?
|
||||||
|
return (json_value_t) {
|
||||||
|
.type=json_type_number,
|
||||||
|
.number=(double)scanner->value.i64
|
||||||
|
};
|
||||||
|
} else if (scan_literal(scanner, "true")) {
|
||||||
|
return (json_value_t) {
|
||||||
|
.type=json_type_boolean,
|
||||||
|
.boolean=true
|
||||||
|
};
|
||||||
|
} else if (scan_literal(scanner, "false")) {
|
||||||
|
return (json_value_t) {
|
||||||
|
.type=json_type_boolean,
|
||||||
|
.boolean=false
|
||||||
|
};
|
||||||
|
} else if (scan_literal(scanner, "null")) {
|
||||||
|
return (json_value_t) {
|
||||||
|
.type=json_type_null
|
||||||
|
};
|
||||||
|
} else if (scan_literal(scanner, "[")) {
|
||||||
|
json_parse(scanner, allocator);
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,6 +51,8 @@ build:
|
|||||||
|
|
||||||
DEPENDENCY_HEADERS := if os() == "macos" {
|
DEPENDENCY_HEADERS := if os() == "macos" {
|
||||||
"$(pkg-config --cflags-only-I criterion | sed 's/-I//g')"
|
"$(pkg-config --cflags-only-I criterion | sed 's/-I//g')"
|
||||||
|
} else if os() == "linux" {
|
||||||
|
"/usr/include/criterion/"
|
||||||
} else {
|
} else {
|
||||||
"TODO"
|
"TODO"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user