diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 6b272da..0c95a66 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -24,6 +24,54 @@ sw buf_inspect_str_reserved_size (const s_str *x);
sw buf_inspect_sym_reserved (s_buf *buf, const s_sym *x);
sw buf_inspect_sym_reserved_size (const s_sym *x);
+sw buf_inspect_array (s_buf *buf, const s_array *a)
+{
+ uw *address;
+ sw (* buf_inspect) (s_buf *buf, void *x);
+ sw i = 0;
+ sw r;
+ sw result;
+ assert(a);
+ assert(buf);
+ address = calloc(a->dimension, sizeof(uw));
+ while (i >= 0 && i < a->dimension && address[i] < a->sizes[i]) {
+ if (i < a->dimension - 1) {
+ if (! address[i]) {
+ if ((r = buf_write_1(buf, "[")) < 0)
+ return r;
+ result += r;
+ }
+ }
+ if (i == a->dimension - 1) {
+ switch (a->type) {
+ case TAG_VOID:
+ assert(! "void array");
+ errx(1, "void array");
+ return -1;
+ case TAG_ARRAY:
+ inspect = buf_inspect_array;
+ break;
+ case TAG_BOOL:
+ inspect = buf_inspect_bool;
+ break;
+ }
+ if ((r = inspect(buf, array_data(a, address))) < 0)
+ return r;
+ result += r;
+ }
+ if (i == a->dimension - 1) {
+ while (i >= 0 && address[i] == a->sizes[i]) {
+ if ((r = buf_write_1(buf, "],\n")) < 0)
+ return r;
+ result += r;
+ i--;
+ }
+ break;
+ }
+ i++;
+ }
+}
+
sw buf_inspect_bool (s_buf *buf, e_bool x)
{
if (x)
diff --git a/libc3/buf_inspect.h b/libc3/buf_inspect.h
index b61b1a7..1070c8e 100644
--- a/libc3/buf_inspect.h
+++ b/libc3/buf_inspect.h
@@ -25,6 +25,7 @@
#define BUF_INSPECT_UW_HEX_SIZE (sizeof(uw) / 4)
#define BUF_INSPECT_VAR_SIZE (BUF_INSPECT_UW_HEX_SIZE + 7)
+sw buf_inspect_array (s_buf *buf, s_array *a);
sw buf_inspect_bool (s_buf *buf, e_bool b);
sw buf_inspect_bool_size (e_bool b);
sw buf_inspect_call (s_buf *buf, const s_call *call);
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index f2e9f5f..ff707cf 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -1129,7 +1129,7 @@ sw buf_parse_list (s_buf *buf, s_list **list)
s_buf_save save;
buf_save_init(buf, &save);
i = list;
- if ((r = buf_read_1(buf, "[")) <= 0)
+ if ((r = buf_read_1(buf, "(")) <= 0)
goto clean;
result += r;
if ((r = buf_parse_comments(buf)) < 0)
@@ -1138,7 +1138,7 @@ sw buf_parse_list (s_buf *buf, s_list **list)
if ((r = buf_ignore_spaces(buf)) < 0)
goto restore;
result += r;
- if ((r = buf_read_1(buf, "]")) < 0)
+ if ((r = buf_read_1(buf, ")")) < 0)
goto restore;
if (r > 0) {
result += r;
@@ -1158,7 +1158,7 @@ sw buf_parse_list (s_buf *buf, s_list **list)
if ((r = buf_ignore_spaces(buf)) < 0)
goto restore;
result += r;
- if ((r = buf_read_1(buf, "]")) < 0)
+ if ((r = buf_read_1(buf, ")")) < 0)
goto restore;
if (r > 0) {
result += r;
@@ -1197,7 +1197,7 @@ sw buf_parse_list (s_buf *buf, s_list **list)
if ((r = buf_ignore_spaces(buf)) < 0)
goto restore;
result += r;
- if ((r = buf_read_1(buf, "]")) <= 0)
+ if ((r = buf_read_1(buf, ")")) <= 0)
goto restore;
result += r;
r = result;
diff --git a/libc3/tag.c b/libc3/tag.c
index 0ba431a..8f3ccea 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -291,6 +291,14 @@ s_tag * tag_add (const s_tag *a, const s_tag *b, s_tag *dest)
tag_type_to_string(b->type.type));
}
+s_tag * tag_array (s_tag *tag, s_array *a)
+{
+ assert(tag);
+ assert(a);
+ tag_clean(tag);
+ return tag_init_array(a);
+}
+
s_tag * tag_bool (s_tag *tag, bool b)
{
assert(tag);
@@ -810,6 +818,15 @@ s_tag * tag_init_1 (s_tag *tag, const s8 *p)
return tag;
}
+s_tag * tag_init_array (s_tag *tag, const s_array *a)
+{
+ assert(tag);
+ assert(a);
+ tag->type.type = TAG_ARRAY;
+ array_copy(a, &tag->data.array);
+ return tag;
+}
+
s_tag * tag_init_bool (s_tag *tag, bool b)
{
assert(tag);
@@ -1451,6 +1468,15 @@ s_tag * tag_new_1 (const s8 *p)
return tag_init_1(tag, p);
}
+s_tag * tag_new_array (s_array *a)
+{
+ s_tag *dest;
+ assert(a);
+ if (! (dest = malloc(sizeof(s_tag))))
+ errx(1, "tag_new_array: out of memory");
+ return tag_init_array(dest, a);
+}
+
s_tag * tag_new_copy (const s_tag *src)
{
s_tag *dest;
diff --git a/libc3/tag.h b/libc3/tag.h
index f60b4cd..16379ec 100644
--- a/libc3/tag.h
+++ b/libc3/tag.h
@@ -33,6 +33,7 @@ extern s_tag g_tag_last;
/* Stack allocation compatible functions */
s_tag * tag_init (s_tag *tag);
s_tag * tag_init_1 (s_tag *tag, const s8 *p);
+s_tag * tag_init_array (s_tag *tag, s_array *a);
s_tag * tag_init_bool (s_tag *tag, bool p);
s_tag * tag_init_call (s_tag *tag, const s_call *call);
s_tag * tag_init_character (s_tag *tag, character c);
@@ -65,7 +66,7 @@ void tag_clean (s_tag *tag);
/* Constructors, call tag_delete after use */
s_tag * tag_new ();
s_tag * tag_new_1 (const s8 *p);
-s_tag * tag_new_str (s8 *free, uw size, const s8 *p);
+s_tag * tag_new_array (s_array *a);
s_tag * tag_new_bool (bool p);
s_tag * tag_new_character (character c);
s_tag * tag_new_copy (const s_tag *src);
@@ -76,6 +77,7 @@ s_tag * tag_new_s8 (s8 i);
s_tag * tag_new_s16 (s16 i);
s_tag * tag_new_s32 (s32 i);
s_tag * tag_new_s64 (s64 i);
+s_tag * tag_new_str (s8 *free, uw size, const s8 *p);
s_tag * tag_new_tuple_2 (s_tag *a, s_tag *b);
s_tag * tag_new_u8 (u8 i);
s_tag * tag_new_u16 (u16 i);
@@ -100,6 +102,7 @@ s8 * tag_type_to_string (e_tag_type type);
/* Modifiers */
s_tag * tag_1 (s_tag *tag, const s8 *p);
+s_tag * tag_array (s_tag *tag, s_array *a);
s_tag * tag_bool (s_tag *tag, bool p);
s_tag * tag_cast_integer_to_s16 (s_tag *tag);
s_tag * tag_cast_integer_to_s32 (s_tag *tag);
diff --git a/libc3/types.h b/libc3/types.h
index ef5dc89..a1876c8 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -56,7 +56,8 @@ typedef enum {
typedef enum {
TAG_VOID = 0,
- TAG_BOOL = 1,
+ TAG_ARRAY,
+ TAG_BOOL,
TAG_CALL,
TAG_CALL_FN,
TAG_CALL_MACRO,
@@ -139,6 +140,7 @@ typedef u64 t_skiplist_height;
/* 1 */
struct array {
uw dimension;
+ e_tag_type type;
uw *sizes;
uw size;
void *data;
diff --git a/test/ic3/list.in b/test/ic3/list.in
index 1c2d275..06076de 100644
--- a/test/ic3/list.in
+++ b/test/ic3/list.in
@@ -1,28 +1,28 @@
-[]
-[[] | []]
-[[], []]
-[[], [], []]
-[[], [], [], []]
-[[], [] | []]
-[[], [], [] | []]
-[[] | [[], []]]
-[[] | [[], [], []]]
-[[] | [[] | []]]
-[[] | [[], [] | []]]
-[[] | [[], [], [] | []]]
-[[[], []] | [[], []]]
-[[[] | []] | [[] | []]]
-[a]
-[a, b]
-[a, b, c]
-[a | b]
-[a, b | c]
-[a, b, c, d]
-[a, b, c | d]
+()
+(() | ())
+((), ())
+((), (), ())
+((), (), (), ())
+((), () | ())
+((), (), () | ())
+(() | ((), ()))
+(() | ((), (), ()))
+(() | (() | ()))
+(() | ((), () | ()))
+(() | ((), (), () | ()))
+(((), ()) | ((), ()))
+((() | ()) | (() | ()))
+(a)
+(a, b)
+(a, b, c)
+(a | b)
+(a, b | c)
+(a, b, c, d)
+(a, b, c | d)
# comment 0
# comment 0b
-[ # comment 1
+( # comment 1
# comment 1b
a # comment 2
# comment 2b
@@ -38,5 +38,5 @@
## comment 7b
d ## comment 8
## comment 8b
- ] ## comment 9
+ ) ## comment 9
## comment 9b