diff options
| author | nasr <nsrddyn@gmail.com> | 2026-03-26 22:35:30 +0100 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-04-13 17:24:42 +0200 |
| commit | dd5586abec207dd4acd16d51ce0d392c03e5e957 (patch) | |
| tree | e56573f49ebb2a3236a39148842dc80bde5a286d /source/fajr_lexer/fajr_lexer.h | |
feature(main): initmain
feature(main): init
Diffstat (limited to 'source/fajr_lexer/fajr_lexer.h')
| -rw-r--r-- | source/fajr_lexer/fajr_lexer.h | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/source/fajr_lexer/fajr_lexer.h b/source/fajr_lexer/fajr_lexer.h new file mode 100644 index 0000000..754b89a --- /dev/null +++ b/source/fajr_lexer/fajr_lexer.h | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | #ifndef FAJR_LEXER_H | ||
| 2 | #define FAJR_LEXER_H | ||
| 3 | |||
| 4 | typedef enum token_type token_type; | ||
| 5 | enum token_type | ||
| 6 | { | ||
| 7 | TokenUndefined = 256, | ||
| 8 | TokenIdentifier, | ||
| 9 | TokenIdentifierAssignmentValue, | ||
| 10 | TokenValue, | ||
| 11 | TokenString, | ||
| 12 | TokenNumber, | ||
| 13 | TokenDoubleEqual, | ||
| 14 | TokenGreaterEqual, | ||
| 15 | TokenLesserEqual, | ||
| 16 | TokenParam, | ||
| 17 | TokenFunc, | ||
| 18 | TokenReturn, | ||
| 19 | TokenIf, | ||
| 20 | TokenElse, | ||
| 21 | TokenFor, | ||
| 22 | TokenWhile, | ||
| 23 | TokenBreak, | ||
| 24 | TokenContinue, | ||
| 25 | TokenExpression, | ||
| 26 | TokenFuncBody, | ||
| 27 | TokenUnwantedChild, | ||
| 28 | TokenNewLine, | ||
| 29 | TokenRightShift, | ||
| 30 | TokenLeftShift, | ||
| 31 | TokenStar, | ||
| 32 | }; | ||
| 33 | |||
| 34 | typedef struct Tokenizer Tokenizer; | ||
| 35 | struct Tokenizer | ||
| 36 | { | ||
| 37 | i32 Line; | ||
| 38 | i32 Column; | ||
| 39 | }; | ||
| 40 | |||
| 41 | typedef enum token_flags token_flags; | ||
| 42 | enum token_flags | ||
| 43 | { | ||
| 44 | FlagNone = (0), | ||
| 45 | FlagConstant = (1 << 0), | ||
| 46 | FlagGlobal = (1 << 1), | ||
| 47 | FlagsValue = (1 << 2), | ||
| 48 | FlagDefinition = (1 << 3), | ||
| 49 | FlagComparison = (1 << 4), | ||
| 50 | FlagDeprecated = (1 << 5), | ||
| 51 | FlagDirty = (1 << 6), | ||
| 52 | }; | ||
| 53 | |||
| 54 | typedef struct token token; | ||
| 55 | struct token | ||
| 56 | { | ||
| 57 | string8 Lexeme; | ||
| 58 | token_type Type; | ||
| 59 | token_flags Flags; | ||
| 60 | u64 ByteOffset; | ||
| 61 | i32 Column; | ||
| 62 | i32 Line; | ||
| 63 | |||
| 64 | string8 MetaData; | ||
| 65 | }; | ||
| 66 | |||
| 67 | typedef struct token_node token_node; | ||
| 68 | struct token_node | ||
| 69 | { | ||
| 70 | token_node *Next; | ||
| 71 | token_node *Previous; | ||
| 72 | token *Token; | ||
| 73 | }; | ||
| 74 | |||
| 75 | typedef struct token_list token_list; | ||
| 76 | struct token_list | ||
| 77 | { | ||
| 78 | token_node *Root; | ||
| 79 | token_node *Current; | ||
| 80 | }; | ||
| 81 | |||
| 82 | typedef struct lexer lexer; | ||
| 83 | struct lexer | ||
| 84 | { | ||
| 85 | u8 *Text; | ||
| 86 | u64 TextCount; | ||
| 87 | u8 *EndOfFile; | ||
| 88 | u8 *UndefinedTokens; | ||
| 89 | }; | ||
| 90 | |||
| 91 | global_variable const u8 Delimiters[] = | ||
| 92 | { | ||
| 93 | '{', | ||
| 94 | '}', | ||
| 95 | '(', | ||
| 96 | ')', | ||
| 97 | '[', | ||
| 98 | ']', | ||
| 99 | ';', | ||
| 100 | }; | ||
| 101 | |||
| 102 | read_only global_variable token nil_token = | ||
| 103 | { | ||
| 104 | .Lexeme = {NULL, 0}, | ||
| 105 | .Type = TokenUndefined, | ||
| 106 | .Flags = FlagNone, | ||
| 107 | .ByteOffset = 0, | ||
| 108 | .Column = 0, | ||
| 109 | .Line = 0, | ||
| 110 | }; | ||
| 111 | |||
| 112 | read_only global_variable token_node nil_token_node = | ||
| 113 | { | ||
| 114 | .Next = &nil_token_node, | ||
| 115 | .Previous = &nil_token_node, | ||
| 116 | .Token = NULL, | ||
| 117 | }; | ||
| 118 | |||
| 119 | #endif // FAJR_LEXER_H | ||
