fix symbol prining with #\uFEFF characters

Since the reader now treats #\uFEFF as whitespace, adjust the printer to
escape \uFEFFa.

Thanks, Xsmith!

Writing an actual #\uFEFF character seems bad, even escaped, but
Racket's symbol syntax doesn't have a kind of escaping that uses
different characters than the one to be represented.

Closes #3486
This commit is contained in:
Matthew Flatt 2020-11-06 12:20:47 -07:00
parent 6b7a184297
commit 128174594e
4 changed files with 69 additions and 60 deletions

View File

@ -67,6 +67,7 @@
(ptest "'||" '||)
(ptest "'|;|" '|;|)
(ptest "'|`|" '|`|)
(ptest "'|\uFEFF_|" (string->symbol "\uFEFF_"))
(ptest "'#:apple" '#:apple)
(ptest "'#:|apple pie|" '#:|apple pie|)
(ptest "'#:|.|" '#:|.|)

View File

@ -659,7 +659,8 @@ const char *scheme_symbol_name_and_size(Scheme_Object *sym, uintptr_t *length, i
/* space is OK in type symbols */
} else
has_space = 1;
} else if (isSpecial(ch))
} else if (isSpecial(ch)
|| (ch == 0xFEFF)) /* BOM, treated as whitespace by the reader */
has_special = 1;
else if (ch == '|')
has_pipe = 1;

View File

@ -20908,62 +20908,68 @@
(if or-part_11
or-part_11
(let ((or-part_12
(char=?
ch_0
'#\xfeff)))
(if or-part_12
or-part_12
(let ((or-part_13
(if (char=?
ch_0
'#\x7c)
(let ((or-part_12
(let ((or-part_13
(not
config8_0)))
(if or-part_12
or-part_12
(if or-part_13
or-part_13
(config-get
config8_0
1/read-accept-bar-quote)))
#f)))
(if or-part_12
or-part_12
(let ((or-part_13
(if or-part_13
or-part_13
(let ((or-part_14
(if for-type?9_0
(let ((or-part_13
(let ((or-part_14
(char=?
ch_0
'#\x3c)))
(if or-part_13
or-part_13
(if or-part_14
or-part_14
(char=?
ch_0
'#\x3e)))
#f)))
(if or-part_13
or-part_13
(let ((or-part_14
(if (char-whitespace?
ch_0)
(let ((or-part_14
(not
for-type?9_0)))
(if or-part_14
or-part_14
(let ((or-part_15
(if (char-whitespace?
ch_0)
(let ((or-part_15
(not
for-type?9_0)))
(if or-part_15
or-part_15
(not
(char=?
ch_0
'#\x20))))
#f)))
(if or-part_14
or-part_14
(let ((or-part_15
(if or-part_15
or-part_15
(let ((or-part_16
(if (char=?
ch_0
'#\x23)
(if (zero?
i_0)
(let ((or-part_15
(let ((or-part_16
(<
(string-length
str_0)
2)))
(if or-part_15
or-part_15
(if or-part_16
or-part_16
(not
(char=?
(string-ref
@ -20972,9 +20978,9 @@
'#\x25))))
#f)
#f)))
(if or-part_15
or-part_15
(let ((or-part_16
(if or-part_16
or-part_16
(let ((or-part_17
(if (char=?
ch_0
'#\x2e)
@ -20986,8 +20992,8 @@
1)
#f)
#f)))
(if or-part_16
or-part_16
(if or-part_17
or-part_17
(if (not
case-sensitive?_0)
(not
@ -20995,7 +21001,7 @@
ch_0
(char-foldcase
ch_0)))
#f))))))))))))))))))))))))))))))))))))))))
#f))))))))))))))))))))))))))))))))))))))))))
(loop_0
(|#%name|
loop

View File

@ -35,6 +35,7 @@
(char=? ch #\,)
(char=? ch #\;)
(char=? ch #\`)
(char=? ch #\uFEFF) ; BOM, treated as whitespace by the reader
(and (char=? ch #\|)
(or (not config) (config-get config read-accept-bar-quote)))
(and for-type?