2023-05-06 18:31:07 +00:00
|
|
|
#ifndef __ARCANA_LISP_LEXER_H__
|
|
|
|
#define __ARCANA_LISP_LEXER_H__
|
2023-05-04 10:16:58 +00:00
|
|
|
|
2023-05-05 08:16:50 +00:00
|
|
|
#include "tokens.h"
|
|
|
|
|
2023-05-05 08:28:17 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2023-05-05 19:34:56 +00:00
|
|
|
#define LEXER_BUFFER_SLEN 1023
|
|
|
|
#define LEXER_BUFFER_SIZE (LEXER_BUFFER_SLEN + 1)
|
|
|
|
|
2023-05-05 08:28:17 +00:00
|
|
|
#define LEXER_DELETE(lexer) do { \
|
|
|
|
Lexer_delete(lexer); \
|
|
|
|
lexer = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
2023-05-05 19:34:56 +00:00
|
|
|
enum Lexer_State {
|
|
|
|
STATE_INIT,
|
|
|
|
STATE_WHITESPACE,
|
2023-05-06 15:55:45 +00:00
|
|
|
STATE_COMMENT_LINE,
|
2023-05-05 19:34:56 +00:00
|
|
|
STATE_ROUND_OPEN,
|
|
|
|
STATE_ROUND_CLOSE,
|
|
|
|
STATE_SQUARE_OPEN,
|
|
|
|
STATE_SQUARE_CLOSE,
|
|
|
|
STATE_CURLY_OPEN,
|
|
|
|
STATE_CURLY_CLOSE,
|
|
|
|
STATE_QUOTE,
|
2023-05-07 12:52:24 +00:00
|
|
|
STATE_QUASI_QUOTE,
|
|
|
|
STATE_QUASI_UNQUOTE,
|
2023-05-05 19:34:56 +00:00
|
|
|
STATE_SHARP,
|
|
|
|
STATE_TAG,
|
|
|
|
STATE_IDENT,
|
|
|
|
STATE_NUM,
|
2023-05-05 20:06:04 +00:00
|
|
|
STATE_STRING_START,
|
|
|
|
STATE_STRING_INSIDE,
|
|
|
|
STATE_STRING_END,
|
2023-05-07 11:01:02 +00:00
|
|
|
STATE_STRING_ESCAPE,
|
2023-05-05 19:34:56 +00:00
|
|
|
};
|
|
|
|
|
2023-05-05 08:28:17 +00:00
|
|
|
typedef struct Lexer {
|
|
|
|
Tokens tokens;
|
2023-05-05 19:34:56 +00:00
|
|
|
enum Lexer_State state;
|
|
|
|
char buffer[LEXER_BUFFER_SIZE];
|
|
|
|
size_t buffer_index;
|
2023-05-05 08:28:17 +00:00
|
|
|
} *Lexer;
|
|
|
|
|
|
|
|
Lexer Lexer_new(Tokens tokens);
|
|
|
|
void Lexer_delete(Lexer lexer);
|
|
|
|
|
|
|
|
void Lexer_lex(Lexer self, char chr);
|
2023-05-04 10:16:58 +00:00
|
|
|
|
|
|
|
#endif
|