From ddefaa4167f60ed5888865d53851bf014f6e171a Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Sat, 19 Nov 2016 04:07:46 +0000 Subject: [PATCH] Recognize | and x char escapes --- CHANGELOG.md | 3 +++ scheme/read.sld | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 476d31ea..2cafabc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Next Release - Date TBD TODO: SRFI 113 +Features: + +- Recognize escaped vertical line and hex scalar value characters when reading a string. # 0.3.1 - November 20, 2016 diff --git a/scheme/read.sld b/scheme/read.sld index 10a24311..a906dbec 100644 --- a/scheme/read.sld +++ b/scheme/read.sld @@ -471,6 +471,25 @@ (loop (cons (read-char fp) buf)))))) (loop '())) +(define (read-hex-scalar-value fp ptbl) + (define (done buf) + (cond + ((= 0 (length buf)) + (parse-error "missing character" + (in-port:get-lnum ptbl) + (in-port:get-cnum ptbl))) + (else + (integer->char (string->number (list->string buf) 16))))) + (define (loop buf) + (let ((c (read-char fp))) + (cond + ((or (eof-object? c) + (eq? #\; c)) + (done (reverse buf))) + (else + (loop (cons c buf)))))) + (loop '())) + (define (read-str fp buf ptbl) (let ((c (read-char fp))) (cond @@ -505,6 +524,8 @@ ((equal? #\n c) (cons #\newline buf)) ((equal? #\r c) (cons #\return buf)) ((equal? #\t c) (cons #\tab buf)) + ((equal? #\x c) + (cons (read-hex-scalar-value fp ptbl) buf)) (else (parse-error (string-append "invalid escape character ["