Skip to content

Commit

Permalink
fix: make typeset work with vector literal with no srcloc
Browse files Browse the repository at this point in the history
Fixes #384
  • Loading branch information
sorawee committed Dec 9, 2023
1 parent f7f51eb commit bdffb99
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
27 changes: 23 additions & 4 deletions scribble-lib/scribble/racket.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,30 @@
(unless (and expr? (zero? quote-depth))
(let ([vec (syntax-e c)])
(out "#" p-color)
;; A vector literal looks like "#( x y z )".
;; At this point we want to advance src-col past "#".
;; However, after this we will need to advance src-loc to
;; account for "(" and spaces to reach the first element.
;; The "(" component is handled by unconditionally adding 1 below.
;; For simplicity, we will handle the spaces component right now
;; along with advancing src-col past "#",
;; even though it's technically not the right place to do it.
(if (zero? (vector-length vec))
(set! src-col (+ src-col (- (syntax-span c) 2)))
(set! src-col (+ src-col (- (syntax-column (vector-ref vec 0))
(syntax-column c)
1)))))))
;; assume no srcloc means "#()"
(set! src-col
(+ src-col
(- (or (syntax-span c) 3) 2)))
;; assume no srcloc means "#(x ...)";
;; first element appears at the third character
(set! src-col
(+ src-col
(cond
[(and (syntax-column (vector-ref vec 0))
(syntax-column c))
(- (syntax-column (vector-ref vec 0))
(syntax-column c)
1)]
[else 1])))))))
(when (struct? (syntax-e c))
(unless (and expr? (zero? quote-depth))
(out "#s" p-color)
Expand Down
16 changes: 16 additions & 0 deletions scribble-test/tests/scribble/docs/text.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ Here's some Racket code:
(x x)
]

We should be able to use @racket[racketblock] without having source location.

@(require (for-syntax racket/base))

@(define-syntax (test stx)
(with-syntax ([(xs ...) '(1 2 3 4)])
#'@racketblock[#(xs ...)
(xs ...)
'(xs ...)]))

@(test)

Spaces inside lists should be preserved.

@racketblock[( a b c)]

@subsection{Another Subsection}

@defmodule[racket/base]
Expand Down
10 changes: 10 additions & 0 deletions scribble-test/tests/scribble/docs/text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ Here’s some Racket code:
               (x x)))
(x x)

We should be able to use racketblock without having source location.

#(1 2 3 4)
(1 2 3 4)
'(1 2 3 4)

Spaces inside lists should be preserved.

( a   b   c)

1.2. Another Subsection

 (require racket/base) package: base
Expand Down

0 comments on commit bdffb99

Please sign in to comment.