From: Brendan Hansen Date: Thu, 27 May 2021 03:48:30 +0000 (-0500) Subject: updated docs and added notes to the lexer X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=cf37b85db8c10cb4718bb92162a7aec09522f627;p=onyx.git updated docs and added notes to the lexer --- diff --git a/CHANGELOG b/CHANGELOG index 1b7b79e8..2cdf3e7c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -22,6 +22,10 @@ Additions: * logging allocator. Wraps any allocator and prints what kind of allocations are happening. * many math functions. * basics of reading environment variables +* Relative file inclusion using "./" at the start of the path +* Basics of "notes" in the code. Basically special comments that allow you to easily search in the code. + Currently this is not something very useful in the language, but I wanted a way to write searchable + notes without having to parse comments. The syntax is "@Note". Removals: diff --git a/bin/onyx b/bin/onyx index b0d63f12..10336020 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/docs/module_thoughts b/docs/module_thoughts index 592da54c..e56ab6b7 100644 --- a/docs/module_thoughts +++ b/docs/module_thoughts @@ -25,3 +25,5 @@ Things that need to be done in the compiler: If the string starts with './', it should be considered relative. This will make it easier for modules to include their files, regardless of how the project is set up. + + ✔ This has been done diff --git a/include/onyxlex.h b/include/onyxlex.h index 4d7bb280..bbb2d9a6 100644 --- a/include/onyxlex.h +++ b/include/onyxlex.h @@ -74,6 +74,8 @@ typedef enum TokenType { Token_Type_Literal_True, Token_Type_Literal_False, + Token_Type_Note, + Token_Type_Count, } TokenType; diff --git a/misc/onyx.sublime-syntax b/misc/onyx.sublime-syntax index 3a430881..950dddea 100644 --- a/misc/onyx.sublime-syntax +++ b/misc/onyx.sublime-syntax @@ -48,6 +48,9 @@ contexts: - match: '#[a-zA-Z_]+' scope: keyword.other.onyx + - match: '@[a-zA-Z0-9_]+' + scope: meta.toc-list.task-tag.note.onyx + - match: '\$[a-zA-Z0-9_]+' scope: constant.other.onyx diff --git a/src/onyxlex.c b/src/onyxlex.c index b244065c..da72ce08 100644 --- a/src/onyxlex.c +++ b/src/onyxlex.c @@ -71,6 +71,8 @@ static const char* token_type_names[] = { "true", "false", + "NOTE" + "TOKEN_TYPE_COUNT" }; @@ -250,6 +252,20 @@ whitespace_skipped: goto token_parsed; } + if (*tokenizer->curr == '@') { + INCREMENT_CURR_TOKEN(tokenizer); + u32 len = 2; + while (char_is_alphanum(*(tokenizer->curr + 1)) || *(tokenizer->curr + 1) == '_') { + len++; + INCREMENT_CURR_TOKEN(tokenizer); + } + + tk.type = Token_Type_Note; + tk.length = len; + INCREMENT_CURR_TOKEN(tokenizer); + goto token_parsed; + } + // Number literal if (char_is_num(*tokenizer->curr) || (*(tokenizer->curr) == '.' && char_is_num(*(tokenizer->curr + 1)))) { diff --git a/src/onyxparser.c b/src/onyxparser.c index 0b7195c6..3b94e85c 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -75,7 +75,8 @@ static void consume_token(OnyxParser* parser) { parser->prev = parser->curr; // :LinearTokenDependent parser->curr++; - while (parser->curr->type == Token_Type_Comment) parser->curr++; + while (parser->curr->type == Token_Type_Comment || parser->curr->type == Token_Type_Note) + parser->curr++; } static OnyxToken* find_matching_paren(OnyxToken* paren) { @@ -144,6 +145,7 @@ static b32 next_tokens_are(OnyxParser* parser, i32 n, ...) { i32 matched = 1; + // BUG: This does not take into consideration comments and notes that can occur between any tokens. fori (i, 0, n) { TokenType expected_type = va_arg(va, TokenType); if (peek_token(i)->type != expected_type) {