diff --git a/libkc3/buf_parse.c b/libkc3/buf_parse.c
index 50908d3..00e0433 100644
--- a/libkc3/buf_parse.c
+++ b/libkc3/buf_parse.c
@@ -975,20 +975,14 @@ sw buf_parse_call_op_rec (s_buf *buf, s_call *dest, sw min_precedence)
if (! operator_resolve(&next_op, 2, &next_op) &&
! operator_resolve(&next_op, 1, &next_op))
break;
- if (! operator_precedence(&next_op, &next_op_precedence)) {
- r = -1;
+ if (! operator_precedence(&next_op, &next_op_precedence))
break;
- }
while (1) {
- if (r <= 0 ||
- operator_arity(&next_op) != 2) {
+ if (operator_arity(&next_op) != 2)
break;
- }
if (next_op_precedence <= op_precedence) {
- if (! operator_is_right_associative(&next_op, &b)) {
- r = -1;
- break;
- }
+ if (! operator_is_right_associative(&next_op, &b))
+ goto ok;
if (! b ||
next_op_precedence != op_precedence)
break;
@@ -1000,47 +994,35 @@ sw buf_parse_call_op_rec (s_buf *buf, s_call *dest, sw min_precedence)
op_precedence + 1 : op_precedence)) <= 0) {
tmp2.arguments->tag.type = TAG_VOID;
call_clean(&tmp2);
- break;
+ goto ok;
}
result += r;
tag_init_call(right);
right->data.call = tmp2;
if ((r = buf_ignore_spaces_but_newline(buf)) < 0)
- break;
+ goto ok;
result += r;
if ((r = buf_peek_character_utf8(buf, &c)) <= 0)
- break;
+ goto ok;
if (r > 0 && c == '\n') {
- r = -1;
- break;
+ goto ok;
}
r = buf_peek_ident(buf, &next_op);
- if (r > 0 &&
+ if (r <= 0 ||
(! operator_resolve(&next_op, 2, &next_op) ||
- ! operator_precedence(&next_op, &next_op_precedence))) {
- r = 0;
- break;
- }
+ ! operator_precedence(&next_op, &next_op_precedence)))
+ goto ok;
}
if (r <= 0)
- break;
+ goto ok;
call_init_op(&tmp3);
tmp3.ident = op;
- if (true) {
- tmp3.arguments->tag = *left;
- list_next(tmp3.arguments)->tag = *right;
- tag_init_call(left);
- left->data.call = tmp3;
- }
- else {
- tag_init_call(&tmp3.arguments->tag);
- tmp3.arguments->tag.data.call = tmp;
- list_next(tmp3.arguments)->tag = *right;
- tmp = tmp3;
- left = &tmp.arguments->tag;
- right = &list_next(tmp.arguments)->tag;
- }
+ tmp3.arguments->tag = *left;
+ list_next(tmp3.arguments)->tag = *right;
+ tag_init_call(left);
+ left->data.call = tmp3;
}
+ ok:
call_clean(dest);
*dest = tmp;
r = result;
diff --git a/test/inspect_test.c b/test/inspect_test.c
index de8f058..eac3a31 100644
--- a/test/inspect_test.c
+++ b/test/inspect_test.c
@@ -172,6 +172,20 @@
test_context(NULL); \
} while (0)
+#define INSPECT_TEST_TAG(test, expected) \
+ do { \
+ s_tag tag_test; \
+ s_str str_result; \
+ test_context("inspect_tag(" # test ") -> " # expected); \
+ tag_init_1(&tag_test, (test)); \
+ TEST_EQ(inspect_tag(&tag_test, &str_result), &str_result); \
+ tag_clean(&tag_test); \
+ TEST_EQ(str_result.size, strlen(expected)); \
+ TEST_STRNCMP(str_result.ptr.p, (expected), str_result.size); \
+ str_clean(&str_result); \
+ test_context(NULL); \
+ } while (0)
+
#define INSPECT_TEST_TUPLE(test, expected) \
do { \
s_tuple tuple_test; \
@@ -180,12 +194,9 @@
tuple_init_1(&tuple_test, (test)); \
TEST_EQ(inspect_tuple(&tuple_test, &str_result), &str_result); \
tuple_clean(&tuple_test); \
- if (g_test_last_ok) { \
- TEST_EQ(str_result.size, strlen(expected)); \
- if (g_test_last_ok) \
- TEST_STRNCMP(str_result.ptr.p, (expected), str_result.size); \
- str_clean(&str_result); \
- } \
+ TEST_EQ(str_result.size, strlen(expected)); \
+ TEST_STRNCMP(str_result.ptr.p, (expected), str_result.size); \
+ str_clean(&str_result); \
test_context(NULL); \
} while (0)
@@ -212,6 +223,7 @@ TEST_CASE_PROTOTYPE(inspect_ratio);
TEST_CASE_PROTOTYPE(inspect_str);
TEST_CASE_PROTOTYPE(inspect_struct);
TEST_CASE_PROTOTYPE(inspect_sym);
+TEST_CASE_PROTOTYPE(inspect_tag);
TEST_CASE_PROTOTYPE(inspect_tuple);
TEST_CASE_PROTOTYPE(inspect_var);
@@ -227,6 +239,7 @@ void inspect_test (void)
TEST_CASE_RUN(inspect_str);
TEST_CASE_RUN(inspect_struct);
TEST_CASE_RUN(inspect_sym);
+ TEST_CASE_RUN(inspect_tag);
TEST_CASE_RUN(inspect_tuple);
TEST_CASE_RUN(inspect_var);
}
@@ -500,6 +513,22 @@ TEST_CASE(inspect_sym)
}
TEST_CASE_END(inspect_sym)
+TEST_CASE(inspect_tag)
+{
+ INSPECT_TEST_TAG("1 + 20",
+ "1 + 20");
+ INSPECT_TEST_TAG("1 + 20 / 3",
+ "1 + 20 / 3");
+ INSPECT_TEST_TAG("1 + 20 / 3 + 4",
+ "1 + 20 / 3 + 4");
+ INSPECT_TEST_TAG("1 + 20 / 3 + 4 - 5",
+ "1 + 20 / 3 + 4 - 5");
+ INSPECT_TEST_TAG("a = ? <- 1 ; 2",
+ "a = ? <- 1 ; 2");
+}
+TEST_CASE_END(inspect_tag)
+
+
TEST_CASE(inspect_tuple)
{
INSPECT_TEST_TUPLE("{:a, :b}", "{:a, :b}");