From: Brendan Hansen Date: Tue, 1 Sep 2020 03:11:03 +0000 (-0500) Subject: added block comments (kinda); bug fixes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=48e62a50249c685b972a1b30abee0cb09d11dfd8;p=onyx.git added block comments (kinda); bug fixes --- diff --git a/misc/onyx.sublime-syntax b/misc/onyx.sublime-syntax index 9a6f2e04..6d0bbfcd 100644 --- a/misc/onyx.sublime-syntax +++ b/misc/onyx.sublime-syntax @@ -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 421c6822..59cbb27a 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/poly_test.onyx b/progs/poly_test.onyx index 8feafe2e..b8b9ba62 100644 --- a/progs/poly_test.onyx +++ b/progs/poly_test.onyx @@ -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; diff --git a/src/onyxlex.c b/src/onyxlex.c index 4d3e3fdb..4f6945db 100644 --- a/src/onyxlex.c +++ b/src/onyxlex.c @@ -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; diff --git a/src/onyxparser.c b/src/onyxparser.c index d3fe8209..cd8601bb 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -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);