Fixes bug 163589: ikarus does not support the #!r6rs comment.

* Added #!r6rs and #!ikarus tokens to the reader
* #!r6rs disables the #:foo and #{foo bar} gensym syntaxes and it
  also disables the #n= and #n# graphs marks syntax.
* #!ikarus enables both options.
* every opened port starts in the ikarus-mode by default.
This commit is contained in:
Abdulaziz Ghuloum 2007-11-18 19:53:32 -05:00
parent 543d59313b
commit 7282bd1c48
2 changed files with 55 additions and 43 deletions

Binary file not shown.

View File

@ -354,25 +354,30 @@
(let ([e (read-char p)]) (let ([e (read-char p)])
(when (eof-object? e) (when (eof-object? e)
(error 'tokenize "invalid eof near #!")) (error 'tokenize "invalid eof near #!"))
(unless ($char= #\e e) (case e
[(#\e)
(read-char* p '(#\e) "of" "eof sequence" #f #f)
(cons 'datum (eof-object))]
[(#\r)
(read-char* p '(#\r) "6rs" "#!r6rs comment" #f #f)
(set-port-mode! p 'r6rs-mode)
(tokenize p)]
[(#\i)
(read-char* p '(#\i) "karus" "#!ikarus comment" #f #f)
(set-port-mode! p 'ikarus-mode)
(tokenize p)]
[else
(error 'tokenize (error 'tokenize
(format "invalid syntax near #!~a" e))) (format "invalid syntax near #!~a" e))]))]
(let ([o (read-char p)])
(when (eof-object? o)
(error 'tokenize "invalid eof near #!e"))
(unless ($char= #\o o)
(error 'tokenize
(format "invalid syntax near #!e~a" o)))
(let ([f (read-char p)])
(when (eof-object? f)
(error 'tokenize "invalid syntax near #!eo"))
(unless ($char= #\f f)
(error 'tokenize
(format "invalid syntax near #!eo~a" f)))
(cons 'datum (eof-object)))))]
[(digit? c) [(digit? c)
(when (eq? (port-mode p) 'r6rs-mode)
(error 'tokenize "graph syntax is invalid in #!r6rs mode"
(format "#~a" c)))
(tokenize-hashnum p (char->num c))] (tokenize-hashnum p (char->num c))]
[($char= #\: c) [($char= #\: c)
(when (eq? (port-mode p) 'r6rs-mode)
(error 'tokenize "gensym syntax is invalid in #!r6rs mode"
(format "#~a" c)))
(let* ([c (skip-whitespace p "gensym")] (let* ([c (skip-whitespace p "gensym")]
[id0 [id0
(cond (cond
@ -387,6 +392,9 @@
"invalid char inside gensym" c)])]) "invalid char inside gensym" c)])])
(cons 'datum (gensym id0)))] (cons 'datum (gensym id0)))]
[($char= #\{ c) [($char= #\{ c)
(when (eq? (port-mode p) 'r6rs-mode)
(error 'tokenize "gensym syntax is invalid in #!r6rs mode"
(format "#~a" c)))
(let* ([c (skip-whitespace p "gensym")] (let* ([c (skip-whitespace p "gensym")]
[id0 [id0
(cond (cond
@ -463,6 +471,9 @@
[(memq c '(#\d #\D)) [(memq c '(#\d #\D))
(cons 'datum (tokenize-radix-mark p (list c #\#) 10))] (cons 'datum (tokenize-radix-mark p (list c #\#) 10))]
[($char= #\@ c) [($char= #\@ c)
(when (eq? (port-mode p) 'r6rs-mode)
(error 'tokenize "fasl syntax is invalid in #!r6rs mode"
(format "#~a" c)))
(error 'read "FIXME: fasl read disabled") (error 'read "FIXME: fasl read disabled")
'(cons 'datum ($fasl-read p))] '(cons 'datum ($fasl-read p))]
[else [else
@ -692,32 +703,33 @@
[(#\1) 1] [(#\1) 1]
[else #f])] [else #f])]
[else (error 'radix-digit "invalid radix" radix)])) [else (error 'radix-digit "invalid radix" radix)]))
(define (tokenize-integer/nan/inf-no-digits p ls) (define (read-char* p ls str who ci? delimited?)
(define (read-char* p ls str who)
(let f ([i 0] [ls ls]) (let f ([i 0] [ls ls])
(let ([c (read-char p)])
(cond (cond
[(fx= i (string-length str)) [(fx= i (string-length str))
(cond (when delimited?
[(eof-object? c) (void)] (let ([c (peek-char p)])
[(delimiter? c) (unread-char c p)] (when (and (not (eof-object? c)) (not (delimiter? c)))
[else
(unread-char c p)
(error 'tokenize (error 'tokenize
(format "invalid ~a: ~s" who (format "invalid ~a: ~s" who
(list->string (reverse (cons c ls)))))])] (list->string (reverse (cons c ls))))))))]
[else
(let ([c (read-char p)])
(cond
[else [else
(cond (cond
[(eof-object? c) [(eof-object? c)
(error 'tokenize (error 'tokenize
(format "invalid eof inside ~a" who))] (format "invalid eof inside ~a" who))]
[(char=? (char-downcase c) (string-ref str i)) [(or (and (not ci?) (char=? c (string-ref str i)))
(and ci? (char=? (char-downcase c) (string-ref str i))))
(f (add1 i) (cons c ls))] (f (add1 i) (cons c ls))]
[else [else
(unread-char c p) (unread-char c p)
(error 'tokenize (error 'tokenize
(format "invalid ~a: ~s" who (format "invalid ~a: ~s" who
(list->string (reverse (cons c ls)))))])])))) (list->string (reverse (cons c ls)))))])]))])))
(define (tokenize-integer/nan/inf-no-digits p ls)
(let ([c (read-char p)]) (let ([c (read-char p)])
(cond (cond
[(eof-object? c) (num-error "invalid eof" ls)] [(eof-object? c) (num-error "invalid eof" ls)]
@ -727,10 +739,10 @@
[(char=? c #\.) [(char=? c #\.)
(tokenize-decimal-no-digits p (cons c ls) #f)] (tokenize-decimal-no-digits p (cons c ls) #f)]
[(memv c '(#\i #\I)) [(memv c '(#\i #\I))
(read-char* p (cons #\i ls) "nf.0" "number sequence") (read-char* p (cons #\i ls) "nf.0" "number sequence" #t #t)
+inf.0] +inf.0]
[(memv c '(#\n #\N)) [(memv c '(#\n #\N))
(read-char* p (cons #\i ls) "an.0" "number sequence") (read-char* p (cons #\i ls) "an.0" "number sequence" #t #t)
+nan.0] +nan.0]
[else (num-error "invalid sequence" (cons c ls))]))) [else (num-error "invalid sequence" (cons c ls))])))
(define (tokenize-integer-no-digits p ls exact? radix?) (define (tokenize-integer-no-digits p ls exact? radix?)