Commit 6aa3bbe1c0ba1c02f58e9081c074759026faf5e5

Thomas de Grivel 2023-03-22T19:55:13

wip newline

diff --git a/libc3/buf.c b/libc3/buf.c
index 8c3b661..92a2f83 100644
--- a/libc3/buf.c
+++ b/libc3/buf.c
@@ -119,6 +119,33 @@ sw buf_ignore_line (s_buf *buf)
   return result;
 }
 
+sw buf_ignore_newline (s_buf *buf)
+{
+  character c;
+  sw csize;
+  sw r;
+  sw result = 0;
+  s_buf_save save;
+  assert(buf);
+  buf_save_init(buf, &save);
+  while ((r = buf_peek_character_utf8(buf, &c)) > 0 &&
+         character_is_space(c)) {
+    csize = r;
+    if ((r = buf_ignore(buf, csize)) < 0)
+      goto clean;
+    result += csize;
+    if (c == '\n') {
+      r = result;
+      goto clean;
+    }
+  }
+  buf_save_restore_rpos(buf, &save);
+  r = 0;
+ clean:
+  buf_save_clean(buf, &save);
+  return r;
+}
+
 sw buf_ignore_spaces (s_buf *buf)
 {
   character c;
diff --git a/libc3/buf.h b/libc3/buf.h
index 2b0e412..60582ed 100644
--- a/libc3/buf.h
+++ b/libc3/buf.h
@@ -51,6 +51,7 @@ sw      buf_f (s_buf *buf, const char *fmt, ...);
 sw      buf_flush (s_buf *buf);
 sw      buf_ignore (s_buf *buf, uw size);
 sw      buf_ignore_line (s_buf *buf);
+sw      buf_ignore_newline (s_buf *buf);
 sw      buf_ignore_spaces (s_buf *buf);
 sw      buf_peek_1 (s_buf *buf, const s8 *p);
 sw      buf_peek_character_utf8 (s_buf *buf, character *p);
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index db0b35b..ee82c32 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -248,6 +248,12 @@ sw buf_parse_call_op_rec (s_buf *buf, s_call *dest, u8 min_precedence)
     if ((r = buf_parse_tag_primary(buf, right)) <= 0)
       goto restore;
     result += r;
+    if ((r = buf_ignore_newline(buf)) < 0)
+      break;
+    if (r > 0) {
+      result += r;
+      break;
+    }
     if ((r = buf_ignore_spaces(buf)) < 0)
       break;
     result += r;