mes: Support octal numbers in reader.

* module/mes/read-0.mes (read-octal): New function.
  (read-word): Use it.
* tests/read.test: Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-05-19 21:10:08 +02:00
parent 8dc593ab18
commit 44c8f26bf0
2 changed files with 12 additions and 0 deletions

View file

@ -252,6 +252,15 @@
(read-hex c p 1 0))) (read-hex c p 1 0)))
(read-byte) (peek-byte))) (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 (reader:read-string)
(define (append-char s c) (define (append-char s c)
(append2 s (cons (integer->char c) (list)))) (append2 s (cons (integer->char c) (list))))
@ -293,6 +302,7 @@
(read-word (read-byte) w a))) (read-word (read-byte) w a)))
((eq? c 40) (list->vector (read-list a))) ((eq? c 40) (list->vector (read-list a)))
((eq? c 92) (read-character)) ((eq? c 92) (read-character))
((eq? c 111) (read-octal))
((eq? c 120) (read-hex)) ((eq? c 120) (read-hex))
((eq? c 44) (cond ((eq? (peek-byte) 64) ((eq? c 44) (cond ((eq? (peek-byte) 64)
(read-byte) (read-byte)

View file

@ -17,6 +17,8 @@ cons
(display #f) (newline) (display #f) (newline)
'foo 'foo
(display 'foo) (newline) (display 'foo) (newline)
(display #o77) (newline)
(display #o-6) (newline)
(display #x16) (newline) (display #x16) (newline)
(display #x-16) (newline) (display #x-16) (newline)
(display #\A) (newline) (display #\A) (newline)