Add char_type function to lexer.c but exclude it from build

This commit is contained in:
Abdelrahman Said 2023-07-25 08:55:46 +01:00
parent fd8231b02d
commit 6c454fbb8e

View File

@ -95,6 +95,9 @@ struct lexer_s {
dstr_t *error_message;
};
#if 0
INTERNAL lexer_input_t char_type(char input);
#endif
INTERNAL void stack_push(state_stack_t *stack, lexer_state_t value);
INTERNAL lexer_state_t stack_pop(state_stack_t *stack);
@ -298,6 +301,83 @@ void print_token(token_t token) {
printf("}\n");
}
#if 0
INTERNAL lexer_input_t char_type(char input) {
if (isspace(input)) {
return LEXER_INPUT_WHITE_SPACE;
} else if (input >= '1' && input <= '9') {
return LEXER_INPUT_NON_ZERO;
}
switch (input) {
case '{':
return LEXER_INPUT_OPEN_BRACE;
case '}':
return LEXER_INPUT_CLOSE_BRACE;
case '[':
return LEXER_INPUT_OPEN_BRACKET;
case ']':
return LEXER_INPUT_CLOSE_BRACKET;
case ',':
return LEXER_INPUT_COMMA;
case ':':
return LEXER_INPUT_COLON;
case '"':
return LEXER_INPUT_DOUBLE_QUOTE;
case '\\':
return LEXER_INPUT_BACK_SLASH;
case '/':
return LEXER_INPUT_FORWARD_SLASH;
case 'a':
return LEXER_INPUT_LOWER_A;
case 'b':
return LEXER_INPUT_LOWER_B;
case 'c':
return LEXER_INPUT_LOWER_C;
case 'd':
return LEXER_INPUT_LOWER_D;
case 'e':
return LEXER_INPUT_LOWER_E;
case 'f':
return LEXER_INPUT_LOWER_F;
case 'l':
return LEXER_INPUT_LOWER_L;
case 'n':
return LEXER_INPUT_LOWER_N;
case 'r':
return LEXER_INPUT_LOWER_R;
case 's':
return LEXER_INPUT_LOWER_S;
case 't':
return LEXER_INPUT_LOWER_T;
case 'u':
return LEXER_INPUT_LOWER_U;
case 'A':
return LEXER_INPUT_UPPER_A;
case 'B':
return LEXER_INPUT_UPPER_B;
case 'C':
return LEXER_INPUT_UPPER_C;
case 'D':
return LEXER_INPUT_UPPER_D;
case 'E':
return LEXER_INPUT_UPPER_E;
case 'F':
return LEXER_INPUT_UPPER_F;
case '-':
return LEXER_INPUT_MINUS;
case '+':
return LEXER_INPUT_PLUS;
case '.':
return LEXER_INPUT_DECIMAL;
case '0':
return LEXER_INPUT_ZERO;
default:
return LEXER_INPUT_OTHER;
}
}
#endif
void stack_push(state_stack_t *stack, lexer_state_t state) {
if (stack->size + 1 >= MAX_STACK_CAPACITY) {
return;
@ -772,8 +852,6 @@ lexer_state_t handle_number(lexer_t *lexer, char input) {
return LEXER_STATE_FRACTION;
} else if (input == '}' || input == ']') {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);
@ -783,8 +861,6 @@ lexer_state_t handle_number(lexer_t *lexer, char input) {
return handle_collection_end(lexer, input);
} else if (input == ',') {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);
@ -794,8 +870,6 @@ lexer_state_t handle_number(lexer_t *lexer, char input) {
return lexer->stack.stack[lexer->stack.size - 1];
} else if (isspace(input)) {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);
@ -815,8 +889,6 @@ lexer_state_t handle_fraction(lexer_t *lexer, char input) {
return LEXER_STATE_FRACTION;
} else if (input == '}' || input == ']') {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);
@ -830,8 +902,6 @@ lexer_state_t handle_fraction(lexer_t *lexer, char input) {
return LEXER_STATE_EXPONENT;
} else if (input == ',') {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);
@ -841,8 +911,6 @@ lexer_state_t handle_fraction(lexer_t *lexer, char input) {
return lexer->stack.stack[lexer->stack.size - 1];
} else if (isspace(input)) {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);
@ -884,8 +952,6 @@ lexer_state_t handle_power(lexer_t *lexer, char input) {
return LEXER_STATE_POWER;
} else if (input == '}' || input == ']') {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);
@ -895,8 +961,6 @@ lexer_state_t handle_power(lexer_t *lexer, char input) {
return handle_collection_end(lexer, input);
} else if (input == ',') {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);
@ -906,8 +970,6 @@ lexer_state_t handle_power(lexer_t *lexer, char input) {
return lexer->stack.stack[lexer->stack.size - 1];
} else if (isspace(input)) {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);
@ -925,8 +987,6 @@ lexer_state_t handle_number_end(lexer_t *lexer, char input) {
if (isspace(input)) {
return LEXER_STATE_NUMBER_END;
} else if (input == ',') {
// TODO (Abdelrahman): Set the token type correctly based on whether the
// number is an integer or a double
lexer->token_ready = true;
u64 column = lexer->column - dstr_length(lexer->current_string);