skribilo-mdoc

Unnamed repository; edit this file 'description' to name the repository.

git clone https://git.8pit.net/skribilo-mdoc.git

 1(define-module (mdoc utils output)
 2  #:use-module (skribilo output)
 3  #:use-module (skribilo ast)
 4
 5  #:export (in-parsed-macro?
 6            with-parsed-macro
 7
 8            output-macro
 9            output-newline
10            output-section
11            output-preamble))
12
13(define in-parsed-macro?
14  (make-parameter #f))
15
16(define-syntax with-parsed-macro
17  (syntax-rules ()
18    ((with-parsed-macro (E M) BODY ...)
19     (begin
20       (%output-macro E M "")
21       (parameterize ((in-parsed-macro? #t))
22         BODY ...)
23       (output-newline E)))))
24
25;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
27(define (%output-macro e name . value)
28  (define (->string obj)
29    (if (string? obj)
30      obj
31      (ast->string obj)))
32
33  (unless (in-parsed-macro?)
34    (output-newline e)
35    (output "." e))
36
37  (output
38    (if (null? value)
39      (symbol->string name)
40      (format #f "~a ~a"
41              (symbol->string name)
42              (string-join (map ->string value) " ")))
43    e))
44
45(define (output-macro e name . value)
46  (%output-macro e name value)
47  (unless (in-parsed-macro?)
48    (output-newline e)))
49
50(define (output-newline e)
51  (output "\n" e))
52
53(define (output-section e title)
54  (output-macro e 'Sh (string-upcase title)))
55
56(define (output-preamble e name date section system)
57  (output-macro e 'Dd date)
58  (output-macro e 'Dt (string-upcase name) section)
59  (if system
60    (output-macro e 'Os system)
61    (output-macro e 'Os)))