diff --git a/collects/scribble/comment-reader.ss b/collects/scribble/comment-reader.ss new file mode 100644 index 00000000..c8a4c94a --- /dev/null +++ b/collects/scribble/comment-reader.ss @@ -0,0 +1,48 @@ + +(module comment-reader mzscheme + (require (lib "kw.ss")) + + (provide (rename *read read) + (rename *read-syntax read-syntax)) + + (define/kw (*read #:optional [inp (current-input-port)]) + (parameterize ([current-readtable (make-comment-readtable)]) + (read/recursive inp))) + + (define/kw (*read-syntax #:optional src [port (current-input-port)]) + (parameterize ([current-readtable (make-comment-readtable)]) + (read-syntax/recursive src port))) + + (define (make-comment-readtable) + (make-readtable (current-readtable) + #\; 'terminating-macro + (case-lambda + [(char port) + (do-comment port (lambda () (read/recursive port #\@)))] + [(char port src line col pos) + (let ([v (do-comment port (lambda () (read-syntax/recursive src port #\@)))]) + (let-values ([(eline ecol epos) (port-next-location port)]) + (datum->syntax-object + #f + v + (list src line col pos (and pos epos (- epos pos))))))]))) + + (define (do-comment port recur) + (let loop () + (when (equal? #\; (peek-char port)) + (read-char port) + (loop))) + `(code:comment + (unsyntax + (t + ,@(let loop () + (let ([c (read-char port)]) + (cond + [(or (eof-object? c) + (char=? c #\newline)) + null] + [(char=? c #\@) + (cons (recur) (loop))] + [else (cons (string c) + (loop))])))))))) + \ No newline at end of file diff --git a/collects/scribble/eval.ss b/collects/scribble/eval.ss index fb362372..c041dd1e 100644 --- a/collects/scribble/eval.ss +++ b/collects/scribble/eval.ss @@ -115,6 +115,8 @@ (syntax-case s (code:comment eval:alts) [(code:line v (code:comment . rest)) (do-eval #'v)] + [(code:comment . rest) + (list (list (void)) "" "")] [(eval:alts p e) (do-eval #'e)] [else @@ -214,13 +216,14 @@ (eval `(define eval-example-string ,eval-example-string))) (define-syntax schemeinput* - (syntax-rules (eval-example-string eval:alts) + (syntax-rules (eval-example-string eval:alts code:comment) [(_ (eval-example-string s)) (make-paragraph (list (hspace 2) (tt "> ") (span-class "schemevalue" (schemefont s))))] + [(_ (code:comment . rest)) (schemeblock (code:comment . rest))] [(_ (eval:alts a b)) (schemeinput* a)] [(_ e) (schemeinput e)])) diff --git a/collects/scribble/manual.ss b/collects/scribble/manual.ss index a1fa2483..13e97d63 100644 --- a/collects/scribble/manual.ss +++ b/collects/scribble/manual.ss @@ -241,10 +241,12 @@ (lambda () (list desc ...)))])) (define-syntax defstruct (syntax-rules () + [(_ name fields #:immutable #:inspector #f desc ...) + (*defstruct (quote-syntax name) 'name 'fields #t #t (lambda () (list desc ...)))] [(_ name fields #:immutable desc ...) - (*defstruct (quote-syntax name) 'name 'fields #t (lambda () (list desc ...)))] + (*defstruct (quote-syntax name) 'name 'fields #t #f (lambda () (list desc ...)))] [(_ name fields desc ...) - (*defstruct (quote-syntax name) 'name 'fields #f (lambda () (list desc ...)))])) + (*defstruct (quote-syntax name) 'name 'fields #f #f (lambda () (list desc ...)))])) (define-syntax (defform*/subs stx) (syntax-case stx () [(_ #:literals (lit ...) [spec spec1 ...] ([non-term-id non-term-form ...] ...) desc ...) @@ -638,7 +640,7 @@ (map symbol->string (car wrappers))))))) (cdr wrappers)))) - (define (*defstruct stx-id name fields immutable? content-thunk) + (define (*defstruct stx-id name fields immutable? transparent? content-thunk) (define spacer (hspace 1)) (make-splice (cons @@ -670,7 +672,8 @@ (list 'set- name '- (car f) '!)) fields)))))) ,(map car fields) - ,@(if immutable? '(#:immutable) null)))))))) + ,@(if immutable? '(#:immutable) null) + ,@(if transparent? '(#:inspector #f) null)))))))) (map (lambda (v) (cond [(pair? v) @@ -904,7 +907,7 @@ (cond [(string? i) (cond - [(regexp-match #rx"^(.*)([()])(.*)$" i) + [(regexp-match #rx"^(.*)([()0-9])(.*)$" i) => (lambda (m) (append (loop (cadr m)) (list (caddr m)) diff --git a/collects/scribble/scheme.ss b/collects/scribble/scheme.ss index 16dd478f..ac59fc5c 100644 --- a/collects/scribble/scheme.ss +++ b/collects/scribble/scheme.ss @@ -183,6 +183,10 @@ (- (cdar m) (caar m)) (literalize-spaces (substring i (cdar m)))) i))) + (define (no-fancy-chars s) + (cond + [(eq? s 'rsquo) "'"] + [else s])) (define (loop init-line! quote-depth) (lambda (c) (cond @@ -194,11 +198,13 @@ (out "; " comment-color) (let ([v (syntax-object->datum (cadr (syntax->list c)))]) (if (paragraph? v) - (map (lambda (v) (if (string? v) - (out v comment-color) - (out v #f))) + (map (lambda (v) + (let ([v (no-fancy-chars v)]) + (if (string? v) + (out v comment-color) + (out v #f)))) (paragraph-content v)) - (out v comment-color)))] + (out (no-fancy-chars v) comment-color)))] [(and (pair? (syntax-e c)) (eq? (syntax-e (car (syntax-e c))) 'code:contract)) (advance c init-line!)