added block comments (kinda); bug fixes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Sep 2020 03:11:03 +0000 (22:11 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Sep 2020 03:11:03 +0000 (22:11 -0500)
misc/onyx.sublime-syntax
onyx
progs/poly_test.onyx
src/onyxlex.c
src/onyxparser.c

index 9a6f2e04ae9468f1bff4ae4e115958a0f741b4ac..6d0bbfcd6a45c12f53638ec3173e7645ecdd40db 100644 (file)
@@ -17,6 +17,9 @@ contexts:
     - match: '//'
       scope: punctuation.definition.comment.onyx
       push: line_comment
+    - match: '/\*'
+      scope: punctuation.definition.comment.onyx
+      push: block_comment
 
     # Keywords are if, else for and while.
     # Note that blackslashes don't need to be escaped within single quoted
@@ -54,3 +57,10 @@ contexts:
     - meta_scope: comment.line.onyx
     - match: $
       pop: true
+
+  block_comment:
+    - meta_scope: comment.block.onyx
+    - match: '\*/'
+      pop: true
+    - match: '/\*'
+      push: block_comment
\ No newline at end of file
diff --git a/onyx b/onyx
index 421c68222492f731b377b666e4487f71f41b1664..59cbb27a1016132ac78f5036ebf4353b3347dc7c 100755 (executable)
Binary files a/onyx and b/onyx differ
index 8feafe2ef4e1986c3868715c2b346aa5b2fb3a8b..b8b9ba6295e7cd4442b78b91958bb7d46e6d8107 100644 (file)
@@ -41,6 +41,13 @@ Dummy :: struct {
 }
 
 
+/* TODO: Make this work at some point
+   compose :: proc (a: $A, f: proc (A) -> $B, g: proc (B) -> $C) -> C {
+      return a |> f() |> g();
+   }
+*/
+
+
 
 SOA :: struct {
     b  : [..] i64;
index 4d3e3fdbc6c74df32fea54c3302da3253ea14daf..4f6945db5de36d9c87a788537f41f9a4a017aa01 100644 (file)
@@ -169,6 +169,32 @@ whitespace_skipped:
         goto token_parsed;
     }
 
+    if (*tokenizer->curr == '/' && *(tokenizer->curr + 1) == '*') {
+        tokenizer->curr += 2;
+        tk.type = Token_Type_Comment;
+        tk.text = tokenizer->curr;
+
+        i32 comment_depth = 1;
+
+        while (comment_depth > 0 && tokenizer->curr != tokenizer->end) {
+            if (*tokenizer->curr == '/' && *(tokenizer->curr + 1) == '*') {
+                tokenizer->curr += 2;
+                comment_depth += 1;
+            }
+
+            else if (*tokenizer->curr == '*' && *(tokenizer->curr + 1) == '/') {
+                tokenizer->curr += 2;
+                comment_depth -= 1;
+            }
+
+            else {
+                INCREMENT_CURR_TOKEN(tokenizer);
+            }
+        }
+
+        goto token_parsed;
+    }
+
     // String literal
     if (*tk.text == '"') {
         u64 len = 0;
index d3fe82099748c89959d21a8affcb2fc7720d60ce..cd8601bbf0c52ede46a2b9f8948cd466bf202fb0 100644 (file)
@@ -1268,10 +1268,13 @@ static AstType* parse_type(OnyxParser* parser, bh_arr(AstPolyParam)* poly_vars)
         }
 
         else if (parser->curr->type == '$') {
+            bh_arr(AstPolyParam) pv = NULL;
+
             if (poly_vars == NULL)
                 onyx_report_error(parser->curr->pos, "polymorphic variable not valid here.");
+            else
+                pv = *poly_vars;
 
-            bh_arr(AstPolyParam) pv = *poly_vars;
             consume_token(parser);
 
             AstNode* symbol_node = make_node(AstNode, Ast_Kind_Symbol);