From a515dfb3b8f8e999362db7a6b52b3104c03b750a Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 1 Nov 2024 23:46:08 -0400 Subject: Import quark sources Signed-off-by: Ian Moffett --- include/lexer/token.h | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 include/lexer/token.h (limited to 'include/lexer/token.h') diff --git a/include/lexer/token.h b/include/lexer/token.h new file mode 100644 index 0000000..e0a9ea3 --- /dev/null +++ b/include/lexer/token.h @@ -0,0 +1,92 @@ +/* + * Token definitions. + * Copyright (c) 2023-2024, Quinn Stephens and the OSMORA team. + * Provided under the BSD 3-Clause license. + */ + +#ifndef _LEXER_TOKEN_H +#define _LEXER_TOKEN_H + +#include +#include +#include "hash.h" + +typedef enum { + TK_UNKNOWN, + TK_EOF, + + TK_IDENTIFIER, + TK_NUMBER, + TK_STRING, + TK_CHARACTER, + + /* Keywords */ + TK_TYPE, + TK_ENUM, + TK_STRUCT, + + /* + * Operators. + * NOTE: lex_oper() requires that TK_*_EQUALS + * immediately follows TK_*. + */ + TK_PLUS, + TK_PLUS_EQUALS, + TK_PLUS_PLUS, + TK_MINUS, + TK_MINUS_EQUALS, + TK_MINUS_MINUS, + TK_ARROW, + TK_STAR, + TK_STAR_EQUALS, + TK_SLASH, + TK_SLASH_EQUALS, + TK_PERCENT, + TK_PERCENT_EQUALS, + TK_EXCLAMATION, + TK_EXCLAMATION_EQUALS, + TK_LESS_THAN, + TK_LESS_THAN_EQUALS, + TK_SHIFT_LEFT, + TK_SHIFT_LEFT_EQUALS, + TK_GREATER_THAN, + TK_GREATER_THAN_EQUALS, + TK_SHIFT_RIGHT, + TK_SHIFT_RIGHT_EQUALS, + TK_CARET, + TK_CARET_EQUALS, + TK_AMPERSAND, + TK_AMPERSAND_EQUALS, + TK_PIPE, + TK_PIPE_EQUALS, + TK_TILDE, + TK_EQUALS, + + /* Miscellaneous */ + TK_COMMA, + TK_DOT, + TK_COLON, + TK_SEMICOLON, + TK_LPAREN, + TK_RPAREN, + TK_LBRACE, + TK_RBRACE, + TK_LBRACK, + TK_RBRACK +} token_kind_t; + +struct token { + token_kind_t kind; + + char *fname; + int line, col; + char *pos; + size_t len; + + union { + hash_t hash; + uint64_t value; + }; +}; + +#endif /* !_LEXER_TOKEN_H */ -- cgit v1.2.3