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
#ifndef __JSON_H__
#define __JSON_H__
#include <stdbool.h>

typedef struct {
    enum  { ELEMENT_INT, ELEMENT_STRING, ELEMENT_LIST } type;
    union {
        int    as_int;
        char*  as_string;
        struct _Node* as_list;
    }; // ANONYMOUS union (C11).
} Element;


typedef struct _Node {
    struct _Node* next;
    Element element;
} Node;

typedef struct { int DELETE_THIS; } ParseResult;  // TODO:  make this into a struct type definition

bool parse_int(int* a_value, char const** a_pos);
bool parse_string(char** a_s, char const** a_pos);
bool parse_element(Element* a_element, char const** a_pos);
bool parse_list(Node** a_head, char const** a_pos);
void print_element(Element element);
void free_element(Element element);
ParseResult parse_json(char const* json);

#endif

#define JSON_H_VERSION_2
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

© Copyright 2023 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.