Skip to content

Commit

Permalink
Change approach to handling older Racket w/o new index structs
Browse files Browse the repository at this point in the history
  • Loading branch information
greghendershott committed Oct 3, 2024
1 parent 8b9db7a commit d09bfa2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 40 deletions.
48 changes: 11 additions & 37 deletions racket/scribble.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#lang racket/base

(require racket/contract
(require (for-syntax racket/base)
racket/contract
racket/format
racket/match
racket/promise
Expand All @@ -13,28 +14,7 @@
tag?
content->string)
scribble/blueboxes
(only-in scribble/manual-struct
;; i.e. Not the newer exported-index-desc*
;; accessors, which we need to dynamic-require below
;; when running on Racket <= 8.14.0, else provide
;; stubs. We can't import them here, too. Note that
;; except-in errors for items that aren't actually
;; exported, so we can't use that here.
constructor-index-desc?
exported-index-desc?
exported-index-desc-name
module-path-index-desc?
language-index-desc?
reader-index-desc?
form-index-desc?
procedure-index-desc?
thing-index-desc?
struct-index-desc?
class-index-desc?
interface-index-desc?
mixin-index-desc?
method-index-desc?
exported-index-desc-from-libs)
scribble/manual-struct
scribble/xref
scribble/tag
setup/xref
Expand All @@ -43,6 +23,14 @@
"elisp.rkt"
"util.rkt")

;; Fallbacks when new index structs aren't available, before c. Racket
;; 8.14.0.6.
(define-fallbacks scribble/manual-struct
[(exported-index-desc*? _) #f]
[(exported-index-desc*-extras _) #hasheq()]
[(index-desc? _) #f]
[(index-desc-extras _) #hasheq()])

(provide binding->path+anchor
identifier->bluebox
bluebox-command
Expand Down Expand Up @@ -132,20 +120,6 @@
;; making _another_ 30K+ list, by returning a thunk for elisp-write
;; to call, to do "streaming" writes.

;; When available use new index structs circa Racket 8.14.0.6.
(define-polyfill (exported-index-desc*? _)
#:module scribble/manual-struct
#f)
(define-polyfill (exported-index-desc*-extras _)
#:module scribble/manual-struct
#hasheq())
(define-polyfill (index-desc? _)
#:module scribble/manual-struct
#f)
(define-polyfill (index-desc-extras _)
#:module scribble/manual-struct
#hasheq())

(define (hide-desc? desc)
;; Don't show doc for constructors; class doc suffices.
(or (constructor-index-desc? desc)
Expand Down
28 changes: 25 additions & 3 deletions racket/util.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#lang racket/base

(require (for-syntax racket/base)
syntax/stx
syntax/parse/define
racket/format)

Expand All @@ -21,7 +20,8 @@
log-racket-mode-fatal
time-apply/log
with-time/log
define-polyfill)
define-polyfill
define-fallbacks)

(define (string->namespace-syntax str)
(namespace-syntax-introduce
Expand Down Expand Up @@ -57,7 +57,7 @@
(define-simple-macro (with-time/log what e ...+)
(time-apply/log what (λ () e ...) '()))

;; dynamic-require with backup implementation
;;; dynamic-require with backup implementation

(define-simple-macro (define-polyfill (id:id arg:expr ...)
#:module mod:id
Expand All @@ -66,3 +66,25 @@
(with-handlers ([exn:fail? (λ (_exn)
(λ (arg ...) body ...))])
(dynamic-require 'mod 'id))))

;;; similar, but defining fallbacks only for items not imported by a
;;; normal require

;; advantage: Things like go-to definition work as expected in the
;; normal, non-fallback case. Whereas with define-polyfill, the
;; identifier _always_ results from the dynamic-require, and go-to def
;; always goes there.

(define-syntax-parser define-fallback
[(_ mod:id (id:id arg:expr ...) body:expr ...+)
(if (with-handlers ([exn:fail? (λ _ #f)])
(dynamic-require (syntax-e #'mod) (syntax-e #'id)))
#'(void)
#'(define (id arg ...)
body ...))])

(define-syntax-parser define-fallbacks
[(_ mod:id [(id:id arg:expr ...) body:expr ...+] ...+)
#'(begin
(define-fallback mod (id arg ...) body ...) ...)])

0 comments on commit d09bfa2

Please sign in to comment.