scribble/reader: allow escape character to be non-ASCII

This commit is contained in:
Matthew Flatt 2013-04-19 20:40:37 -06:00
parent b7f17b389a
commit 96c5521196
5 changed files with 36 additions and 2 deletions

View File

@ -15,7 +15,7 @@
[args (map (lambda (x)
(cond [(bytes? x) x]
[(string? x) (string->bytes/utf-8 x)]
[(char? x) (regexp-quote (bytes (char->integer x)))]
[(char? x) (regexp-quote (string->bytes/utf-8 (string x)))]
[(not x) #""]
[else (internal-error 'px)]))
args)])

View File

@ -198,7 +198,7 @@ Useful for implementing languages that are textual by default (see
@defproc[(make-at-readtable
[#:readtable readtable readtable? (current-readtable)]
[#:command-char command-char character? #\@]
[#:command-char command-char char? #\@]
[#:datum-readtable datum-readtable
(or/c readtable? boolean?
(readtable? . -> . readtable?))

View File

@ -0,0 +1,15 @@
#lang racket/base
(require (only-in scribble/reader make-at-readtable))
(provide (rename-out [diamond-read read]
[diamond-read-syntax read-syntax]))
(define diamond-readtable (make-at-readtable #:command-char #\◇))
(define (diamond-read p)
(parameterize ([current-readtable diamond-readtable])
(read p)))
(define (diamond-read-syntax name p)
(parameterize ([current-readtable diamond-readtable])
(read-syntax name p)))

View File

@ -0,0 +1,14 @@
#lang scribble/base
@#reader "diamond.rkt"
◇begin{
This example checks that @ is not an escape character
if we make a reader that uses a different escape character.
◇(define ch "diamond")
It also makes sure that a non-ASCII character like ◇ch
is ok as an escape character.
}

View File

@ -0,0 +1,5 @@
This example checks that @ is not an escape character if we make a
reader that uses a different escape character.
It also makes sure that a non-ASCII character like diamond is ok as an
escape character.