rename verbatim and unverbatim to disable-prefix and restore-prefix
svn: r15411
This commit is contained in:
parent
6e01e535d9
commit
4239d22ded
|
@ -19,11 +19,11 @@
|
|||
;; system (when line counts are enabled) -- this is used to tell what part of a
|
||||
;; prefix is already displayed.
|
||||
;;
|
||||
;; Each prefix is either an integer (for a number of spaces) or a
|
||||
;; string. The prefix mechanism can be disabled by using #f for the
|
||||
;; global prefix, and in this case the line prefix can have (cons pfx
|
||||
;; lpfx) so it can be restored -- used by `verbatim' and `unverbatim'
|
||||
;; resp. (This is different from 0 -- no prefix will be accumulated).
|
||||
;; Each prefix is either an integer (for a number of spaces) or a string. The
|
||||
;; prefix mechanism can be disabled by using #f for the global prefix, and in
|
||||
;; this case the line prefix can have (cons pfx lpfx) so it can be restored --
|
||||
;; used by `disable-prefix' and `restore-prefix' resp. (This is different from
|
||||
;; a 0 prefix -- #f means that no prefix will be accumulated).
|
||||
;;
|
||||
(define (output x [p (current-output-port)])
|
||||
;; these are the global prefix and the one that is local to the current line
|
||||
|
@ -68,7 +68,7 @@
|
|||
;; the basic printing unit: strings
|
||||
(define (output-string x)
|
||||
(define pfx (mcar pfxs))
|
||||
(if (not pfx) ; verbatim mode?
|
||||
(if (not pfx) ; prefix disabled?
|
||||
(write-string x p)
|
||||
(let ([len (string-length x)]
|
||||
[nls (regexp-match-positions* #rx"\n" x)])
|
||||
|
@ -120,12 +120,14 @@
|
|||
(let ([c (special-contents x)])
|
||||
(case (special-flag x)
|
||||
[(splice) (for-each loop c)]
|
||||
[(verbatim) ; save the previous pfxs
|
||||
[(flush) ; useful before `disable-prefix'
|
||||
(output-pfx (getcol) (mcar pfxs) (mcdr pfxs))]
|
||||
[(disable-prefix) ; save the previous pfxs
|
||||
(let ([pfx (mcar pfxs)] [lpfx (mcdr pfxs)])
|
||||
(set-mcar! pfxs #f) (set-mcdr! pfxs (cons pfx lpfx))
|
||||
(for-each loop c)
|
||||
(set-mcar! pfxs pfx) (set-mcdr! pfxs lpfx))]
|
||||
[(unverbatim) ; restore the previous pfxs
|
||||
[(restore-prefix) ; restore the previous pfxs
|
||||
(let* ([pfx (mcar pfxs)] [lpfx (mcdr pfxs)]
|
||||
[npfx (pfx+col (if (and (not pfx) (pair? lpfx))
|
||||
(pfx+ (car lpfx) (cdr lpfx))
|
||||
|
@ -133,8 +135,6 @@
|
|||
(set-mcar! pfxs npfx) (set-mcdr! pfxs 0)
|
||||
(for-each loop c)
|
||||
(set-mcar! pfxs pfx) (set-mcdr! pfxs lpfx))]
|
||||
[(flush) ; useful before verbatim
|
||||
(output-pfx (getcol) (mcar pfxs) (mcdr pfxs))]
|
||||
[(prefix)
|
||||
(let* ([pfx (mcar pfxs)] [lpfx (mcdr pfxs)]
|
||||
[npfx (pfx+ (pfx+col (pfx+ pfx lpfx)) (car c))])
|
||||
|
@ -171,15 +171,21 @@
|
|||
|
||||
;; special constructs
|
||||
|
||||
(provide splice verbatim unverbatim flush prefix)
|
||||
(provide splice flush disable-prefix restore-prefix prefix)
|
||||
|
||||
(define-struct special (flag contents))
|
||||
|
||||
(define (splice . contents) (make-special 'splice contents))
|
||||
(define (verbatim . contents) (make-special 'verbatim contents))
|
||||
(define (unverbatim . contents) (make-special 'unverbatim contents))
|
||||
(define flush (make-special 'flush #f))
|
||||
(define (prefix pfx . contents) (make-special 'prefix (cons pfx contents)))
|
||||
(define-syntax define-special
|
||||
(syntax-rules ()
|
||||
[(_ (name x ...)) (define (name x ... . contents)
|
||||
(make-special 'name (list* x ... contents)))]
|
||||
[(_ name) (define name (make-special 'name #f))]))
|
||||
|
||||
(define-special (splice))
|
||||
(define-special flush)
|
||||
(define-special (disable-prefix))
|
||||
(define-special (restore-prefix))
|
||||
(define-special (prefix pfx))
|
||||
|
||||
(define make-spaces ; (efficiently)
|
||||
(let ([t (make-hasheq)] [v (make-vector 80 #f)])
|
||||
|
|
|
@ -718,9 +718,10 @@ number of values but avoid introducing a new indentation context.
|
|||
end
|
||||
}-|
|
||||
|
||||
The @scheme[verbatim] function disables all indentation printouts in
|
||||
its contents, including the indentation before the verbatim value
|
||||
itself. It is useful, for example, to print out CPP directives.
|
||||
The @scheme[disable-prefix] function disables all indentation
|
||||
printouts in its contents, including the indentation before the body
|
||||
of the @scheme[disable-prefix] value itself. It is useful, for
|
||||
example, to print out CPP directives.
|
||||
|
||||
@example|-{#lang scribble/text
|
||||
@(define (((IFFOO . var) . expr1) . expr2)
|
||||
|
@ -728,14 +729,14 @@ itself. It is useful, for example, to print out CPP directives.
|
|||
@list{[@e1,
|
||||
@e2]})
|
||||
@list{var @var;
|
||||
@verbatim{#ifdef FOO}
|
||||
@disable-prefix{#ifdef FOO}
|
||||
@var = @array[expr1 expr2];
|
||||
@verbatim{#else}
|
||||
@disable-prefix{#else}
|
||||
@var = @array[expr2 expr1];
|
||||
@verbatim{#endif}})
|
||||
@disable-prefix{#endif}})
|
||||
|
||||
function blah(something, something_else) {
|
||||
@verbatim{#include "stuff.inc"}
|
||||
@disable-prefix{#include "stuff.inc"}
|
||||
@@@IFFOO{i}{something}{something_else}
|
||||
}
|
||||
---***---
|
||||
|
@ -752,8 +753,8 @@ itself. It is useful, for example, to print out CPP directives.
|
|||
}
|
||||
}-|
|
||||
|
||||
If there are values after a @scheme[verbatim] value on the same line,
|
||||
they will get indented to the goal column (unless the output is
|
||||
If there are values after a @scheme[disable-prefix] value on the same
|
||||
line, they will get indented to the goal column (unless the output is
|
||||
already beyond it).
|
||||
|
||||
@example|-{#lang scribble/text
|
||||
|
@ -762,11 +763,11 @@ already beyond it).
|
|||
@body
|
||||
}})
|
||||
@(define (ifdef cond then else)
|
||||
@list{@verbatim{#}ifdef @cond
|
||||
@list{@disable-prefix{#}ifdef @cond
|
||||
@then
|
||||
@verbatim{#}else
|
||||
@disable-prefix{#}else
|
||||
@else
|
||||
@verbatim{#}endif})
|
||||
@disable-prefix{#}endif})
|
||||
|
||||
@thunk['do_stuff]{
|
||||
init();
|
||||
|
@ -774,7 +775,7 @@ already beyond it).
|
|||
@list{var x = blah();}
|
||||
@thunk['blah]{
|
||||
@ifdef["BLEHOS"
|
||||
@list{@verbatim{#}include <bleh.h>
|
||||
@list{@disable-prefix{#}include <bleh.h>
|
||||
bleh();}
|
||||
@list{error("no bleh");}]
|
||||
}]
|
||||
|
@ -833,17 +834,17 @@ indentation in the contents gets added to the prefix.
|
|||
}
|
||||
}-|
|
||||
|
||||
Trying to combine @scheme[prefix] and @scheme[verbatim] is more useful
|
||||
using an additional value: @scheme[flush] is bound to a value that
|
||||
causes @scheme[output] to print the current indentation and prefix.
|
||||
It makes it possible to get the ``ignored as a prefix'' property of
|
||||
@scheme[verbatim] but only for a nested prefix.
|
||||
When combining @scheme[prefix] and @scheme[disable-prefix] there is an
|
||||
additional value that can be useful: @scheme[flush]. This is a value
|
||||
that causes @scheme[output] to print the current indentation and
|
||||
prefix. This makes it possible to get the ``ignored as a prefix''
|
||||
property of @scheme[disable-prefix] but only for a nested prefix.
|
||||
|
||||
@example|-{#lang scribble/text
|
||||
@(define (comment . text)
|
||||
(list flush
|
||||
@prefix[" *"]{
|
||||
@verbatim{/*} @text */}))
|
||||
@disable-prefix{/*} @text */}))
|
||||
function foo(x) {
|
||||
@comment{blah
|
||||
more blah
|
||||
|
@ -876,12 +877,12 @@ It makes it possible to get the ``ignored as a prefix'' property of
|
|||
|
||||
@(begin
|
||||
;; This is a somewhat contrived example, showing how to use lists
|
||||
;; and verbatim to control the added prefix
|
||||
;; and disable-prefix to control the added prefix
|
||||
(define (item . text)
|
||||
;; notes: the `flush' makes the prefix to that point print so the
|
||||
;; verbatim "* " is printed after it, which overwrites the "| "
|
||||
;; prefix
|
||||
(list flush (prefix "| " (verbatim "* ") text)))
|
||||
;; disable-prefix "* " is printed after it, which overwrites the
|
||||
;; "| " prefix
|
||||
(list flush (prefix "| " (disable-prefix "* ") text)))
|
||||
;; note that a simple item with spaces is much easier:
|
||||
(define (simple . text) @list{* @text}))
|
||||
|
||||
|
|
|
@ -19,20 +19,20 @@
|
|||
(provide IFDEF IFNDEF)
|
||||
(define ((((IF*DEF token choose) . c) . t) . e)
|
||||
(if (null? e)
|
||||
@list{@verbatim{#}@token @c
|
||||
@list{@disable-prefix{#}@token @c
|
||||
@t
|
||||
@verbatim{#}endif /* @c */}
|
||||
@list{@verbatim{#}@token @c
|
||||
@disable-prefix{#}endif /* @c */}
|
||||
@list{@disable-prefix{#}@token @c
|
||||
@t
|
||||
@verbatim{#}else /* @c @(choose '("undefined" . "defined")) */
|
||||
@disable-prefix{#}else /* @c @(choose '("undefined" . "defined")) */
|
||||
@e
|
||||
@verbatim{#}endif /* @c */}))
|
||||
@disable-prefix{#}endif /* @c */}))
|
||||
(define IFDEF (IF*DEF "ifdef" car))
|
||||
(define IFNDEF (IF*DEF "ifndef" cdr))
|
||||
|
||||
(provide DEFINE UNDEF)
|
||||
(define (DEFINE . t) @list{@verbatim{#}define @t})
|
||||
(define (UNDEF . t) @list{@verbatim{#}undef @t})
|
||||
(define (DEFINE . t) @list{@disable-prefix{#}define @t})
|
||||
(define (UNDEF . t) @list{@disable-prefix{#}undef @t})
|
||||
|
||||
(provide scheme-id->c-name)
|
||||
(define (scheme-id->c-name str)
|
||||
|
@ -52,12 +52,12 @@
|
|||
(define (_cdefine name minargs maxargs . body)
|
||||
(define cname @list{foreign_@(scheme-id->c-name name)})
|
||||
(cfunctions (cons (list name cname minargs maxargs) (cfunctions)))
|
||||
@list{@verbatim{#define MYNAME "@name"}
|
||||
@list{@disable-prefix{#define MYNAME "@name"}
|
||||
static Scheme_Object *@|cname|(int argc, Scheme_Object *argv[])
|
||||
{
|
||||
@body
|
||||
}
|
||||
@verbatim{#undef MYNAME}})
|
||||
@disable-prefix{#undef MYNAME}})
|
||||
(provide cdefine)
|
||||
(define-syntax (cdefine stx)
|
||||
(syntax-case stx ()
|
||||
|
|
Loading…
Reference in New Issue
Block a user