public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>
Subject: [PATCH olang v2 3/4] codestyle: add trailing comma on struct initializer
Date: Fri, 11 Oct 2024 16:57:23 +0000 (UTC)	[thread overview]
Message-ID: <20241011165708.553265-4-carlos@maniero.me> (raw)
In-Reply-To: <20241011165708.553265-1-carlos@maniero.me>

It makes the struct to be formatted that way:

  {
    .a = 1,
    .b = 2,
  }

Instead of:

  { .a = 1,
    .b = 2 }

Unfortunately, there is no config on clang-format to enforce this.

Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
 src/cli.c                     |  5 +++-
 src/lexer.c                   | 51 +++++++++++++++++++++++++++++------
 src/main.c                    |  5 +++-
 src/map.c                     | 14 ++++++++--
 src/string_view.c             |  5 +++-
 tests/unit/string_view_test.c | 20 +++++++++++---
 6 files changed, 83 insertions(+), 17 deletions(-)

diff --git a/src/cli.c b/src/cli.c
index 9d0f875..d6b69e1 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -35,7 +35,10 @@ cli_opts_parse_sysroot(cli_opts_t *opts, cli_args_t *args);
 cli_opts_t
 cli_parse_args(int argc, char **argv)
 {
-    cli_args_t args = { .argc = argc, .argv = argv };
+    cli_args_t args = {
+        .argc = argc,
+        .argv = argv,
+    };
     cli_opts_t opts = { 0 };
 
     opts.compiler_path = cli_args_shift(&args);
diff --git a/src/lexer.c b/src/lexer.c
index c4f645c..03763de 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -90,8 +90,10 @@ lexer_next_token(lexer_t *lexer, token_t *token)
                 current_char = lexer_current_char(lexer);
             }
 
-            string_view_t text = { .chars = lexer->src.code.chars + start_cur.offset,
-                                   .size = lexer->cur.offset - start_cur.offset };
+            string_view_t text = {
+                .chars = lexer->src.code.chars + start_cur.offset,
+                .size = lexer->cur.offset - start_cur.offset,
+            };
 
             lexer_init_str_value_token(lexer, token, lexer_str_to_token_kind(text), start_cur);
             return;
@@ -403,22 +405,52 @@ _isspace(char c)
 static void
 lexer_init_char_value_token(lexer_t *lexer, token_t *token, token_kind_t kind)
 {
-    string_view_t str = { .chars = lexer->src.code.chars + lexer->cur.offset, .size = 1 };
-    *token = (token_t){ .kind = kind, .value = str, .loc = (token_loc_t){ .src = lexer->src, .cur = lexer->cur } };
+    string_view_t str = {
+        .chars = lexer->src.code.chars + lexer->cur.offset,
+        .size = 1,
+    };
+    *token = (token_t){
+        .kind = kind,
+        .value = str,
+        .loc =
+            (token_loc_t){
+                .src = lexer->src,
+                .cur = lexer->cur,
+            },
+    };
 }
 
 static void
 lexer_init_str_value_token(lexer_t *lexer, token_t *token, token_kind_t kind, lexer_cursor_t cur)
 {
-    string_view_t str = { .chars = lexer->src.code.chars + cur.offset, .size = lexer->cur.offset - cur.offset };
-    *token = (token_t){ .kind = kind, .value = str, .loc = (token_loc_t){ .src = lexer->src, .cur = cur } };
+    string_view_t str = {
+        .chars = lexer->src.code.chars + cur.offset,
+        .size = lexer->cur.offset - cur.offset,
+    };
+    *token = (token_t){
+        .kind = kind,
+        .value = str,
+        .loc =
+            (token_loc_t){
+                .src = lexer->src,
+                .cur = cur,
+            },
+    };
 }
 
 static void
 lexer_init_eof_token(lexer_t *lexer, token_t *token)
 {
     string_view_t str = { 0 };
-    *token = (token_t){ .kind = TOKEN_EOF, .value = str, .loc = (token_loc_t){ .src = lexer->src, .cur = lexer->cur } };
+    *token = (token_t){
+        .kind = TOKEN_EOF,
+        .value = str,
+        .loc =
+            (token_loc_t){
+                .src = lexer->src,
+                .cur = lexer->cur,
+            },
+    };
 }
 
 static token_kind_t
