diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 770f9de..7e376c0 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -3433,10 +3433,10 @@ sw buf_parse_unquote (s_buf *buf, s_unquote *dest)
if ((r = buf_read_1(buf, "unquote(")) <= 0)
goto clean;
result += r;
- if ((r = buf_parse_comments(buf)) <= 0)
+ if ((r = buf_parse_comments(buf)) < 0)
goto restore;
result += r;
- if ((r = buf_ignore_spaces(buf)) <= 0)
+ if ((r = buf_ignore_spaces(buf)) < 0)
goto restore;
result += r;
unquote.tag = tag_new();
@@ -3449,10 +3449,10 @@ sw buf_parse_unquote (s_buf *buf, s_unquote *dest)
goto restore;
}
result += r;
- if ((r = buf_parse_comments(buf)) <= 0)
+ if ((r = buf_parse_comments(buf)) < 0)
goto restore;
result += r;
- if ((r = buf_ignore_spaces(buf)) <= 0)
+ if ((r = buf_ignore_spaces(buf)) < 0)
goto restore;
result += r;
if ((r = buf_read_1(buf, ")")) <= 0)
diff --git a/libc3/c3.h b/libc3/c3.h
index eaa3bd5..c89c2c8 100644
--- a/libc3/c3.h
+++ b/libc3/c3.h
@@ -93,6 +93,7 @@
#include "u64.h"
#include "uw.h"
#include "ucd.h"
+#include "unquote.h"
#include "var.h"
#include "void.h"
diff --git a/test/buf_parse_test.c b/test/buf_parse_test.c
index 358b26f..5828eeb 100644
--- a/test/buf_parse_test.c
+++ b/test/buf_parse_test.c
@@ -582,6 +582,17 @@
test_context(NULL); \
} while (0)
+#define BUF_PARSE_TEST_UNQUOTE(test) \
+ do { \
+ s_buf buf; \
+ s_unquote dest = {0}; \
+ test_context("buf_parse_unquote(" # test ")"); \
+ buf_init_1(&buf, false, (test)); \
+ TEST_EQ(buf_parse_unquote(&buf, &dest), strlen(test)); \
+ unquote_clean(&dest); \
+ test_context(NULL); \
+ } while (0)
+
TEST_CASE_PROTOTYPE(buf_parse_array);
TEST_CASE_PROTOTYPE(buf_parse_bool);
TEST_CASE_PROTOTYPE(buf_parse_call);
@@ -608,6 +619,7 @@ TEST_CASE_PROTOTYPE(buf_parse_str_u8);
TEST_CASE_PROTOTYPE(buf_parse_sym);
TEST_CASE_PROTOTYPE(buf_parse_tag);
TEST_CASE_PROTOTYPE(buf_parse_tuple);
+TEST_CASE_PROTOTYPE(buf_parse_unquote);
void buf_parse_test (void)
{
@@ -621,6 +633,7 @@ void buf_parse_test (void)
TEST_CASE_RUN(buf_parse_digit_dec);
TEST_CASE_RUN(buf_parse_str_character);
TEST_CASE_RUN(buf_parse_str_u8);
+ TEST_CASE_RUN(buf_parse_cfn);
TEST_CASE_RUN(buf_parse_character);
TEST_CASE_RUN(buf_parse_f32);
TEST_CASE_RUN(buf_parse_f64);
@@ -636,6 +649,7 @@ void buf_parse_test (void)
TEST_CASE_RUN(buf_parse_list);
TEST_CASE_RUN(buf_parse_tag);
TEST_CASE_RUN(buf_parse_tuple);
+ TEST_CASE_RUN(buf_parse_unquote);
#ifdef C3_TEST_BUF_PARSE_SU
TEST_CASE_RUN(buf_parse_u8_binary);
TEST_CASE_RUN(buf_parse_u8_octal);
@@ -688,7 +702,6 @@ void buf_parse_test (void)
TEST_CASE_RUN(buf_parse_s8_decimal_negative);
TEST_CASE_RUN(buf_parse_sw);
#endif /* C3_TEST_BUF_PARSE_SU */
- TEST_CASE_RUN(buf_parse_cfn);
}
TEST_CASE(buf_parse_array)
@@ -1296,6 +1309,16 @@ TEST_CASE(buf_parse_u)
}
TEST_CASE_END(buf_parse_u)
+TEST_CASE(buf_parse_unquote)
+{
+ BUF_PARSE_TEST_UNQUOTE("unquote(1)");
+ BUF_PARSE_TEST_UNQUOTE("unquote(1 + 1)");
+ BUF_PARSE_TEST_UNQUOTE("unquote(ident)");
+ BUF_PARSE_TEST_UNQUOTE("unquote(:sym)");
+ BUF_PARSE_TEST_UNQUOTE("unquote(\"str\")");
+}
+TEST_CASE_END(buf_parse_unquote)
+
TEST_CASE(buf_parse_uw)
{
}
diff --git a/test/ic3/macro.out.expected b/test/ic3/macro.out.expected
index b8e2273..6ebf96d 100644
--- a/test/ic3/macro.out.expected
+++ b/test/ic3/macro.out.expected
@@ -1,5 +1,5 @@
-m = macro (name) { quote "Hello, " + (unquote name) + " !" }
-macro (name) { quote "Hello, " + (unquote name) + " !" }
+m = macro (name) { quote "Hello, " + unquote(name) + " !" }
+macro (name) { quote "Hello, " + unquote(name) + " !" }
m("Terrence")
"Hello, Terrence !"
n = "Phillip"
diff --git a/test/ic3/quote.out.expected b/test/ic3/quote.out.expected
index db57b2b..1907e64 100644
--- a/test/ic3/quote.out.expected
+++ b/test/ic3/quote.out.expected
@@ -23,8 +23,8 @@ quote %{1 => 1}
quote %{1 => 1}
quote %{1 + 1 => 1}
quote %{1 => 1 + 1}
-quote %{unquote 1 + 1 => 1}
-quote %{1 => unquote 1 + 1}
+quote %{unquote(1 + 1) => 1}
+quote %{1 => unquote(1 + 1)}
1
2
4