ifc can be used to compile .if files into self-contained header-only C libraries, which can be used to send/receive messages that conform to the described interface.
64 lines
1.1 KiB
C
64 lines
1.1 KiB
C
#include "token.h"
|
|
|
|
void token_destroy(struct token *tok)
|
|
{
|
|
switch (tok->tok_value_type) {
|
|
case TOK_V_STRING:
|
|
if (tok->tok_str) {
|
|
free(tok->tok_str);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
free(tok);
|
|
}
|
|
|
|
#define ENUM_STR(x) \
|
|
case x: \
|
|
return #x
|
|
|
|
const char *token_type_to_string(enum token_type type)
|
|
{
|
|
switch (type) {
|
|
ENUM_STR(TOK_NONE);
|
|
ENUM_STR(TOK_INT);
|
|
ENUM_STR(TOK_SYMBOL);
|
|
ENUM_STR(TOK_WORD);
|
|
ENUM_STR(TOK_NAME);
|
|
ENUM_STR(TOK_STRING);
|
|
ENUM_STR(TOK_KEYWORD);
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
const char *token_symbol_to_string(enum token_symbol sym)
|
|
{
|
|
switch (sym) {
|
|
ENUM_STR(SYM_NONE);
|
|
ENUM_STR(SYM_COMMA);
|
|
ENUM_STR(SYM_SEMICOLON);
|
|
ENUM_STR(SYM_HYPHEN);
|
|
ENUM_STR(SYM_LEFT_BRACE);
|
|
ENUM_STR(SYM_RIGHT_BRACE);
|
|
ENUM_STR(SYM_LEFT_PAREN);
|
|
ENUM_STR(SYM_RIGHT_PAREN);
|
|
ENUM_STR(SYM_HYPHEN_RIGHT_ANGLE);
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
const char *token_keyword_to_string(enum token_keyword kw)
|
|
{
|
|
switch (kw) {
|
|
ENUM_STR(KW_NONE);
|
|
ENUM_STR(KW_INTERFACE);
|
|
ENUM_STR(KW_MSG);
|
|
default:
|
|
return "";
|
|
}
|
|
}
|