2020-12-26 03:32:21 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN,
|
|
|
|
TOKEN_LEFT_BRACE, TOKEN_RIGHT_BRACE,
|
|
|
|
TOKEN_LEFT_SQUARE, TOKEN_RIGHT_SQUARE,
|
2020-12-28 04:54:25 +03:00
|
|
|
/* 6 */
|
2020-12-26 03:32:21 +03:00
|
|
|
TOKEN_COLON,
|
|
|
|
TOKEN_COMMA, TOKEN_DOT, TOKEN_MINUS, TOKEN_PLUS,
|
|
|
|
TOKEN_SEMICOLON, TOKEN_SOLIDUS, TOKEN_ASTERISK,
|
|
|
|
|
2020-12-28 04:54:25 +03:00
|
|
|
/* 14 */
|
2020-12-26 03:32:21 +03:00
|
|
|
TOKEN_BANG, TOKEN_BANG_EQUAL,
|
|
|
|
TOKEN_EQUAL, TOKEN_EQUAL_EQUAL,
|
|
|
|
TOKEN_GREATER, TOKEN_GREATER_EQUAL,
|
|
|
|
TOKEN_LESS, TOKEN_LESS_EQUAL,
|
|
|
|
|
2020-12-28 04:54:25 +03:00
|
|
|
/* 22 */
|
2021-01-03 08:09:45 +03:00
|
|
|
TOKEN_IDENTIFIER, TOKEN_STRING, TOKEN_NUMBER, TOKEN_BIG_STRING,
|
2020-12-26 03:32:21 +03:00
|
|
|
|
2020-12-28 04:54:25 +03:00
|
|
|
TOKEN_AND, /* 26 and */
|
|
|
|
TOKEN_CLASS, /* 27 class */
|
|
|
|
TOKEN_DEF, /* 28 def */
|
|
|
|
TOKEN_ELSE, /* 29 else */
|
|
|
|
TOKEN_FALSE, /* 30 False */
|
|
|
|
TOKEN_FOR, /* 31 for */
|
|
|
|
TOKEN_IF, /* 32 if */
|
|
|
|
TOKEN_IMPORT,/* 33 import */
|
|
|
|
TOKEN_IN, /* 34 in */
|
|
|
|
TOKEN_LET, /* 35 let */
|
|
|
|
TOKEN_NONE, /* 36 None */
|
|
|
|
TOKEN_NOT, /* 37 not */
|
|
|
|
TOKEN_OR, /* 38 or */
|
|
|
|
TOKEN_PRINT, /* 39 print */
|
|
|
|
TOKEN_RETURN,/* 40 return */
|
|
|
|
TOKEN_SELF, /* 41 self */
|
|
|
|
TOKEN_SUPER, /* 42 super */
|
|
|
|
TOKEN_TRUE, /* 43 True */
|
|
|
|
TOKEN_WHILE, /* 44 while */
|
|
|
|
|
|
|
|
TOKEN_INDENTATION, /* 45 */
|
|
|
|
|
|
|
|
TOKEN_RETRY, /* 46 */
|
|
|
|
TOKEN_EOL, /* 47 */
|
2020-12-26 03:32:21 +03:00
|
|
|
|
2020-12-28 13:25:33 +03:00
|
|
|
TOKEN_EXPORT, /* 48 */
|
2020-12-28 10:32:27 +03:00
|
|
|
TOKEN_MODULO,
|
2020-12-29 05:00:12 +03:00
|
|
|
TOKEN_TRY, TOKEN_EXCEPT, TOKEN_RAISE,
|
2020-12-31 10:59:51 +03:00
|
|
|
TOKEN_BREAK, TOKEN_CONTINUE,
|
2020-12-28 13:25:33 +03:00
|
|
|
|
2021-01-01 02:55:39 +03:00
|
|
|
/* Decorators */
|
|
|
|
TOKEN_AT, /* @ */
|
|
|
|
/* Bitwise operators */
|
|
|
|
TOKEN_CARET, /* ^ (xor) */
|
|
|
|
TOKEN_AMPERSAND, /* & (and) */
|
|
|
|
TOKEN_PIPE, /* | (or) */
|
|
|
|
TOKEN_TILDE, /* ~ (negate) */
|
|
|
|
/* Shifts */
|
|
|
|
TOKEN_LEFT_SHIFT, /* << */
|
|
|
|
TOKEN_RIGHT_SHIFT,/* >> */
|
|
|
|
/* Assignment shortcuts */
|
|
|
|
TOKEN_PLUS_EQUAL, /* += */
|
|
|
|
TOKEN_MINUS_EQUAL,/* -= */
|
|
|
|
TOKEN_PLUS_PLUS, /* ++ */
|
|
|
|
TOKEN_MINUS_MINUS,/* -- */
|
|
|
|
|
2021-01-04 01:39:00 +03:00
|
|
|
TOKEN_AS,
|
|
|
|
|
2020-12-26 03:32:21 +03:00
|
|
|
TOKEN_ERROR,
|
|
|
|
TOKEN_EOF,
|
|
|
|
} KrkTokenType;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
KrkTokenType type;
|
|
|
|
const char * start;
|
|
|
|
size_t length;
|
|
|
|
size_t line;
|
2020-12-29 09:26:45 +03:00
|
|
|
const char * linePtr;
|
|
|
|
size_t col;
|
2020-12-29 16:16:35 +03:00
|
|
|
size_t literalWidth;
|
2020-12-26 03:32:21 +03:00
|
|
|
} KrkToken;
|
|
|
|
|
2020-12-30 15:56:02 +03:00
|
|
|
typedef struct {
|
|
|
|
const char * start;
|
|
|
|
const char * cur;
|
|
|
|
const char * linePtr;
|
|
|
|
size_t line;
|
|
|
|
int startOfLine;
|
|
|
|
int hasUnget;
|
|
|
|
KrkToken unget;
|
|
|
|
} KrkScanner;
|
|
|
|
|
2020-12-28 06:16:44 +03:00
|
|
|
extern void krk_initScanner(const char * src);
|
|
|
|
extern KrkToken krk_scanToken(void);
|
|
|
|
extern void krk_ungetToken(KrkToken token);
|
2020-12-30 15:56:02 +03:00
|
|
|
extern void krk_rewindScanner(KrkScanner to);
|
|
|
|
extern KrkScanner krk_tellScanner(void);
|