<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/cudl.h
blob: 36d236505b5e65ef17fa2a0d2ea13457780e70d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef cudl_h_INCLUDED
#define cudl_h_INCLUDED

#include <stdio.h>
#include <stddef.h>

struct cudl_array_value {
	struct cudl_value *values;
	size_t length;
};

struct cudl_map_value {
	struct cudl_map_field *fields;
	size_t length;
};

struct cudl_value {
	union {
		char *string;
		double number;
		int boolean;
		struct cudl_array_value array;
		struct cudl_map_value map;
	} data;
	int tag;
};

struct cudl_map_field {
	char *key;
	struct cudl_value value;
};

enum {
	CUDL_TAG_NULL,
	CUDL_TAG_BOOL,
	CUDL_TAG_ARRAY,
	CUDL_TAG_MAP,
	CUDL_TAG_STRING,
};

enum {
	CUDL_OK = 0,
	CUDL_ERR_OUT_OF_MEMORY,
	CUDL_ERR_READING,
	CUDL_ERR_EXPECTED_VALUE,
	CUDL_ERR_EXPECTED_BOOL_OR_NULL,
	CUDL_ERR_EXPECTED_ESCAPE_SEQUENCE,
	CUDL_ERR_EXPECTED_MAP_KEY,
	CUDL_ERR_EXPECTED_COLON,
	CUDL_ERR_UNMATCHED_BRACK,
	CUDL_ERR_UNMATCHED_BRACE,
	CUDL_ERR_UNMATCHED_QUOTE,
	CUDL_ERR_UNRECOGNISED_VALUE,
	CUDL_ERR_UNRECOGNISED_UNICODE,
};

extern int cudl_err;

void cudl_debug(struct cudl_value value);
void cudl_deinit_value(struct cudl_value value);
void cudl_parse_from_file(FILE *file, struct cudl_value *value);
size_t cudl_parse(char *input, struct cudl_value *value);

#endif // cudl_h_INCLUDED