mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
Write should pipe-escape symbols beginning with a number.
Fixes issue #316.
This commit is contained in:
parent
ec430071eb
commit
55257b75e3
2 changed files with 18 additions and 2 deletions
14
sexp.c
14
sexp.c
|
@ -1191,7 +1191,9 @@ sexp sexp_intern(sexp ctx, const char *str, sexp_sint_t len) {
|
|||
#if SEXP_USE_HUFF_SYMS
|
||||
res = 0;
|
||||
space = 3;
|
||||
if (len == 0) goto normal_intern;
|
||||
if (len == 0 || sexp_isdigit(p[0])
|
||||
|| ((p[0] == '+' || p[0] == '-') && len > 1 && sexp_isdigit(p[1])))
|
||||
goto normal_intern;
|
||||
for ( ; i<len; i++, p++) {
|
||||
c = *p;
|
||||
if ((unsigned char)c <= 32 || (unsigned char)c > 127 || c == '\\' || c == '.' || sexp_is_separator(c))
|
||||
|
@ -1914,7 +1916,15 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) {
|
|||
break;
|
||||
case SEXP_SYMBOL:
|
||||
str = sexp_lsymbol_data(obj);
|
||||
c = (sexp_lsymbol_length(obj) > 1 || (sexp_lsymbol_length(obj) == 1 && str[0] != '.')) ? EOF : '|';
|
||||
c = (sexp_lsymbol_length(obj) == 0 ||
|
||||
(sexp_lsymbol_length(obj) == 1 && str[0] == '.') ||
|
||||
sexp_isdigit(str[0]) ||
|
||||
(sexp_lsymbol_length(obj) > 1 &&
|
||||
(((str[0] == '+' || str[0] == '-')
|
||||
&& (sexp_isdigit(str[1]) || str[1] == '.')) ||
|
||||
(str[sexp_lsymbol_length(obj)-1] == '0' &&
|
||||
str[sexp_lsymbol_length(obj)-2] == '.'))))
|
||||
? '|' : EOF;
|
||||
for (i=sexp_lsymbol_length(obj)-1; i>=0; i--)
|
||||
if (str[i] <= ' ' || str[i] == '\\' || sexp_is_separator(str[i]))
|
||||
c = '|';
|
||||
|
|
|
@ -2104,6 +2104,12 @@
|
|||
(test-write-syntax "|\"|" '|\"|)
|
||||
(test-write-syntax "a" '|a|)
|
||||
;; (test-write-syntax "a.b" '|a.b|)
|
||||
(test-write-syntax "|2|" '|2|)
|
||||
(test-write-syntax "|+3|" '|+3|)
|
||||
(test-write-syntax "|-.4|" '|-.4|)
|
||||
(test-write-syntax "|+inf.0|" '|+inf.0|)
|
||||
(test-write-syntax "|-inf.0|" '|-inf.0|)
|
||||
(test-write-syntax "|+nan.0|" '|+nan.0|)
|
||||
|
||||
(test-end)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue