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 70ce6e1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
23 changes: 19 additions & 4 deletions scribble-lib/scribble/racket.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,26 @@
(unless (and expr? (zero? quote-depth))
(let ([vec (syntax-e c)])
(out "#" p-color)
;; at this point we want to advance src-col past "#"
;; but we will unconditionally add 1 to src-col below for "(",
;; so we also need to account for the "first element"
;; position as well.
(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
12 changes: 12 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,18 @@ 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)

@subsection{Another Subsection}

@defmodule[racket/base]
Expand Down
6 changes: 6 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,12 @@ 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)

1.2. Another Subsection

 (require racket/base) package: base
Expand Down

0 comments on commit 70ce6e1

Please sign in to comment.