Skip to content

Commit

Permalink
typeset: support hashalw
Browse files Browse the repository at this point in the history
Fixes #395
  • Loading branch information
sorawee committed Dec 24, 2023
1 parent 338a53e commit 0fd64c6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
44 changes: 21 additions & 23 deletions scribble-lib/scribble/racket.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -810,17 +810,18 @@
(out ")" paren-color)))]
[(hash? (syntax-e c))
(advance c init-line! srcless-step)
(let ([equal-table? (hash-equal? (syntax-e c))]
[eqv-table? (hash-eqv? (syntax-e c))]
[quote-depth (to-quoted c expr? quote-depth out color? inc-src-col)])
(define hash-type
(cond
[(hash-equal? (syntax-e c)) 'hash]
[(hash-eqv? (syntax-e c)) 'hasheqv]
[(hash-eq? (syntax-e c)) 'hasheq]
[(hash-equal-always? (syntax-e c)) 'hashalw]
[else (error 'typeset "unexpected hash table type: ~s" (syntax-e c))]))
(let ([quote-depth (to-quoted c expr? quote-depth out color? inc-src-col)])
(unless (and expr? (zero? quote-depth))
(out (if equal-table?
"#hash"
(if eqv-table?
"#hasheqv"
"#hasheq"))
value-color))
(let ([delta (+ 5 (if equal-table? 0 (if eqv-table? 3 2))
(out (iformat "#~a" hash-type) value-color))
(let ([delta (+ 1
(string-length (symbol->string hash-type))
(if (and expr? (zero? quote-depth)) 1 0))]
[orig-col src-col])
(set! src-col (+ src-col delta))
Expand Down Expand Up @@ -880,18 +881,13 @@
(reverse l2)))])
(datum->syntax
#f
(cons (let ([s (if equal-table?
'hash
(if eqv-table?
'hasheqv
'hasheq))])
(datum->syntax #f
s
(vector (syntax-source c)
(syntax-line c)
(+ (syntax-column c) 1)
(+ (syntax-position c) 1)
(string-length (symbol->string s)))))
(cons (datum->syntax #f
hash-type
(vector (syntax-source c)
(syntax-line c)
(+ (syntax-column c) 1)
(+ (syntax-position c) 1)
(string-length (symbol->string hash-type))))
l)
c))
;; quoted:
Expand Down Expand Up @@ -1076,7 +1072,9 @@
[(hash? v) `(,(cond
[(hash-eq? v) 'make-immutable-hasheq]
[(hash-eqv? v) 'make-immutable-hasheqv]
[else 'make-immutable-hash])
[(hash-equal? v) 'make-immutable-hash]
[(hash-equal-always? v) 'make-immutable-hashalw]
[else (error 'define-code "unexpected hash table type: ~s" v)])
(list
,@(hash-map
v
Expand Down
4 changes: 4 additions & 0 deletions scribble-test/tests/scribble/docs/text.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Spaces inside lists should be preserved.

@racketblock[( a b c)]

Hash tables should work.

@racketblock[#hashalw([1 . 2])]

@subsection{Another Subsection}

@defmodule[racket/base]
Expand Down
4 changes: 4 additions & 0 deletions scribble-test/tests/scribble/docs/text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Spaces inside lists should be preserved.

( a   b   c)

Hash tables should work.

#hashalw((1 . 2))

1.2. Another Subsection

 (require racket/base) package: base
Expand Down

0 comments on commit 0fd64c6

Please sign in to comment.