2023-05-03 21:28:58 +00:00
|
|
|
#include "enums.h"
|
|
|
|
|
2023-05-03 21:41:04 +00:00
|
|
|
#include <stdbool.h>
|
2023-05-03 21:28:58 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2023-05-03 21:41:04 +00:00
|
|
|
const char *State_to_str(const enum State state)
|
2023-05-03 21:28:58 +00:00
|
|
|
{
|
|
|
|
switch (state) {
|
2023-05-03 21:41:04 +00:00
|
|
|
case STATE_INIT: return "STATE_INIT";
|
2023-05-03 21:28:58 +00:00
|
|
|
case STATE_WHITESPACE: return "STATE_WHITESPACE";
|
2023-05-03 21:41:04 +00:00
|
|
|
case STATE_OPEN: return "STATE_OPEN";
|
|
|
|
case STATE_CLOSE: return "STATE_CLOSE";
|
|
|
|
case STATE_ID: return "STATE_ID";
|
|
|
|
case STATE_NUM: return "STATE_NUM";
|
2023-05-03 21:28:58 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2023-05-03 21:41:04 +00:00
|
|
|
|
|
|
|
const char *TokenType_to_str(const enum TokenType token_type)
|
|
|
|
{
|
|
|
|
switch (token_type) {
|
|
|
|
case TOKEN_OPEN: return "TOKEN_OPEN";
|
|
|
|
case TOKEN_CLOSE: return "TOKEN_CLOSE";
|
|
|
|
case TOKEN_ID: return "TOKEN_ID";
|
|
|
|
case TOKEN_NUM: return "TOKEN_NUM";
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Type_to_str(const enum Type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case TYPE_PAIR: return "TYPE_PAIR";
|
|
|
|
case TYPE_ATOM: return "TYPE_ATOM";
|
|
|
|
case TYPE_STRING: return "TYPE_STRING";
|
|
|
|
case TYPE_NUMBER: return "TYPE_NUMBER";
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
State_to_token_type(const enum State state, enum TokenType *const token_type)
|
|
|
|
{
|
|
|
|
switch (state) {
|
2023-05-03 22:05:11 +00:00
|
|
|
case STATE_OPEN: *token_type = TOKEN_OPEN; break;
|
|
|
|
case STATE_CLOSE: *token_type = TOKEN_CLOSE; break;
|
|
|
|
case STATE_ID: *token_type = TOKEN_ID; break;
|
|
|
|
case STATE_NUM: *token_type = TOKEN_NUM; break;
|
2023-05-03 21:41:04 +00:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|