updated docs and added notes to the lexer
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 27 May 2021 03:48:30 +0000 (22:48 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 27 May 2021 03:48:30 +0000 (22:48 -0500)
CHANGELOG
bin/onyx
docs/module_thoughts
include/onyxlex.h
misc/onyx.sublime-syntax
src/onyxlex.c
src/onyxparser.c

index 1b7b79e80c61a8547fdd2f4767b70cca516db1cd..2cdf3e7c78a9479adbcd07e4708c475e93b195a3 100644 (file)
--- 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:
 
index b0d63f12be1bc99483631ffa016291787b97e4a8..103360201a8ba16651c2920ade432d57f725fd12 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 592da54c53fbb7ac7efa2245b36f5f383e137f00..e56ab6b790766bfb353f2bce4791e96a45abd68b 100644 (file)
@@ -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
index 4d7bb2806a026750c3b5c2c97eeb1adf80cf678f..bbb2d9a64360521b908daf010148aa8b68847075 100644 (file)
@@ -74,6 +74,8 @@ typedef enum TokenType {
     Token_Type_Literal_True,
     Token_Type_Literal_False,
 
+    Token_Type_Note,
+
     Token_Type_Count,
 } TokenType;
 
index 3a4308810620d8e4a6eecf4c83dd115a9b36a05c..950dddea0f1136c8057ca0b7738ef48756c52d61 100644 (file)
@@ -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
 
index b244065c05bdee76313c4f183385285a8be35870..da72ce080fcd3cb0ee53b958acf0655aa35538f7 100644 (file)
@@ -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)))) {
index 0b7195c63590c15f9f61af7c3bb231b96ed90393..3b94e85c81a58151a7351ed3b5d8e2724b48b45e 100644 (file)
@@ -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) {