Files
rosetta/toolchain/ifc/token.h
Max Wash b631fca0fd toolchain: add a program for compiling ipc interface definitions
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.
2026-02-26 19:44:32 +00:00

71 lines
1.4 KiB
C

#ifndef IFC_TOKEN_H_
#define IFC_TOKEN_H_
#include "file-span.h"
#include <blue/core/queue.h>
#define TOKEN_TYPE(tok) ((tok) ? (tok)->tok_type : TOK_NONE)
#define TOKEN_IS(tok, type) ((tok) && ((tok)->tok_type & (type)) != 0)
#define TOKEN_IS_SYMBOL(tok, sym) \
((tok) && (tok)->tok_type == TOK_SYMBOL && (tok)->tok_sym == (sym))
enum token_type {
TOK_NONE = 0,
TOK_SYMBOL = 0x0001u,
TOK_KEYWORD = 0x0002u,
TOK_WORD = 0x0004u,
TOK_NAME = 0x0008u,
TOK_INT = 0x0010u,
TOK_STRING = 0x0020u,
__TOK_UBOUND = 0x0040u,
};
enum token_value_type {
TOK_V_NONE = 0,
TOK_V_INT,
TOK_V_STRING,
TOK_V_SYMBOL,
TOK_V_KEYWORD,
};
enum token_symbol {
SYM_NONE = 0,
SYM_COMMA = __TOK_UBOUND,
SYM_HYPHEN,
SYM_SEMICOLON,
SYM_LEFT_BRACE,
SYM_RIGHT_BRACE,
SYM_LEFT_PAREN,
SYM_RIGHT_PAREN,
SYM_HYPHEN_RIGHT_ANGLE,
__SYM_UBOUND,
};
enum token_keyword {
KW_NONE = 0,
KW_INTERFACE = __SYM_UBOUND,
KW_MSG,
};
struct token {
struct file_span tok_location;
enum token_type tok_type;
enum token_value_type tok_value_type;
b_queue_entry tok_entry;
union {
char *tok_str;
enum token_symbol tok_sym;
enum token_keyword tok_kw;
long long tok_int;
};
};
extern void token_destroy(struct token *tok);
extern const char *token_type_to_string(enum token_type type);
extern const char *token_symbol_to_string(enum token_symbol sym);
extern const char *token_keyword_to_string(enum token_keyword kw);
#endif