File: preparse.scm

package info (click to toggle)
sdc 1.0.8beta-8
  • links: PTS
  • area: contrib
  • in suites: slink
  • size: 1,400 kB
  • ctags: 874
  • sloc: lisp: 8,120; ansic: 967; makefile: 671; perl: 136; sh: 50
file content (158 lines) | stat: -rw-r--r-- 5,028 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
(message 1 "Loading Slide")
(set! sgml-opts (cons "-i Lout " (cons "-i Slide " sgml-opts)))
(set! *load-path* (append *typeset-lib* *load-path*))
(load "target/lout/preparse.scm")

(define-macro (divert-on) ''#(DIVERT POP))
(define-macro (divert-off) ''#(DIVERT "/dev/null"))

(define (rdp-parse-new grammar stream . variables)
  (if
   (stream-empty? stream)
   stream
   (grammar
    `(,(lambda (c h s) (display 'empty-stream (current-error-port)) s))
    (apply ((make-state-env) 'def) variables)
    stream)))

(define (slide-heads contents)
  (let* ((heading '())
	 (get-heading
	  (rdp-repll '()
		     (rdp-map1
		      (lambda (h)
			(set! heading (stream->list h))
			empty-stream)
		      contents))))
    `((#(STARTTAG (H0 H1 H2 H3 H4 HP AH0 AH1 AH2 AH3 AH4))
       ,get-heading)
      (#(STARTTAG SLIDE)
       ,(rdp-repll
	 (lambda (t)
	   (let ((hd (xat t 'HEADING)))
	     (if (not (eq? (arg-type hd) 'IMPLIED))
		 (set! heading
		       (stream->list
			(rdp-parse
			 contents
			 ; confusing?
			 ; need to terminate the `contents'-parsing
			 ; by apppending a `ENDTAG' token
			 (stream-append (arg-val hd) (stream '#(ENDTAG))))))))
	   `((,(divert-on) #"\n@Overhead @Title{" ,@heading #"}\n@Begin\n")
	     (#"\n@End @Overhead\n" ,(divert-off))))
	 contents))
      (#(STARTTAG NEWPAGE)
       ,(rdp-repll
	 (lambda (t)
	   `((#"\n@NP @CenteredDisplay @Heading{" ,@heading #"}\n")))
	 contents))
      )))

(define slide-divs
  `(((SECT APPDX)
     (,(divert-on) #"\n@Lecture\n@Begin\n@BeginOverheads\n" ,(divert-off))
     (,(divert-on) #"\n@EndOverheads\n@End @Lecture\n" ,(divert-off)))
    ((DTTL RTTL BTTL)  "    @Title{ " (" }
//
" ,(divert-off)))

    ((SECT1 SECT2 SECTN APPDX1 APPDX2 APPDXN
      SECTS SECT1S SECT2S SECTNS APPDXS APPDX1S APPDX2S APPDXNS
      CPAPT CHAPTS
      INTRO PREFACE ABSTRACT))
    ))

(define slide-repls
  (letrec
      ((contents
	(rdp-cond*
	 (lout-desc
	  (old-lout-tbl
	   `(,lout-p-data
	     ,@(slide-heads (rdp-call contents))
	     (#(ENDTAG) ,rdp-leave)
	     . ,(def-repl
		  (rdp-call contents)
		  `(,slide-divs ,lout-repls1 ,lout-body)
		  `(,@(lout-figure (rdp-call contents))
		    (#((PLACE BIBDB INDEXDB)) ,(rdp-skip 1))
		    (#((PI OUTPUT)) ,pass-token-action)
		    (#() ,(lambda (c h s)
			    (message 0 #"\nUnhandled: " (head s))
			    (rdp-reduce c h (tail s))))))))))))
    contents))

(define (slide-all basic)
  ((rdp-cond
    `((#(STARTTAG (BOOK DOCUMENT REPORT)) ; all the possible docs
					; replaced by:
       ,(rdp-repll
	 (lambda (t)
	   (let ((author (lout-tr-string (xatv t 'author)))
		 (inst (lout-tr-string (xatv t 'inst))))
	     `(( ,lout-general-header
		 "
  @SysInclude { slidesf }			  # OverheadLayout extension
  @SysInclude { graph }
  @Include { mydefs }

@Use { @DocumentLayout
    @InitialFont	{ Times Base 20p	} # initial font
    @InitialBreak	{ ragged 1.2fx nohyphen	} # initial break
    @PageType		{ Other			} # page type (width, height)
    @PageWidth		{ 595p			} # page width if type Other
#    @PageHeight	{ 595p			} # page height if type Other
    @PageHeight		{ 842p			} # page height if type Other
#    @PageOrientation	{  Landscape	} # Portrait, Landscape, etc.
    @PageOrientation	{  Portrait	} # Portrait, Landscape, etc.
    @PageBoxType	{ CurveBox	} # None Box CurveBox ShadowBox
    @PageBoxMargin	{ 0.4c			} # page box margin
    @FootMargin		{ 5.00c		} # bottom margin of all pages
#    @OddLeftMargin	{  5.0c	} # left margin of odd pages
#    @EvenLeftMargin	{  5.0c	} # left margin of even pages
    @ListGap{ 1v }
    @PageHeaders	{ Titles	       } # None Simple Titles NoTitles
    @OddTop		{ @Right 8p @Font @PageNum	}
    @EvenTop		{ @Right 8p @Font @PageNum	}
    @StartOddTop	{ @Right 8p @Font @PageNum	}
    @StartEvenTop	{ @Right 8p @Font @PageNum	}
    @RunningOddTop  { 8p @Font {@MajorTitle @MinorNum (ctd.) @Right @PageNum}}
    @RunningOddFoot { 8p @Font { @Right " ,AUTHOR "}	      	     }
    @RunningEvenTop { 8p @Font {@MajorTitle @MinorNum (ctd.) @Right @PageNum}}
    @RunningEvenFoot{ 8p @Font { @Right " ,AUTHOR "}	      	     }
    @RunningStartOddTop	 { 8p @Font { @MajorTitle @MinorNum @Right @PageNum }}
    @RunningStartOddFoot { 8p @Font { @Right " ,AUTHOR "}		     }
    @RunningStartEvenTop { 8p @Font { @MajorTitle @MinorNum @Right @PageNum }}
    @RunningStartEvenFoot{ 8p @Font { @Right " ,AUTHOR "}		     }
}

@Use { @OverheadLayout }
@Use { @TypesetLayout }

@OverheadTransparencies
   @Author{ "      ,AUTHOR " }
   @Institution{ " ,INST " }
"))))
	 slide-repls))
       ))				; close the repl list
					; and the rdp-cond

     `(,(lambda (c h s) empty-stream))	; terminator
     (lambda nanu nanu)			; dummy
     basic				; the input
  ))

(set! compile-function
      (lambda (o d e)
	(with-output-to-file
	    (string-append d e)
	  (lambda ()
	    (doc-preprocess-hook 'run)
	    ((stream-display-diverted)
	     (stream-through
	      (token-stream o)
	      slide-all
	      all-doctypes))))))

(set! compile-function (lout-run-over compile-function))