get_next_token returns result which includes possible error and token

This commit is contained in:
2023-06-27 22:23:16 +01:00
parent a6b45834fc
commit 1e510411dc
4 changed files with 369 additions and 26 deletions

View File

@@ -10,7 +10,7 @@
typedef const char *str_view_t;
typedef enum {
TK_NO_TOKEN,
TK_NO_TOKEN,
TK_L_BRACE,
TK_R_BRACE,
TK_L_BRACKET,
@@ -22,7 +22,7 @@ typedef enum {
TK_STR_VAL,
TK_INTEGER,
TK_DOUBLE,
} token_type_t;
} token_type;
typedef union {
void *no_val;
@@ -34,15 +34,30 @@ typedef union {
typedef struct {
u64 line;
u64 column;
token_type_t type;
token_type type;
token_value_t value;
} token_t;
typedef enum {
LEX_ERR_NONE,
LEX_ERR_INVALID,
} lex_err_type;
typedef struct {
lex_err_type errno;
str_view_t msg;
} lex_err_t;
typedef struct {
lex_err_t error;
token_t token;
} lex_result_t;
typedef struct lexer lexer_t;
void lexer_init(lexer_t **lexer);
void lexer_free(lexer_t **lexer);
token_t get_next_token(lexer_t *lexer, const char *text);
lex_result_t get_next_token(lexer_t *lexer, const char *text);
bool validate_json(char *json);
void print_token(token_t token);