From 44c8f26bf03c577a908155ee91d04ef31986cf58 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 19 May 2017 21:10:08 +0200 Subject: [PATCH] mes: Support octal numbers in reader. * module/mes/read-0.mes (read-octal): New function. (read-word): Use it. * tests/read.test: Test it. --- module/mes/read-0.mes | 10 ++++++++++ tests/read.test | 2 ++ 2 files changed, 12 insertions(+) diff --git a/module/mes/read-0.mes b/module/mes/read-0.mes index cbaeb022..dcadf770 100644 --- a/module/mes/read-0.mes +++ b/module/mes/read-0.mes @@ -252,6 +252,15 @@ (read-hex c p 1 0))) (read-byte) (peek-byte))) + (define (read-octal) + (define (read-octal c p s n) + (if (not (or (and (> p 47) (< p 56)))) (* s (+ (ash n 3) (- c 48))) + (read-octal (read-byte) (peek-byte) s (+ (ash n 3) (- c 48))))) + ((lambda (c p) + (if (eq? c 45) (read-octal (read-byte) (peek-byte) -1 0) + (read-octal c p 1 0))) + (read-byte) (peek-byte))) + (define (reader:read-string) (define (append-char s c) (append2 s (cons (integer->char c) (list)))) @@ -293,6 +302,7 @@ (read-word (read-byte) w a))) ((eq? c 40) (list->vector (read-list a))) ((eq? c 92) (read-character)) + ((eq? c 111) (read-octal)) ((eq? c 120) (read-hex)) ((eq? c 44) (cond ((eq? (peek-byte) 64) (read-byte) diff --git a/tests/read.test b/tests/read.test index c23a530e..63bf765d 100755 --- a/tests/read.test +++ b/tests/read.test @@ -17,6 +17,8 @@ cons (display #f) (newline) 'foo (display 'foo) (newline) +(display #o77) (newline) +(display #o-6) (newline) (display #x16) (newline) (display #x-16) (newline) (display #\A) (newline)