Commit 8ae86061d56c325a7c06afa22bac623415008c3e

Thomas de Grivel 2024-07-09T15:16:30

fix buf_parse_tag_call_access with buf_parse_tag_primary_2

diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index d35d8fb..e9c1b1f 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -764,7 +764,7 @@ sw buf_parse_call_access (s_buf *buf, s_call *dest)
   tag_left = &tmp.arguments->tag;
   tmp.ident.module = &g_sym_C3;
   tmp.ident.sym = &g_sym_access;
-  r = buf_parse_tag_primary(buf, &tmp.arguments->tag);
+  r = buf_parse_tag_primary_2(buf, &tmp.arguments->tag);
   if (r <= 0)
     goto clean;
   result += r;
@@ -3462,7 +3462,6 @@ sw buf_parse_tag (s_buf *buf, s_tag *dest)
   }
   if ((r = buf_parse_tag_call_op(buf, dest)) != 0 ||
       (r = buf_parse_tag_brackets(buf, dest)) != 0 ||
-      (r = buf_parse_tag_call_access(buf, dest)) != 0 ||
       (r = buf_parse_tag_primary(buf, dest)) != 0)
     goto end;
  end:
@@ -3750,6 +3749,43 @@ sw buf_parse_tag_primary (s_buf *buf, s_tag *dest)
       goto restore;
     result += r;
   }
+  if ((r = buf_parse_tag_call_access(buf, dest)) != 0 ||
+      (r = buf_parse_tag_primary_2(buf, dest)) != 0)
+    goto end;
+  goto restore;
+ end:
+  if (r < 0)
+    goto restore;
+  if (r > 0) {
+    result += r;
+    if ((r = buf_parse_comments(buf)) > 0)
+      result += r;
+  }
+  r = result;
+  goto clean;
+ restore:
+  buf_save_restore_rpos(buf, &save);
+ clean:
+  buf_save_clean(buf, &save);
+  return r;
+}
+
+sw buf_parse_tag_primary_2 (s_buf *buf, s_tag *dest)
+{
+  sw r;
+  sw result = 0;
+  s_buf_save save;
+  assert(buf);
+  assert(dest);
+  buf_save_init(buf, &save);
+  if ((r = buf_parse_comments(buf)) < 0)
+    goto clean;
+  if (r > 0) {
+    result += r;
+    if ((r = buf_ignore_spaces(buf)) <= 0)
+      goto restore;
+    result += r;
+  }
   if ((r = buf_parse_tag_var(buf, dest)) != 0 ||
       (r = buf_parse_tag_void(buf, dest)) != 0 ||
       (r = buf_parse_tag_number(buf, dest)) != 0 ||
diff --git a/libc3/buf_parse.h b/libc3/buf_parse.h
index 3768158..2b7c1e2 100644
--- a/libc3/buf_parse.h
+++ b/libc3/buf_parse.h
@@ -125,6 +125,7 @@ sw buf_parse_tag_map (s_buf *buf, s_tag *map);
 sw buf_parse_tag_module_name (s_buf *buf, s_tag *module_name);
 sw buf_parse_tag_number (s_buf *buf, s_tag *dest);
 sw buf_parse_tag_primary (s_buf *buf, s_tag *dest);
+sw buf_parse_tag_primary_2 (s_buf *buf, s_tag *dest);
 sw buf_parse_tag_quote (s_buf *buf, s_tag *dest);
 sw buf_parse_tag_special_operator (s_buf *buf, s_tag *dest);
 sw buf_parse_tag_str (s_buf *buf, s_tag *dest);