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