diff options
Diffstat (limited to 'json/include/lcq')
| -rw-r--r-- | json/include/lcq/json.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/json/include/lcq/json.h b/json/include/lcq/json.h new file mode 100644 index 0000000..d5bc37e --- /dev/null +++ b/json/include/lcq/json.h @@ -0,0 +1,63 @@ +#ifndef LCOLONQ_JSON_H +#define LCOLONQ_JSON_H + +#include <lcq/prelude.h> + +typedef enum { + JSON_TOKEN__ERROR=-1, + JSON_TOKEN__START=0, + JSON_TOKEN_NUMBER_INT, + JSON_TOKEN_NUMBER_FLOAT, + JSON_TOKEN_STRING, + JSON_TOKEN_LSQUARE, + JSON_TOKEN_RSQUARE, + JSON_TOKEN_LCURLY, + JSON_TOKEN_RCURLY, + JSON_TOKEN_COMMA, + JSON_TOKEN_COLON, + JSON_TOKEN__END, +} json_token; + +typedef struct { + u8 *buf; + i64 size; + i64 start, end; +} json_lexer; + +char *json_token_name(json_token t); +void json_lexer_new(json_lexer *l, u8 *buf, i64 size); +json_token json_lex(json_lexer *l); + +typedef enum { + JSON_VALUE_TYPE__ERROR=-1, + JSON_VALUE_TYPE_NUMBER=1, + JSON_VALUE_TYPE_STRING, + JSON_VALUE_TYPE_ARRAY, + JSON_VALUE_TYPE_OBJECT, +} json_value_type; + +typedef struct { + i64 idx; +} json_value; + +typedef struct { + i64 idx; +} json_array_iter; + +typedef struct { + json_lexer lex; + json_token next; + i64 curstart, curend; +} json_parser; + +void json_parser_new(json_parser *p, u8 *buf, i64 size); +json_value json_parse(json_parser *p); + +json_value_type json_value_get_type(json_parser *p, json_value v); +char *json_value_as_string(json_parser *p, json_value v); +i64 json_value_as_number(json_parser *p, json_value v); +json_array_iter json_value_as_array(json_parser *p, json_value v); +json_value json_array_iter_get(json_parser *p, json_array_iter i); +bool json_array_iter_next(json_parser *p, json_array_iter *i); + +#endif |
