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,
|
|
|
|
TOKEN_COLON,
|
2021-01-10 16:07:13 +03:00
|
|
|
TOKEN_COMMA,
|
|
|
|
TOKEN_DOT,
|
|
|
|
TOKEN_MINUS,
|
|
|
|
TOKEN_PLUS,
|
|
|
|
TOKEN_SEMICOLON,
|
|
|
|
TOKEN_SOLIDUS,
|
|
|
|
TOKEN_ASTERISK,
|
2021-01-19 13:29:29 +03:00
|
|
|
TOKEN_POW,
|
2020-12-28 10:32:27 +03:00
|
|
|
TOKEN_MODULO,
|
2021-01-10 16:07:13 +03:00
|
|
|
TOKEN_AT,
|
2021-01-01 02:55:39 +03:00
|
|
|
TOKEN_CARET, /* ^ (xor) */
|
|
|
|
TOKEN_AMPERSAND, /* & (and) */
|
|
|
|
TOKEN_PIPE, /* | (or) */
|
|
|
|
TOKEN_TILDE, /* ~ (negate) */
|
|
|
|
TOKEN_LEFT_SHIFT, /* << */
|
|
|
|
TOKEN_RIGHT_SHIFT,/* >> */
|
2021-01-19 13:29:29 +03:00
|
|
|
TOKEN_BANG,
|
|
|
|
TOKEN_GREATER,
|
|
|
|
TOKEN_LESS,
|
2021-01-01 02:55:39 +03:00
|
|
|
|
2021-01-19 13:29:29 +03:00
|
|
|
/* Comparisons */
|
|
|
|
TOKEN_GREATER_EQUAL,
|
|
|
|
TOKEN_LESS_EQUAL,
|
|
|
|
TOKEN_BANG_EQUAL,
|
|
|
|
TOKEN_EQUAL_EQUAL,
|
|
|
|
|
|
|
|
/* Assignments */
|
|
|
|
TOKEN_EQUAL,
|
|
|
|
TOKEN_LSHIFT_EQUAL, /* <<= */
|
|
|
|
TOKEN_RSHIFT_EQUAL, /* >>= */
|
|
|
|
TOKEN_PLUS_EQUAL, /* += */
|
|
|
|
TOKEN_MINUS_EQUAL, /* -= */
|
|
|
|
TOKEN_PLUS_PLUS, /* ++ */
|
|
|
|
TOKEN_MINUS_MINUS, /* -- */
|
|
|
|
TOKEN_CARET_EQUAL,
|
|
|
|
TOKEN_PIPE_EQUAL,
|
|
|
|
TOKEN_AMP_EQUAL,
|
|
|
|
TOKEN_SOLIDUS_EQUAL,
|
|
|
|
TOKEN_ASTERISK_EQUAL,
|
|
|
|
TOKEN_POW_EQUAL,
|
|
|
|
TOKEN_MODULO_EQUAL,
|
2021-01-10 16:07:13 +03:00
|
|
|
|
|
|
|
TOKEN_STRING,
|
|
|
|
TOKEN_BIG_STRING,
|
|
|
|
TOKEN_NUMBER,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Everything after this, up to indentation,
|
|
|
|
* consists of alphanumerics.
|
|
|
|
*/
|
|
|
|
TOKEN_IDENTIFIER,
|
|
|
|
TOKEN_AND,
|
|
|
|
TOKEN_CLASS,
|
|
|
|
TOKEN_DEF,
|
2021-01-14 10:00:43 +03:00
|
|
|
TOKEN_DEL,
|
2021-01-10 16:07:13 +03:00
|
|
|
TOKEN_ELSE,
|
|
|
|
TOKEN_FALSE,
|
|
|
|
TOKEN_FOR,
|
|
|
|
TOKEN_IF,
|
|
|
|
TOKEN_IMPORT,
|
|
|
|
TOKEN_IN,
|
2021-01-11 09:01:34 +03:00
|
|
|
TOKEN_IS,
|
2021-01-10 16:07:13 +03:00
|
|
|
TOKEN_LET,
|
|
|
|
TOKEN_NONE,
|
|
|
|
TOKEN_NOT,
|
|
|
|
TOKEN_OR,
|
|
|
|
TOKEN_ELIF,
|
2021-01-19 12:22:13 +03:00
|
|
|
TOKEN_PASS,
|
2021-01-10 16:07:13 +03:00
|
|
|
TOKEN_RETURN,
|
|
|
|
TOKEN_SELF,
|
|
|
|
TOKEN_SUPER,
|
|
|
|
TOKEN_TRUE,
|
|
|
|
TOKEN_WHILE,
|
|
|
|
TOKEN_TRY,
|
|
|
|
TOKEN_EXCEPT,
|
|
|
|
TOKEN_RAISE,
|
|
|
|
TOKEN_BREAK,
|
|
|
|
TOKEN_CONTINUE,
|
2021-01-04 01:39:00 +03:00
|
|
|
TOKEN_AS,
|
2021-01-04 01:47:05 +03:00
|
|
|
TOKEN_FROM,
|
2021-01-05 07:28:45 +03:00
|
|
|
TOKEN_LAMBDA,
|
2021-01-09 05:01:18 +03:00
|
|
|
TOKEN_WITH,
|
2021-01-04 01:39:00 +03:00
|
|
|
|
2021-01-12 13:23:14 +03:00
|
|
|
TOKEN_PREFIX_B,
|
|
|
|
|
2021-01-10 16:07:13 +03:00
|
|
|
TOKEN_INDENTATION,
|
|
|
|
|
|
|
|
TOKEN_EOL,
|
|
|
|
TOKEN_RETRY,
|
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);
|