changed syntax for tagging structures
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 27 Feb 2022 00:49:41 +0000 (18:49 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 27 Feb 2022 00:49:41 +0000 (18:49 -0600)
core/container/map.onyx
misc/vscode/onyx-0.0.2.vsix
misc/vscode/syntaxes/onyx.tmLanguage
misc/vscode/textmate-configuration.json
src/parser.c
tests/interfaces.onyx

index 2571b41d5767ae8fe20085c66204c9993b9d36b1..51219c3ae208590c6162d253cfb01413e5489910 100644 (file)
@@ -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;
index 1802361b50f482a9e9d2987443d1e88bfd75c670..797688cc5c0960ad42d6ce76b92ff8b732df97ec 100644 (file)
Binary files a/misc/vscode/onyx-0.0.2.vsix and b/misc/vscode/onyx-0.0.2.vsix differ
index 1cd19c128dd4e7f1e79214faf5fa73c7ae1da412..0aedf74a6d111e3c65ef79c185161d1ca91b1f75 100644 (file)
                <dict>
                        <key>patterns</key>
                        <array>
+                               <dict>
+                                       <key>match</key>
+                                       <string>({)</string>
+                                       <key>captures</key>
+                                       <dict>
+                                               <key>1</key>
+                                               <dict>
+                                                       <key>name</key>
+                                                       <string>punctuation.block.begin.onyx</string>
+                                               </dict>
+                                       </dict>
+                               </dict>
+
+                               <dict>
+                                       <key>match</key>
+                                       <string>(})</string>
+                                       <key>captures</key>
+                                       <dict>
+                                               <key>1</key>
+                                               <dict>
+                                                       <key>name</key>
+                                                       <string>punctuation.block.end.onyx</string>
+                                               </dict>
+                                       </dict>
+                               </dict>
+
                                <dict>
                                        <key>match</key>
                                        <string>\b(sizeof|alignof|typeof)\b\s*\(</string>
index 00d5e6cb4ba3eb5f4c663d85375e2aecc58f62e6..d61a8ec964f0943b6c0990abc84acea51e3ab263 100644 (file)
         "entity.name.function.onyx",
         "entity.name.type.onyx"
     ],
-    "indentation": {},
+    "indentation": {
+      "punctuation.block.begin.onyx": 1,
+      "punctuation.block.end.onyx": -1
+    },
     "dedentation": [],
     "punctuation": {
       "continuation": ""
index fe4cff224bb96a4f7f52424e3b57891f2babfe06..5e96e892c5ac2b43c62d1bac2a15afe76a3802ee 100644 (file)
@@ -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);
index ea10259a3acb7943267c23660c81df8c667d866f..69c1eb1a86d0dffd91c096e7ad713cdad90ef7d2 100644 (file)
@@ -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);
     }