reader: fix bugs in cdot readering

This commit is contained in:
Matthew Flatt 2018-06-11 16:24:34 -06:00
parent f11b4319b5
commit 0d870fb11c
5 changed files with 1319 additions and 1278 deletions

View File

@ -956,16 +956,17 @@ When the @racket[read-cdot] @tech{parameter} is set to @racket[#t],
then a variety of changes occur in the reader.
First, symbols can no longer include the character @litchar{.}, unless
the entire symbol is quoted with @litchar{|}.
the @litchar{.} is quoted with @litchar{|} or @litchar{\}.
Second, numbers can no longer include the character @litchar{.},
unless the number is prefixed with @litchar{#e} or @litchar{#i}, or an
unless the number is prefixed with @litchar{#e}, @litchar{#i},
@litchar{#b}, @litchar{#o}, @litchar{#d}, @litchar{#x}, or an
equivalent prefix as discussed in @secref["parse-number"]. If these
numbers are followed by a @litchar{.} intended to be read as a C-style
infix dot, then there must be separating whitespace.
infix dot, then a delimiter must precede the @litchar{.}.
Finally, after reading any datum @racket[_x], the reader will seek
through whitespace and look for zero or more sequences of a
through whitespace and comments and look for zero or more sequences of a
@litchar{.} followed by another datum @racket[_y]. It will then group
@racket[_x] and @racket[_y] together in a @racket[#%dot] form so that
@racket[_x.y] reads equal to @racket[(#%dot _x _y)].

View File

@ -1356,7 +1356,19 @@
(test '(#%dot (f a) (m b c)) readstr "(f a).(m b c)")
(test '(#%dot (#%dot (f a) (m b c)) (n d e)) readstr "(f a).(m b c).(n d e)")
(test '(#%dot (#%dot (#%dot (#%dot (#%dot (f a) (m b c)) x) (n d e)) y) z)
readstr "(f a).(m b c).x.(n d e).y.z"))
readstr "(f a).(m b c).x.(n d e).y.z")
(test '(#%dot 1.2 a) readstr "#i1.2 .a")
(test '(#%dot 1.0 a) readstr "#b1.0 .a")
(test '(#%dot 1.25 a) readstr "#o1.2 .a")
(test '(#%dot 1.2 a) readstr "#d1.2 .a")
(test '(#%dot 1.125 a) readstr "#x1.2 .a")
(test '(#%dot (#%dot 1 2) a) readstr "1.2 .a")
(test 'a.b readstr "|a.b|")
(test 'a.b readstr "a|.|b")
(test 'a.b readstr "a|.b|")
(test 'a.b readstr "a\\.b")
(err/rt-test (readstr "x.") exn:fail:read:eof?)
(err/rt-test (readstr "1.") exn:fail:read:eof?))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; srcloc->string

View File

@ -153,8 +153,11 @@
[(char=? ec #\.)
(define-values (dot-line dot-col dot-pos) (port-next-location in))
(consume-char in c)
(define cdot (wrap '#%dot in (reading-at config dot-line dot-col dot-pos) #\.))
(define pos-config (reading-at config dot-line dot-col dot-pos))
(define cdot (wrap '#%dot in pos-config #\.))
(define post-v (read-undotted #f in config))
(when (eof-object? post-v)
(reader-error in pos-config #:due-to eof "expected a datum after cdot, found end-of-file"))
(loop (wrap (list cdot v post-v) in (reading-at config line col pos) #\.))]
[else v]))])]))

View File

@ -12,7 +12,7 @@
(provide read-symbol-or-number)
(define (read-symbol-or-number init-c in config
(define (read-symbol-or-number init-c in orig-config
;; `mode` can be 'symbol-or-number,
;; 'symbol, 'symbol/indirect, 'keyword,
;; or a number prefix string like "#e";
@ -21,6 +21,9 @@
;; symbol handler
#:mode [mode 'symbol-or-number]
#:extra-prefix [extra-prefix #f])
(define config (if (string? mode)
(override-parameter read-cdot orig-config #f)
orig-config))
(define rt (read-config-readtable config))
(cond
[(and rt

File diff suppressed because it is too large Load Diff