@@ -473,7 +505,10 @@ string_view_t
 token_loc_to_line(token_loc_t loc)
 {
     size_t offset = loc.cur.bol;
-    string_view_t line = { .chars = loc.src.code.chars + offset, .size = 0 };
+    string_view_t line = {
+        .chars = loc.src.code.chars + offset,
+        .size = 0,
+    };
 
     while ((line.size + offset) < loc.src.code.size && line.chars[line.size] != '\n' && line.chars[line.size] != 0) {
         ++line.size;
diff --git a/src/main.c b/src/main.c
index d1c76e3..aa09f34 100644
--- a/src/main.c
+++ b/src/main.c
@@ -238,7 +238,10 @@ read_entire_file(char *filepath, arena_t *arena)
 
     fclose(stream);
 
-    return (source_code_t){ .filepath = filepath, .code = code };
+    return (source_code_t){
+        .filepath = filepath,
+        .code = code,
+    };
 }
 
 static void
diff --git a/src/map.c b/src/map.c
index a6bc3a3..42801b0 100644
--- a/src/map.c
+++ b/src/map.c
@@ -86,7 +86,12 @@ map_put(map_t *map, char *key, void *value)
     map_entry_t *entry = map->entries + map_get_index(map, hash);
 
     if (entry->key == NULL) {
-        *entry = (map_entry_t){ .key = _strdup(key, map->arena), .hash = hash, .value = value, .next = NULL };
+        *entry = (map_entry_t){
+            .key = _strdup(key, map->arena),
+            .hash = hash,
+            .value = value,
+            .next = NULL,
+        };
         return true;
     }
 
@@ -97,7 +102,12 @@ map_put(map_t *map, char *key, void *value)
         }
         if (entry->next == NULL) {
             entry->next = (map_entry_t *)arena_alloc(map->arena, sizeof(map_entry_t));
-            *entry->next = (map_entry_t){ .key = _strdup(key, map->arena), .hash = hash, .value = value, .next = NULL };
+            *entry->next = (map_entry_t){
+                .key = _strdup(key, map->arena),
+                .hash = hash,
+                .value = value,
+                .next = NULL,
+            };
 
             break;
         }
diff --git a/src/string_view.c b/src/string_view.c
index b4d4103..13d359c 100644
--- a/src/string_view.c
+++ b/src/string_view.c
@@ -24,7 +24,10 @@
 string_view_t
 string_view_from_cstr(char *cstr)
 {
-    return (string_view_t){ .chars = cstr, .size = strlen(cstr) };
+    return (string_view_t){
+        .chars = cstr,
+        .size = strlen(cstr),
+    };
 }
 
 bool
diff --git a/tests/unit/string_view_test.c b/tests/unit/string_view_test.c
index 7a6776c..d85f19b 100644
--- a/tests/unit/string_view_test.c
+++ b/tests/unit/string_view_test.c
@@ -26,14 +26,20 @@ string_view_eq_to_cstr_test(const MunitParameter params[], void *user_data_or_fi
 {
     char *name = "John Doe";
 
-    string_view_t str = { .chars = name, .size = strlen(name) };
+    string_view_t str = {
+        .chars = name,
+        .size = strlen(name),
+    };
 
     assert_true(string_view_eq_to_cstr(str, "John Doe"));
     assert_false(string_view_eq_to_cstr(str, "Doe"));
 
     char *return_stmt = "return EXIT_SUCCESS;";
 
-    str = (string_view_t){ .chars = return_stmt + 7, .size = 12 };
+    str = (string_view_t){
+        .chars = return_stmt + 7,
+        .size = 12,
+    };
     assert_true(string_view_eq_to_cstr(str, "EXIT_SUCCESS"));
 
     return MUNIT_OK;
@@ -44,11 +50,17 @@ string_view_to_u32_test(const MunitParameter params[], void *user_data_or_fixtur
 {
     char *number = "69";
 
-    string_view_t str = { .chars = number, .size = strlen(number) };
+    string_view_t str = {
+        .chars = number,
+        .size = strlen(number),
+    };
 
     assert_uint32(string_view_to_u32(str), ==, 69);
 
-    str = (string_view_t){ .chars = "39;", .size = 2 };
+    str = (string_view_t){
+        .chars = "39;",
+        .size = 2,
+    };
 
     assert_uint32(string_view_to_u32(str), ==, 39);
 
-- 
2.46.1


  parent reply	other threads:[~2024-10-11 16:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-11 16:57 [PATCH olang v2 0/4] codestyle: change our formater Carlos Maniero
2024-10-11 16:57 ` [PATCH olang v2 1/4] codestyle: prevent extra empty lines at EOF Carlos Maniero
2024-10-11 16:57 ` [PATCH olang v2 2/4] codestyle: do not allow single line enums Carlos Maniero
2024-10-11 16:57 ` Carlos Maniero [this message]
2024-10-11 16:57 ` [PATCH olang v2 4/4] codestyle: limit the code to 80 characters Carlos Maniero
2024-10-11 16:58   ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-12 23:35 ` [PATCH olang v2 0/4] codestyle: change our formater Johnny Richard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241011165708.553265-4-carlos@maniero.me \
    --to=carlos@maniero.me \
    --cc=~johnnyrichard/olang-devel@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox