aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-18 02:07:12 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-18 02:07:12 -0500
commite5f706b258fd68c0b6b84cd9e05d741d01a588f4 (patch)
treeb8a903aba2376a3969b4e90bd4e41bc50798185f
parent16e663941a51df9124412be0490446e868fef238 (diff)
Change syntax back to "enum(...)" and "struct(...)"
-rw-r--r--parse.c10
-rw-r--r--types.c102
2 files changed, 57 insertions, 55 deletions
diff --git a/parse.c b/parse.c
index 5c9520ea..56e47e5b 100644
--- a/parse.c
+++ b/parse.c
@@ -1429,7 +1429,7 @@ PARSER(parse_struct_def) {
if (!name) parser_err(ctx, start, pos, "I expected a name for this struct");
spaces(&pos);
- if (!match(&pos, "{"))
+ if (!match(&pos, "("))
parser_err(ctx, pos, pos, "I expected a '(' and a list of fields here");
arg_ast_t *fields = parse_args(ctx, &pos, false);
@@ -1449,7 +1449,7 @@ PARSER(parse_struct_def) {
}
}
- expect_closing(ctx, &pos, "}", "I wasn't able to parse the rest of this struct");
+ expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this struct");
const char *ns_pos = pos;
whitespace(&ns_pos);
@@ -1474,7 +1474,7 @@ ast_t *parse_enum_def(parse_ctx_t *ctx, const char *pos) {
if (!name)
parser_err(ctx, start, pos, "I expected a name for this enum");
spaces(&pos);
- if (!match(&pos, "[")) return NULL;
+ if (!match(&pos, "(")) return NULL;
tag_ast_t *tags = NULL;
int64_t next_value = 0;
@@ -1518,7 +1518,7 @@ ast_t *parse_enum_def(parse_ctx_t *ctx, const char *pos) {
}
whitespace(&pos);
- expect_closing(ctx, &pos, "]", "I wasn't able to parse the rest of this enum definition");
+ expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this enum definition");
REVERSE_LIST(tags);
@@ -1729,7 +1729,7 @@ ast_t *parse_file(file_t *file, jmp_buf *on_err) {
pos = ast->end;
whitespace(&pos);
if (pos < file->text + file->len) {
- parser_err(&ctx, pos, pos + strlen(pos), "I couldn't parse this part of the file %zu");
+ parser_err(&ctx, pos, pos + strlen(pos), "I couldn't parse this part of the file");
}
return ast;
}
diff --git a/types.c b/types.c
index 316877e6..68d3c309 100644
--- a/types.c
+++ b/types.c
@@ -38,22 +38,23 @@ CORD type_to_cord(type_t *t) {
}
case StructType: {
auto struct_ = Match(t, StructType);
- CORD c = CORD_asprintf("%s{", struct_->name);
- int64_t i = 1;
- for (arg_t *field = struct_->fields; field; field = field->next) {
- const char *fname = field->name ? field->name : heap_strf("_%lu", i);
- ++i;
- if (fname && !streq(fname, heap_strf("_%lu", i+1)))
- c = CORD_cat(CORD_cat(c, fname), ":");
- else
- c = CORD_cat(c, ":");
-
- c = CORD_cat(c, type_to_cord(field->type));
-
- if (field->next) c = CORD_cat(c, ", ");
- }
- c = CORD_cat(c, "}");
- return c;
+ return struct_->name;
+ // CORD c = CORD_asprintf("%s(", struct_->name);
+ // int64_t i = 1;
+ // for (arg_t *field = struct_->fields; field; field = field->next) {
+ // const char *fname = field->name ? field->name : heap_strf("_%lu", i);
+ // ++i;
+ // if (fname && !streq(fname, heap_strf("_%lu", i+1)))
+ // c = CORD_cat(CORD_cat(c, fname), ":");
+ // else
+ // c = CORD_cat(c, ":");
+
+ // c = CORD_cat(c, type_to_cord(field->type));
+
+ // if (field->next) c = CORD_cat(c, ", ");
+ // }
+ // c = CORD_cat(c, ")");
+ // return c;
}
case PointerType: {
auto ptr = Match(t, PointerType);
@@ -63,40 +64,41 @@ CORD type_to_cord(type_t *t) {
}
case EnumType: {
auto tagged = Match(t, EnumType);
-
- CORD c = CORD_asprintf("%s[", tagged->name);
- int64_t next_tag = 0;
- for (tag_t *tag = tagged->tags; tag; tag = tag->next) {
- // name, tag_value, type
- c = CORD_cat(c, tag->name);
- if (tag->type) {
- c = CORD_cat(c, "(");
- auto struct_ = Match(tag->type, StructType);
- int64_t i = 1;
- for (arg_t *field = struct_->fields; field; field = field->next) {
- if (field->name && !streq(field->name, heap_strf("_%lu", i)))
- c = CORD_cat(CORD_cat(c, field->name), ":");
-
- CORD fstr = type_to_cord(field->type);
- c = CORD_cat(c, fstr);
- if (field->next) c = CORD_cat(c, ",");
- ++i;
- }
- c = CORD_cat(c, ")");
- }
-
- if (tag->tag_value != next_tag) {
- CORD_sprintf(&c, "%r=%ld", c, tag->tag_value);
- next_tag = tag->tag_value + 1;
- } else {
- ++next_tag;
- }
-
- if (tag->next)
- c = CORD_cat(c, ", ");
- }
- c = CORD_cat(c, "]");
- return c;
+ return tagged->name;
+
+// CORD c = CORD_asprintf("%s(", tagged->name);
+// int64_t next_tag = 0;
+// for (tag_t *tag = tagged->tags; tag; tag = tag->next) {
+// // name, tag_value, type
+// c = CORD_cat(c, tag->name);
+// if (tag->type) {
+// c = CORD_cat(c, "(");
+// auto struct_ = Match(tag->type, StructType);
+// int64_t i = 1;
+// for (arg_t *field = struct_->fields; field; field = field->next) {
+// if (field->name && !streq(field->name, heap_strf("_%lu", i)))
+// c = CORD_cat(CORD_cat(c, field->name), ":");
+
+// CORD fstr = type_to_cord(field->type);
+// c = CORD_cat(c, fstr);
+// if (field->next) c = CORD_cat(c, ",");
+// ++i;
+// }
+// c = CORD_cat(c, ")");
+// }
+
+// if (tag->tag_value != next_tag) {
+// CORD_sprintf(&c, "%r=%ld", c, tag->tag_value);
+// next_tag = tag->tag_value + 1;
+// } else {
+// ++next_tag;
+// }
+
+// if (tag->next)
+// c = CORD_cat(c, ", ");
+// }
+// c = CORD_cat(c, ")");
+// return c;
}
case PlaceholderType: {
return Match(t, PlaceholderType)->name;