* reader now recognizes all standard character names:
#\nul #\alaram #\backspace ... #\delete
This commit is contained in:
parent
e75bd7e33c
commit
da16a5ef7a
|
@ -190,15 +190,48 @@
|
|||
(cond
|
||||
[(eof-object? c)
|
||||
(error 'tokenize "invalid #\\ near end of file")]
|
||||
[($char= #\s c)
|
||||
(tokenize-char-seq p "space" '(datum . #\space))]
|
||||
[($char= #\n c)
|
||||
(tokenize-char-seq p "newline" '(datum . #\newline))]
|
||||
[($char= #\t c)
|
||||
[(eqv? #\n c)
|
||||
(let ([c (read-char p)])
|
||||
(cond
|
||||
[(eof-object? c)
|
||||
(error 'tokenize "invalid eof inside character syntax")]
|
||||
[(eqv? #\u c)
|
||||
(tokenize-char-seq p "ul"
|
||||
(cons 'datum (integer->char 0)))]
|
||||
[(eqv? #\e c)
|
||||
(tokenize-char-seq p "ewline"
|
||||
(cons 'datum (integer->char #xA)))]
|
||||
[else
|
||||
(error 'tokenize "invalid syntax"
|
||||
(string #\# #\\ #\n c))]))]
|
||||
[(eqv? #\a c)
|
||||
(tokenize-char-seq p "alarm"
|
||||
(cons 'datum (integer->char 7)))]
|
||||
[(eqv? #\b c)
|
||||
(tokenize-char-seq p "backspace"
|
||||
(cons 'datum (integer->char 8)))]
|
||||
[(eqv? #\t c)
|
||||
(tokenize-char-seq p "tab" '(datum . #\tab))]
|
||||
[($char= #\r c)
|
||||
[(eqv? #\l c)
|
||||
(tokenize-char-seq p "linefeed"
|
||||
(cons 'datum (integer->char #xA)))]
|
||||
[(eqv? #\v c)
|
||||
(tokenize-char-seq p "vtab"
|
||||
(cons 'datum (integer->char #xB)))]
|
||||
[(eqv? #\p c)
|
||||
(tokenize-char-seq p "page"
|
||||
(cons 'datum (integer->char #xC)))]
|
||||
[(eqv? #\r c)
|
||||
(tokenize-char-seq p "return" '(datum . #\return))]
|
||||
[($char= #\x c)
|
||||
[(eqv? #\e c)
|
||||
(tokenize-char-seq p "esc"
|
||||
(cons 'datum (integer->char #x1B)))]
|
||||
[(eqv? #\s c)
|
||||
(tokenize-char-seq p "space" '(datum . #\space))]
|
||||
[(eqv? #\d c)
|
||||
(tokenize-char-seq p "delete"
|
||||
(cons 'datum (integer->char #x7F)))]
|
||||
[(eqv? #\x c)
|
||||
(let ([n (peek-char p)])
|
||||
(cond
|
||||
[(or (eof-object? n) (delimiter? n))
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
(printf "[exact-integer-sqrt] Happy Happy Joy Joy\n"))
|
||||
|
||||
(test-reader)
|
||||
(test-char-syntax)
|
||||
(test-bytevectors)
|
||||
(test-strings)
|
||||
(test-exact-integer-sqrt)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(library (tests reader)
|
||||
(export test-reader)
|
||||
(export test-reader test-char-syntax)
|
||||
(import (ikarus) (tests framework))
|
||||
|
||||
(define t
|
||||
|
@ -71,7 +71,33 @@
|
|||
"#O+23761236721631263126371263712"
|
||||
"#O+0"
|
||||
"#O-0"
|
||||
"#O0"
|
||||
"#O0")
|
||||
|
||||
(define-tests test-char-syntax
|
||||
[(lambda (x) (= (char->integer x) #x0))
|
||||
(read (open-input-string "#\\nul"))]
|
||||
[(lambda (x) (= (char->integer x) #x7))
|
||||
(read (open-input-string "#\\alarm"))]
|
||||
[(lambda (x) (= (char->integer x) #x8))
|
||||
(read (open-input-string "#\\backspace"))]
|
||||
[(lambda (x) (= (char->integer x) #x9))
|
||||
(read (open-input-string "#\\tab"))]
|
||||
[(lambda (x) (= (char->integer x) #xA))
|
||||
(read (open-input-string "#\\linefeed"))]
|
||||
[(lambda (x) (= (char->integer x) #xA))
|
||||
(read (open-input-string "#\\newline"))]
|
||||
[(lambda (x) (= (char->integer x) #xB))
|
||||
(read (open-input-string "#\\vtab"))]
|
||||
[(lambda (x) (= (char->integer x) #xC))
|
||||
(read (open-input-string "#\\page"))]
|
||||
[(lambda (x) (= (char->integer x) #xD))
|
||||
(read (open-input-string "#\\return"))]
|
||||
[(lambda (x) (= (char->integer x) #x1B))
|
||||
(read (open-input-string "#\\esc"))]
|
||||
[(lambda (x) (= (char->integer x) #x20))
|
||||
(read (open-input-string "#\\space"))]
|
||||
[(lambda (x) (= (char->integer x) #x7F))
|
||||
(read (open-input-string "#\\delete"))])
|
||||
|
||||
))
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue