diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-07-20 06:55:25 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-07-20 06:55:25 -0700 |
commit | a087f6e4d5d50952ed6c8358e24f692ff79b9f9e (patch) | |
tree | 7da730922448996675755ced3ddea5ad6439783a | |
parent | d4b6ca2a14f7c74bff7563954b5c6d37786d4ca0 (diff) | |
download | txr-a087f6e4d5d50952ed6c8358e24f692ff79b9f9e.tar.gz txr-a087f6e4d5d50952ed6c8358e24f692ff79b9f9e.tar.bz2 txr-a087f6e4d5d50952ed6c8358e24f692ff79b9f9e.zip |
Print notation for quasi-strings and quasi-word-lists.
* lib.c (out_quasi_str): New static function.
(obj_print_impl): Handle sys:quasi and sys:quasilist
forms, reproducing a syntax similar to their read
notation.
-rw-r--r-- | lib.c | 64 |
1 files changed, 64 insertions, 0 deletions
@@ -8785,6 +8785,52 @@ static void out_lazy_str(val lstr, val out) put_char(chr('"'), out); } +static void out_quasi_str(val args, val out) +{ + val iter, next; + + for (iter = cdr(args); iter; iter = next) { + val elem = car(iter); + next = cdr(iter); + + if (stringp(elem)) { + int semi_flag = 0; + out_str_readable(c_str(elem), out, &semi_flag); + } else if (consp(elem)) { + val sym = car(elem); + if (sym == var_s) + { + val next_elem = car(next); + val name = second(elem); + val mods = third(elem); + val next_elem_char = and3(next_elem && !mods, stringp(next_elem), + chr_str(next_elem, zero)); + int need_brace = mods || + (next_elem_char && + (chr_isalpha(next_elem_char) || + chr_isdigit(next_elem_char) || + next_elem_char == chr('_'))); + put_char(chr('@'), out); + if (need_brace) + put_char(chr('{'), out); + obj_print_impl(name, out, nil); + while (mods) { + put_char(chr(' '), out); + obj_print_impl(car(mods), out, nil); + mods = cdr(mods); + } + if (need_brace) + put_char(chr('}'), out); + } else if (sym == expr_s) { + put_char(chr('@'), out); + obj_print_impl(rest(elem), out, nil); + } + } else { + obj_print_impl(elem, out, nil); + } + } +} + val obj_print_impl(val obj, val out, val pretty) { val ret = obj; @@ -8844,6 +8890,24 @@ val obj_print_impl(val obj, val out, val pretty) put_string(lit("."), out); iter = next; } + } else if (sym == quasi_s) { + put_char(chr('`'), out); + out_quasi_str(obj, out); + put_char(chr('`'), out); + } else if (sym == quasilist_s) { + val args = cdr(obj); + put_string(lit("#`"), out); + if (args) { + out_quasi_str(car(args), out); + args = cdr(args); + } + while (args) { + put_char(chr(' '), out); + out_quasi_str(car(args), out); + args = cdr(args); + } + out_quasi_str(cdr(obj), out); + put_char(chr('`'), out); } else { val iter; val closepar = chr(')'); |