diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | lib.c | 23 | ||||
-rw-r--r-- | parser.l | 2 | ||||
-rw-r--r-- | parser.y | 2 | ||||
-rw-r--r-- | stream.c | 4 |
5 files changed, 35 insertions, 14 deletions
@@ -1,5 +1,23 @@ 2012-02-12 Kaz Kylheku <kaz@kylheku.com> + * lib.c (obj_print): Print control characters in string and + character literals as hex escapes, followed by semicolon if + necessary. Don't use iswprint function since it is locale-specific + and concludes that non-ASCII characters are unprintable. + Changed print syntax for lazy strings. + (obj_pprint): Changed print syntax for lazy strings. + + * parser.l: Bugfix in hex/octal character constant. + num_esc(yytext) was called rather than num_esc(yytext+1). + + * parser.y (chrlit): Bugfix: missing case for hex and octal + constants which are given by a LITCHAR token. + + * stream.c (vformat): Bugfix: strings were being printed as if using ~a + even under ~s. + +2012-02-12 Kaz Kylheku <kaz@kylheku.com> + Task #11486 * match.c (h_coll): Call consume_prefix in the loop. @@ -3789,7 +3789,12 @@ val obj_print(val obj, val out) { const wchar_t *ptr; put_char(out, chr('"')); + int semi_flag = 0; + for (ptr = c_str(obj); *ptr; ptr++) { + if (semi_flag && iswxdigit(*ptr)) + put_char(out, chr(';')); + semi_flag = 0; switch (*ptr) { case '\a': put_string(out, lit("\\a")); break; case '\b': put_string(out, lit("\\b")); break; @@ -3802,10 +3807,12 @@ val obj_print(val obj, val out) case '\\': put_string(out, lit("\\\\")); break; case 27: put_string(out, lit("\\e")); break; default: - if (iswprint(*ptr)) + if (*ptr >= ' ') { put_char(out, chr(*ptr)); - else - format(out, lit("\\~03o"), num(*ptr), nao); + } else { + format(out, lit("\\x~,02X"), num(*ptr), nao); + semi_flag = 1; + } } } put_char(out, chr('"')); @@ -3828,10 +3835,10 @@ val obj_print(val obj, val out) case 27: put_string(out, lit("esc")); break; case ' ': put_string(out, lit("space")); break; default: - if (iswprint(ch)) + if (ch >= ' ') put_char(out, chr(ch)); else - format(out, lit("x~x"), num(ch), nao); + format(out, lit("x~,02x"), num(ch), nao); } } return obj; @@ -3868,8 +3875,7 @@ val obj_print(val obj, val out) } return obj; case LSTR: - obj_print(obj->ls.prefix, out); - put_string(out, lit("#<... lazy string>")); + format(out, lit("#<lazy-string: ~s>"), obj->ls.prefix); return obj; case COBJ: obj->co.ops->print(obj, out); @@ -3964,8 +3970,7 @@ val obj_pprint(val obj, val out) } return obj; case LSTR: - obj_pprint(obj->ls.prefix, out); - put_string(out, lit("...")); + format(out, lit("#<lazy-string: ~a>"), obj->ls.prefix); return obj; case COBJ: obj->co.ops->print(obj, out); @@ -601,7 +601,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} } <CHRLIT>(x{HEX}+|o{OCT}+) { - yylval.chr = num_esc(yytext); + yylval.chr = num_esc(yytext+1); return LITCHAR; } @@ -812,6 +812,8 @@ chrlit : HASH_BACKSLASH IDENT { wchar_t ch; str, nao); }} end_of_char(); $$ = chr(ch); } + | HASH_BACKSLASH LITCHAR { $$ = chr($2); + end_of_char(); } | HASH_BACKSLASH error { $$ = nil; yybadtoken(yychar, lit("character literal")); } @@ -1010,10 +1010,6 @@ val vformat(val stream, val fmtstr, va_list vl) value = c_num(obj); sprintf(num_buf, num_fmt->dec, value); goto output_num; - } else if (stringp(obj)) { - if (!vformat_str(stream, obj, width, left, precision)) - return nil; - continue; } else if (bignump(obj)) { int nchars = mp_radix_size(mp(obj), 10); if (nchars >= (int) sizeof (num_buf)) |