error when crlf appears in format expression's control-string

Bug #1342005 reported by David Wang
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
SBCL
New
Undecided
Unassigned

Bug Description

When compiling a format expression that contains a tilde "~" followed by a CRLF line-ending, the compiler will catch an error stating the character 'Return' is an unknown directive. For example: (this text-entry field may not faithfully reproduce CRLF line endings, but a CRLF line-ending is critical to produce this error).

(format t "Hello ~
World")

Results in the error:
; caught ERROR:
; during macroexpansion of
; (FORMATTER "Hello ~

; World").
; Use *BREAK-ON-SIGNALS* to intercept.
;
; error in FORMAT: unknown directive (character: Return)

The correct behavior occurs when only the LF (unix-style newline line-ending) appears The directive indicator (~) right before the end of the line in the control-string ("Hello ~ World") acts to suppress the newline in the formatted output, and allows the control-string to be typed across multiple-lines.

This bug will primary occur on SBCL on windows, where CRLF line-endings are the standard, but will most likely occur in any SBCL implementation where a CRLF line-ending occurs in a format expression's control string.

Error occurs on:
* Windows SBCL 1.2.1 (32 and 64 bit, downloaded binaries, running on Windows 7 x64)
* Linux SBCL 1.2.1 (32 bit, compiled from source, running on Ubuntu 12.04)

POSSIBLE FIXES:
I have tried to fix this error in the SBCL src code myself, but have had no luck. I believe I have a good solution strategy for this particular error, but my fixes always require using the lisp character expression #\Return, which causes an error when executing "sh make.sh" to build SBCL. I believe this error stems from the fact that #\Return is not a character in the Lisp-standard-ASCII, and thus the compiler will not accept it as Lisp code.

Both of the fixes I have tried are modifications to "late-format.lisp". Each fix I tried is stand-alone, and does not depend on the other:
* One possible fix involves modifying the function "parse-directive", so there is an additional conditional statement that catches CRLF style line-endings and replaces them with LF style line-endings. This may work alright for this bug, but I believe it may cause other bugs in the strict interpretation of other directives such as "@", where the character immediately following "@" is supposed to be included in the output of format (i.e. "@#\Return#\Newline" should technically force the inclusion of #\Return in the output of format).
* Another possible fix involves the addition of a new format-directive, via the macro:
(def-complex-format-directive #\return (colonp atsignp params directives) ... )

Note: I believe characters such as #\Return are considered semi-standard in the CL spec, and so there is grounds for the SBCL compiler to accept them.

OTHER BUGS:
* This bug may be related to SBCL Bug "#310185 wanted: newline policies in external formats". But, I was unsure what the term "external formats" meant, so I created a new, more specific report.
* This bug was reported to cause issues in the use of another lisp library: https://github.com/tpapp/lla/issues/15

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.