Remove validate_json

This commit is contained in:
Abdelrahman Said 2023-07-01 15:05:41 +01:00
parent ff110ea6e2
commit 10597c0ed7
2 changed files with 2 additions and 36 deletions

View File

@ -53,13 +53,12 @@ typedef struct {
token_t token;
} lex_result_t;
typedef struct lexer lexer_t;
typedef struct lexer_s lexer_t;
void lexer_init(lexer_t **lexer);
void lexer_free(lexer_t **lexer);
lex_result_t get_next_token(lexer_t *lexer, const char *text);
bool validate_json(char *json);
void print_token(token_t token);
#endif // !LEXER_STATES_H

View File

@ -77,7 +77,7 @@ typedef struct {
};
} lexer_string_t;
struct lexer {
struct lexer_s {
u64 cursor;
u64 line;
u64 column;
@ -246,39 +246,6 @@ lex_result_t get_next_token(lexer_t *lexer, const char *text) {
};
}
bool validate_json(char *json) {
lexer_t lexer = {0};
lexer.line = 1;
lexer.column = 0;
lexer.current = LEXER_STATE_START;
lexer.keyword.type = LEXER_STRING_KEYWORD;
lexer.codepoint.type = LEXER_STRING_UNICODE;
lexer.current_string = dstr_with_capacity(STRING_BUF_START_CAPACITY);
if (!lexer.current_string) {
// TODO (Abdelrahman): This is fine for now, but it doesn't make sense to
// return INVALID_JSON if string allocation fails
return INVALID_JSON;
}
for (char *c = json; *c != '\0'; ++c) {
lexer_state_machine(&lexer, *c);
// Track the position in the text
++(lexer.column);
if (*c == '\n') {
++(lexer.line);
lexer.column = 0;
}
if (lexer.current == LEXER_STATE_ERROR) {
return INVALID_JSON;
}
}
return lexer.current == LEXER_STATE_LAST_COLLECTION || lexer.stack.size == 0;
}
void print_token(token_t token) {
i32 num_padding = 4;