-
-
Save Bogdanp/2eac8b4f7f1726af5b1bcce0a90e0fe5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(provide f | |
h) | |
(define (f x) | |
"Adds 1 to @racket[x]." | |
(add1 x)) | |
(define g 1) | |
(define (h x y) | |
"Adds @racket[x] and @racket[y] and applies @racket[f] to the result." | |
(f (+ x y))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang scribble/manual | |
@(require (for-label racket/base | |
racket/contract | |
"a.rkt") | |
"docstring.rkt") | |
@defproc[(f [x integer?]) integer?]{ | |
@(docstring "a.rkt" f) | |
} | |
@defproc[(h [x integer?] | |
[y integer?]) integer?]{ | |
@(docstring "a.rkt" h) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require (for-syntax racket/base | |
racket/list | |
(only-in scribble/reader read-syntax-inside) | |
syntax/modread | |
syntax/parse)) | |
(provide | |
docstring) | |
(define-syntax (docstring stx) | |
(define-syntax-class definition | |
#:datum-literals (define) | |
(pattern (define (name:id . args) doc:string e ...+))) | |
(define (lookup-docstring p id) | |
(parameterize ([current-namespace (make-base-namespace)]) | |
(with-module-reading-parameterization | |
(lambda _ | |
(define path | |
(resolved-module-path-name | |
((current-module-name-resolver) p #f #f #f))) | |
(define docstrings | |
(apply hash | |
(flatten | |
(syntax->datum | |
(syntax-parse (with-input-from-file path read-syntax) | |
#:datum-literals (#%module-begin module) | |
[(module name lang | |
(#%module-begin | |
(~or def:definition e) ...)) | |
#'((def.name def.doc) ...)]))))) | |
(hash-ref docstrings id))))) | |
(syntax-parse stx | |
[(_ mod:str name:id) | |
(with-syntax ([(part ...) | |
(read-syntax-inside | |
'docstring | |
(open-input-string | |
(lookup-docstring (syntax->datum #'mod) | |
(syntax->datum #'name))))]) | |
(datum->syntax stx (syntax->datum #'(list part ...))))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment