1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-25 04:40:19 +02:00

Enable character hex escapes by default

R6RS character hex escapes do not conflict with legacy Guile octal
character escapes, so they can be enabled by default.

* libguile/read.c (scm_read_character): modified
* test-suite/tests/reader.test: modify character escape tests
* doc/ref/api-data.texi: modified
* doc/ref/api-options.texi: modified
This commit is contained in:
Michael Gran 2010-07-17 04:16:57 -07:00
parent 211683cc5c
commit 0f3a70cfa8
4 changed files with 15 additions and 31 deletions

View file

@ -1763,17 +1763,9 @@ Characters may also be written using their code point values. They can
be written with as an octal number, such as @code{#\10} for be written with as an octal number, such as @code{#\10} for
@code{#\bs} or @code{#\177} for @code{#\del}. @code{#\bs} or @code{#\177} for @code{#\del}.
When the @code{r6rs-hex-escapes} reader option is enabled, there is an If one prefers hex to octal, there is an additional syntax for character
additional syntax for character escapes: @code{#\xHHHH} -- the letter 'x' escapes: @code{#\xHHHH} -- the letter 'x' followed by a hexadecimal
followed by a hexadecimal number of one to eight digits. number of one to eight digits.
@lisp
(read-enable 'r6rs-hex-escapes)
@end lisp
Enabling this option will also change the hex escape format for strings. More
on string escapes can be found at (@pxref{String Syntax}). More on reader
options in general can be found at (@pxref{Reader options}).
@rnindex char? @rnindex char?
@deffn {Scheme Procedure} char? x @deffn {Scheme Procedure} char? x
@ -2698,9 +2690,8 @@ it can be enabled with the reader option @code{r6rs-hex-escapes}.
(read-enable 'r6rs-hex-escapes) (read-enable 'r6rs-hex-escapes)
@end lisp @end lisp
Enabling this option will also change the hex escape format for characters. More on reader options in general can be found at (@pxref{Reader
More on character escapes can be found at (@pxref{Characters}). More on options}).
reader options in general can be found at (@pxref{Reader options}).
@node String Predicates @node String Predicates
@subsubsection String Predicates @subsubsection String Predicates

View file

@ -509,7 +509,7 @@ keywords #f Style of keyword recognition: #f, 'prefix or 'postfix
case-insensitive no Convert symbols to lower case. case-insensitive no Convert symbols to lower case.
positions yes Record positions of source code expressions. positions yes Record positions of source code expressions.
copy no Copy source code expressions. copy no Copy source code expressions.
r6rs-hex-escapes no Use R6RS-style string and character hex escapes r6rs-hex-escapes no Use R6RS-style string hex escapes
@end smalllisp @end smalllisp
Notice that while Standard Scheme is case insensitive, to ease Notice that while Standard Scheme is case insensitive, to ease
@ -523,7 +523,7 @@ To make Guile case insensitive, you can type
@end lisp @end lisp
For more information on the effect of the @code{r6rs-hex-escapes} option, see For more information on the effect of the @code{r6rs-hex-escapes} option, see
(@pxref{Characters}) and (@pxref{String Syntax}). (@pxref{String Syntax}).
@node Printing options @node Printing options
@subsubsection Printing options @subsubsection Printing options

View file

@ -972,7 +972,7 @@ scm_read_character (scm_t_wchar chr, SCM port)
} }
} }
if (cp == 'x' && (charname_len > 1) && SCM_R6RS_ESCAPES_P) if (cp == 'x' && (charname_len > 1))
{ {
SCM p; SCM p;

View file

@ -332,28 +332,21 @@
"\\xff;\\x100;\\xfff;\\x1000;\\xffff;\\x10000;")) "\\xff;\\x100;\\xfff;\\x1000;\\xffff;\\x10000;"))
(pass-if "one-digit hex escape" (pass-if "one-digit hex escape"
(eqv? (with-read-options '(r6rs-hex-escapes) (eqv? (with-input-from-string "#\\xA" read)
(lambda ()
(with-input-from-string "#\\xA" read)))
(integer->char #x0A))) (integer->char #x0A)))
(pass-if "two-digit hex escape" (pass-if "two-digit hex escape"
(eqv? (with-read-options '(r6rs-hex-escapes) (eqv? (with-input-from-string "#\\xFF" read)
(lambda ()
(with-input-from-string "#\\xFF" read)))
(integer->char #xFF))) (integer->char #xFF)))
(pass-if "four-digit hex escape" (pass-if "four-digit hex escape"
(eqv? (with-read-options '(r6rs-hex-escapes) (eqv? (with-input-from-string "#\\x00FF" read)
(lambda ()
(with-input-from-string "#\\x00FF" read)))
(integer->char #xFF))) (integer->char #xFF)))
(pass-if "eight-digit hex escape" (pass-if "eight-digit hex escape"
(eqv? (with-read-options '(r6rs-hex-escapes) (eqv? (with-input-from-string "#\\x00006587" read)
(lambda ()
(with-input-from-string "#\\x00006587" read)))
(integer->char #x6587))) (integer->char #x6587)))
(pass-if "write R6RS escapes" (pass-if "write R6RS escapes"
(string=? (string=?
(with-read-options '(r6rs-hex-escapes) (with-read-options '(r6rs-hex-escapes)