summaryrefslogtreecommitdiffhomepage
path: root/ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/ast.c b/ast.c
index 0c9abe8..823b2a7 100644
--- a/ast.c
+++ b/ast.c
@@ -297,10 +297,13 @@ func_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
struct ut_function *fn = op->tag.data;
size_t i, len;
- sprintbuf(pb, "%sfunction%s%s(",
- strict ? "\"" : "",
- fn->name ? " " : "",
- fn->name ? fn->name : "");
+ if (op->is_arrow)
+ sprintbuf(pb, "%s(", strict ? "\"" : "");
+ else
+ sprintbuf(pb, "%sfunction%s%s(",
+ strict ? "\"" : "",
+ fn->name ? " " : "",
+ fn->name ? fn->name : "");
if (fn->args) {
len = json_object_array_length(fn->args);
@@ -314,7 +317,9 @@ func_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
}
}
- return sprintbuf(pb, ") { ... }%s", strict ? "\"" : "");
+ return sprintbuf(pb, ") %s{ ... }%s",
+ op->is_arrow ? "=> " : "",
+ strict ? "\"" : "");
}
struct json_object *
@@ -360,6 +365,7 @@ ut_new_func(struct ut_state *s, struct ut_op *decl, struct ut_scope *scope)
op->val = val;
op->type = T_FUNC;
+ op->is_arrow = (decl->type == T_ARROW);
op->tag.data = fn;
json_object_set_serializer(val, func_to_string, op, func_free);