From: Brendan Hansen Date: Sun, 27 Feb 2022 00:49:41 +0000 (-0600) Subject: changed syntax for tagging structures X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=e3c68260369b0c47c16d95033084dcb3d88c4437;p=onyx.git changed syntax for tagging structures --- diff --git a/core/container/map.onyx b/core/container/map.onyx index 2571b41d..51219c3a 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -21,9 +21,9 @@ package core.map } } -Map :: struct (Key_Type: type_expr, Value_Type: type_expr) where ValidKey(Key_Type) - [conv.Custom_Format.{ #solidify format_map {K=Key_Type, V=Value_Type} }] -{ +Map :: struct (Key_Type: type_expr, Value_Type: type_expr) where ValidKey(Key_Type) { + #struct_tag conv.Custom_Format.{ #solidify format_map {K=Key_Type, V=Value_Type} }; + allocator : Allocator; hashes : [] i32; diff --git a/misc/vscode/onyx-0.0.2.vsix b/misc/vscode/onyx-0.0.2.vsix index 1802361b..797688cc 100644 Binary files a/misc/vscode/onyx-0.0.2.vsix and b/misc/vscode/onyx-0.0.2.vsix differ diff --git a/misc/vscode/syntaxes/onyx.tmLanguage b/misc/vscode/syntaxes/onyx.tmLanguage index 1cd19c12..0aedf74a 100644 --- a/misc/vscode/syntaxes/onyx.tmLanguage +++ b/misc/vscode/syntaxes/onyx.tmLanguage @@ -291,6 +291,32 @@ patterns + + match + ({) + captures + + 1 + + name + punctuation.block.begin.onyx + + + + + + match + (}) + captures + + 1 + + name + punctuation.block.end.onyx + + + + match \b(sizeof|alignof|typeof)\b\s*\( diff --git a/misc/vscode/textmate-configuration.json b/misc/vscode/textmate-configuration.json index 00d5e6cb..d61a8ec9 100644 --- a/misc/vscode/textmate-configuration.json +++ b/misc/vscode/textmate-configuration.json @@ -23,7 +23,10 @@ "entity.name.function.onyx", "entity.name.type.onyx" ], - "indentation": {}, + "indentation": { + "punctuation.block.begin.onyx": 1, + "punctuation.block.end.onyx": -1 + }, "dedentation": [], "punctuation": { "continuation": "" diff --git a/src/parser.c b/src/parser.c index fe4cff22..5e96e892 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1948,26 +1948,7 @@ static AstStructType* parse_struct(OnyxParser* parser) { } } - // Parse tags bh_arr(AstTyped *) struct_meta_tags=NULL; - if (parser->curr->type == '[') { - expect_token(parser, '['); - if (struct_meta_tags == NULL) bh_arr_new(global_heap_allocator, struct_meta_tags, 1); - - while (parser->curr->type != ']') { - if (parser->hit_unexpected_token) return s_node; - - AstTyped* expr = parse_expression(parser, 0); - bh_arr_push(struct_meta_tags, expr); - - if (parser->curr->type != ']') - expect_token(parser, ','); - } - - expect_token(parser, ']'); - } - - s_node->meta_tags = struct_meta_tags; expect_token(parser, '{'); @@ -1978,6 +1959,15 @@ static AstStructType* parse_struct(OnyxParser* parser) { while (!consume_token_if_next(parser, '}')) { if (parser->hit_unexpected_token) return s_node; + if (parse_possible_directive(parser, "struct_tag")) { + if (struct_meta_tags == NULL) bh_arr_new(global_heap_allocator, struct_meta_tags, 1); + AstTyped* expr = parse_expression(parser, 0); + bh_arr_push(struct_meta_tags, expr); + + consume_token_if_next(parser, ';'); + continue; + } + if (next_tokens_are(parser, 3, Token_Type_Symbol, ':', ':')) { if (!s_node->scope) { s_node->scope = scope_create(context.ast_alloc, parser->current_scope, s_node->token->pos); @@ -2063,6 +2053,7 @@ static AstStructType* parse_struct(OnyxParser* parser) { expect_token(parser, ';'); } + s_node->meta_tags = struct_meta_tags; if (s_node->scope) parser->current_scope = parser->current_scope->parent; bh_arr_free(member_list_temp); diff --git a/tests/interfaces.onyx b/tests/interfaces.onyx index ea10259a..69c1eb1a 100644 --- a/tests/interfaces.onyx +++ b/tests/interfaces.onyx @@ -53,9 +53,10 @@ BitField :: interface (t: $T) { { t ^ t } -> T; } -Complex :: struct [conv.Custom_Format.{ format }] { +Complex :: struct { x, y: f32; + #struct_tag conv.Custom_Format.{ format } format :: (output: ^conv.Format_Output, format: ^conv.Format, c: ^Complex) { conv.format(output, "{.2} + {.2}i", c.x, c.y); }