From 6fb34ff4e32cab93f437ed6c3d93042b87024437 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 8 Sep 2022 18:36:12 -0700 Subject: syntax: read and print [. x] and [. @x]. * lib.c (obj_print_impl): Handle (dwim . atom) syntax by printing [. atom]. Note that (dwim . @var) and (dwim . @(expr)) already print as [. @var] and [. @(expr)]; this is not new. But none of these forms are supported by reading without the accompanying change to the parser. * parser.y (dwim): Handle the [. expr] and [ . expr] syntax, so that forms like [. a] and [. @a] have print-read consistency. The motivation is to be able to [. @args] in pattern matching to match a DWIM forms; I tried that and was surprised to have it blow up in my face. * tests/012/readprint.tl: New test file. Future printer/parser changes will be tested here. Historically, changes to the syntax have not been consistently unit-tested. * y.tab.c.shipped: Regenerated. --- lib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index fbb5d9e8..9e220f10 100644 --- a/lib.c +++ b/lib.c @@ -14099,8 +14099,14 @@ val obj_print_impl(val obj, val out, val pretty, struct strm_ctx *ctx) cnum max_len = ctx->strm->max_length; cnum max_count = max_len; - if (sym == dwim_s && have_args) { + if (sym == dwim_s) { put_char(chr('['), out); + if (!have_args) { + put_string(lit(". "), out); + obj_print_impl(args, out, pretty, ctx); + put_char(chr(']'), out); + break; + } obj = args; closepar = chr(']'); } else { -- cgit v1.2.3