From bb9ffefd74d36fcd0beeeade0676be1462b35907 Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Wed, 8 May 2013 10:52:04 -0600 Subject: [PATCH] Adding customization of command-char to web-server/template This entails adding it to include/text and read-syntax-inside as well. original commit: 73232afd9934f5b7918d29414d835f33f21aa57c --- collects/scribble/text/syntax-utils.rkt | 46 +++++++++++-------- .../scribble/reader-internals.scrbl | 4 +- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/collects/scribble/text/syntax-utils.rkt b/collects/scribble/text/syntax-utils.rkt index ebcd501c..e39e7f4b 100644 --- a/collects/scribble/text/syntax-utils.rkt +++ b/collects/scribble/text/syntax-utils.rkt @@ -172,22 +172,32 @@ #'(process-begin/text begin/collect begin expr ...)])) ;; include for templates -(require (for-syntax scheme/base (prefix-in scribble: "../reader.rkt")) +(require (for-syntax scheme/base (prefix-in scribble: "../reader.rkt") syntax/parse) scheme/include) -(define-syntax-rule (include/text path-spec) - (begin/text - (include-at/relative-to/reader path-spec path-spec path-spec - (let ([xs #f]) - (λ (src inp) - (unless xs - (set! xs (scribble:read-syntax-inside src inp)) - (when (syntax? xs) (set! xs (or (syntax->list xs) (list xs))))) - (if (null? xs) - eof - (let ([x (car xs)]) - (set! xs (cdr xs)) - (if (and (null? xs) - (let ([p (syntax-property x 'scribble)]) - (and (pair? p) (eq? (car p) 'newline)))) - eof ; throw away the last newline from the included file - x)))))))) +(define-syntax (include/text stx) + (syntax-case stx () + [(_ path-spec) + (syntax/loc stx + (include/text #:command-char #f path-spec))] + [(_ #:command-char command-char path-spec) + (syntax/loc stx + (begin/text + (include-at/relative-to/reader + path-spec path-spec path-spec + (let ([xs #f] + [command-char-v command-char]) + (λ (src inp) + (unless xs + (set! xs (if command-char-v + (scribble:read-syntax-inside #:command-char command-char-v src inp) + (scribble:read-syntax-inside src inp))) + (when (syntax? xs) (set! xs (or (syntax->list xs) (list xs))))) + (if (null? xs) + eof + (let ([x (car xs)]) + (set! xs (cdr xs)) + (if (and (null? xs) + (let ([p (syntax-property x 'scribble)]) + (and (pair? p) (eq? (car p) 'newline)))) + eof ; throw away the last newline from the included file + x))))))))])) diff --git a/collects/scribblings/scribble/reader-internals.scrbl b/collects/scribblings/scribble/reader-internals.scrbl index 5a94f199..c7aa6d0b 100644 --- a/collects/scribblings/scribble/reader-internals.scrbl +++ b/collects/scribblings/scribble/reader-internals.scrbl @@ -188,10 +188,12 @@ for reading. @defproc[(read-inside [in input-port? (current-input-port)]) any]{} @defproc[(read-syntax-inside [source-name any/c (object-name in)] - [in input-port? (current-input-port)]) + [in input-port? (current-input-port)] + [#:command-char command-char char? #\@]) (or/c syntax? eof-object?)]{ These @racketid[-inside] variants parse as if starting inside a @litchar["@{"]...@litchar["}"], and they return a (syntactic) list. +The @racket[command-char] is used to customize the readtable. Useful for implementing languages that are textual by default (see @filepath{docreader.rkt} for example). }