The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
jsmn.h
1 #ifndef __JSMN_H_
2 #define __JSMN_H_
3 
4 #include <stddef.h>
5 
6 #define JSMN_PARENT_LINKS
7 #define JSMN_STRICT
8 // TODO HOMEBREW OUR OWN JSON PARSER FOR PRIDE
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
20 typedef enum {
21  JSMN_UNDEFINED = 0,
22  JSMN_OBJECT = 1,
23  JSMN_ARRAY = 2,
24  JSMN_STRING = 3,
25  JSMN_PRIMITIVE = 4
26 } jsmntype_t;
27 
28 enum jsmnerr {
29  /* Not enough tokens were provided */
30  JSMN_ERROR_NOMEM = -1,
31  /* Invalid character inside JSON string */
32  JSMN_ERROR_INVAL = -2,
33  /* The string is not a full JSON packet, more bytes expected */
34  JSMN_ERROR_PART = -3
35 };
36 
43 typedef struct {
44  jsmntype_t type;
45  int start;
46  int end;
47  int size;
48 #ifdef JSMN_PARENT_LINKS
49  int parent;
50 #endif
51 } jsmntok_t;
52 
57 typedef struct {
58  unsigned int pos; /* offset in the JSON string */
59  unsigned int toknext; /* next token to allocate */
60  int toksuper; /* superior token node, e.g parent object or array */
61 } jsmn_parser;
62 
66 void jsmn_init(jsmn_parser *parser);
67 
72 int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
73  jsmntok_t *tokens, unsigned int num_tokens);
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* __JSMN_H_ */
Definition: jsmn.h:43