src/parser/streams-{proto,impl}.lisp: Publish classes and generic functions.
[sod] / doc / sod.sty
CommitLineData
1f7d590d
MW
1%%% -*-latex-*-
2%%%
3%%% Styles and other hacking for the Sod manual
4%%%
5%%% (c) 2015 Straylight/Edgeware
6%%%
7
8%%%----- Licensing notice ---------------------------------------------------
9%%%
e0808c47 10%%% This file is part of the Sensible Object Design, an object system for C.
1f7d590d
MW
11%%%
12%%% SOD is free software; you can redistribute it and/or modify
13%%% it under the terms of the GNU General Public License as published by
14%%% the Free Software Foundation; either version 2 of the License, or
15%%% (at your option) any later version.
16%%%
17%%% SOD is distributed in the hope that it will be useful,
18%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
19%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20%%% GNU General Public License for more details.
21%%%
22%%% You should have received a copy of the GNU General Public License
23%%% along with SOD; if not, write to the Free Software Foundation,
24%%% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26\ProvidesPackage{sod}
27
28%% More reference types.
29\defxref{p}{part}
30
ca2023b8
MW
31\def\instead#1#2{#1}
32
1f7d590d
MW
33%% Other languages with special typesetting.
34\def\Cplusplus{C\kern-\p@++}
35\def\Csharp{C\#}
36
37%% Special maths notation.
38\def\chain#1#2{\mathsf{ch}_{#1}(#2)}
39\def\chainhead#1#2{\mathsf{hd}_{#1}(#2)}
40\def\chaintail#1#2{\mathsf{tl}_{#1}(#2)}
41
42%% Other mathematical tweaks.
43\let\implies\Rightarrow
44\let\epsilon\varepsilon
45
2ba6e0bd
MW
46%% A table heading cell. Clone and hack \multicolumn.
47\def\thd{\omit\@ifnextchar[\thd@{\thd@[l]}}
48\def\thd@[#1]#2{%
49 \begingroup
50 \tab@multicol \tab@initread \let\tab@looped\tab@err@multi
51 \tab@preamble{}\def\tab@midtext{\bfseries#2}\tab@readpreamble{#1}%
52 \the\tab@preamble
53 \endgroup \ignorespaces
54}
55
1f7d590d
MW
56%% Unix manpage references.
57\def\man#1#2{\textbf{#1}(#2)}
58
59%% Listings don't need to be small.
60\let\listingsize\relax
61
fea590fe 62%% Notes for later.
228b271d 63\def\fixme#1{\leavevmode\marginpar{FIXME}\index{FIXME}[FIXME: #1]}
fea590fe 64
a4094071 65%% Diagram settings.
7be31112
MW
66\tikzset{
67 every picture/.style={>=stealth, thick},
68 lit/.style={font=\sffamily}
69}
a4094071 70
1f7d590d
MW
71%% Metavariables are italics without decoration.
72\def\syntleft{\normalfont\itshape}
73\let\syntright\empty
74
75%% Literal code is in sans face.
5f1bbd61 76\def\codeface{\upshape\sffamily}
ddfe4265
MW
77\DeclareRobustCommand\code[1]{%
78 \ifmmode\hbox\else\leavevmode\fi%
79 {\normalfont\codeface\/#1\/}%
80}
1f7d590d
MW
81\def\ulitleft{\normalfont\codeface}
82\let\ulitright\empty
48ab1447 83\def\lit@i#1#2#3{\ifmmode\leavevmode\hbox\fi{#1{#3\/}#2}}
1f7d590d
MW
84
85%% Conditionally enter maths mode. Can't use \ensuremath here because we
86%% aren't necessarily sure where the maths will actually end.
87\let\m@maybe@end\relax
88\def\m@maybe{\ifmmode\else$\let\m@maybe@end$\fi}
89
90%% Standard syntax shortcuts.
91\atdef <#1>{\synt{#1}\@scripts}
92\atdef "#1"{\lit*{#1}\@scripts}
93\atdef `#1'{\lit{#1}\@scripts}
5f1bbd61 94\atdef |#1|{\lit*{#1}\@scripts}
1f7d590d
MW
95
96%% A handy abbreviation; `\\' itself is too good to steal.
97\atdef \\{\textbackslash}
98
99%% Intercept grammar typesetting and replace the vertical bar with the
100%% maths-font version.
101\let\@@grammar\grammar
102\def\grammar{\def\textbar{\hbox{$|$}}\@@grammar}
103
104%% Collect super- and subscripts. (Note that underscores are active for the
105%% most part.) When we're done, end maths mode if we entered it
106%% conditionally.
107\def\@scripts{\futurelet\@ch\@scripts@i}
108\begingroup\lccode`\~=`\_\lowercase{\endgroup
109\def\@scripts@i{\if1\ifx\@ch~1\else\ifx\@ch^1\else0\fi\fi%
110 \expandafter\@scripts@ii\else\expandafter\m@maybe@end\fi}}
111\def\@scripts@ii#1#2{\m@maybe#1{#2}\@scripts}
112
113%% Doubling characters, maybe. Either way, chain onto \@scripts.
114\def\dbl@maybe#1{\let\@tempa#1\futurelet\@ch\dbl@maybe@i}
115\def\dbl@maybe@i{\m@maybe\ifx\@ch\@tempa\@tempa\!\@tempa%
116 \expandafter\@firstoftwo\expandafter\@scripts%
117 \else\@tempa\expandafter\@scripts\fi}
118
119%% Extra syntax for Lisp templates. These produce the maths-font versions of
120%% characters, which should contrast well against the sans face used for
121%% literals.
122\atdef [{\dbl@maybe[}
123\atdef ]{\dbl@maybe]}
124\atdef {{\m@maybe\{\@scripts}
125\atdef }{\m@maybe\}\@scripts}
126\atdef ({\m@maybe(\@scripts}
127\atdef ){\m@maybe)\@scripts}
128\atdef !{\m@maybe|\@scripts}
129\def\returns{\m@maybe\longrightarrow\m@maybe@end\hspace{0.5em}\ignorespaces}
130\atdef >{\leavevmode\unskip\hspace{0.5em}\returns}
a5d80269 131\atdef -#1{\if>#1\hbox{--\raisebox{.4pt}{>}}\penalty200\relax\fi}
1f7d590d
MW
132
133%% Comment setting.
888d5e58
MW
134\def\comment#1{\mbox{\normalfont\itshape\/#1\/}}
135\atdef /*#1*/{/*\comment{#1}*/}
136\def\@semis{\@ifnextchar;{;\@semis}\@semicomment}
137\def\@semicomment#1\\{\comment{#1}\\}
138\atdef ;#1\\{;\@semis}
1f7d590d
MW
139
140%% Environment for setting programs. Newlines are explicit, because
141%% otherwise I need comments in weird places to make the vertical spacing
142%% come out properly. You can write `\obeylines' if you really want to.
4effe575
MW
143\def\@prog{\let\prog@@cr\@tabcr\let\@tabcr\@progcr\codeface\tabbing}
144\def\prog{\quote\@prog}
1f7d590d 145\def\endprog{\endtabbing\endquote}
4effe575
MW
146\let\nprog\@prog
147\let\endnprog\endtabbing
1f7d590d 148\def\ind{\quad\=\+\kill}
ebf5ae2e
MW
149\def\@progcr{\futurelet\@tempa\@progcr@i}
150{\def\:{\gdef\@progcr@sp}\: {\@progcr}}
ca8f5d55 151\atdef~{\textasciitilde}
ebf5ae2e
MW
152\def\@progcr@i{%
153 \ifx\@tempa\@sptoken\let\next@\@progcr@sp\else
154 \if1\ifx\@tempa[1\else
155 \ifx\@tempa*1\else
156 0\fi\fi
157 \let\next@\prog@@cr\else
158 \if1\ifx\@tempa+1\else
159 \ifx\@tempa-1\else
160 0\fi\fi
161 \let\next@\@progcr@ii\else
162 \let\next@\@progcr@a\fi\fi\fi
163 \next@}
164\def\@progcr@a{\prog@@cr*{}\ignorespaces}
165\def\@progcr@ii#1{\csname @progcr@#1\endcsname\ignorespaces}
166\@namedef{@progcr@+}{\prog@@cr[\medskipamount]}
167\@namedef{@progcr@-}{\prog@@cr*[\jot]}
5e4a5d53 168\def\macsl{\`\textbackslash\hskip\leftmargin}
1f7d590d
MW
169
170%% Put a chunk of text in a box.
171\newenvironment{boxy}[1][\q@]{%
9eb66c6e 172 \savenotes
1f7d590d
MW
173 \dimen@\linewidth\advance\dimen@-1.2pt\advance\dimen@-2ex%
174 \medskip%
175 \vbox\bgroup\hrule\hbox\bgroup\vrule%
176 \vbox\bgroup\vskip1ex\hbox\bgroup\hskip1ex\minipage\dimen@%
177 \def\@temp{#1}\ifx\@temp\q@\else\leavevmode{\headfam\bfseries#1\quad}\fi%
178}{%
179 \endminipage\hskip1ex\egroup\vskip1ex\egroup%
180 \vrule\egroup\hrule\egroup%
181 \medskip%
9eb66c6e 182 \spewnotes%
1f7d590d
MW
183}
184
185%% Lisp documentation machinery.
87883222
MW
186\def\definedescribecategory#1{%
187 \@ifnextchar[{\def@desc{#1}}{\def@desc{#1}[plain]}}
188\def\def@desc#1[#2]#3{\@namedef{cat!#1}##1{#3}\@namedef{catsw!#1}{#2}}
072f666e
MW
189\def\describecategoryname{\@ifnextchar[\@descname@i{\@descname@i[]}}
190\def\@descname@i[#1]#2{%
191 \expandafter\let\expandafter\@tempa\csname cat!#2\endcsname%
19a89075 192 \expandafter\let\expandafter\@tempb\csname modcat/#1\endcsname%
b35ac53a 193 \ifx\@tempa\relax\@tempb{#2}\else\@tempa\@tempb\fi}
22549a08 194\def\@mod@dispatch#1#2{\csname #1/#2\endcsname}
894e3dc9
MW
195\def\@desc@dispatch#1#2{%
196 \csname #1/%
197 \expandafter\ifx\csname catsw!#2\endcsname\relax plain%
198 \else \csname catsw!#2\endcsname \fi%
199 \endcsname%
200}
072f666e 201
95346c38 202\definedescribecategory{sym}{symbol}
b35ac53a
MW
203\definedescribecategory{fun}{#1{function}}
204\definedescribecategory{gf}{generic #1{function}}
57bcf70e 205\definedescribecategory{msg}{message}
1f7d590d 206\definedescribecategory{var}{variable}
7cd50210 207\definedescribecategory{modvar}{module variable}
1f7d590d 208\definedescribecategory{const}{constant}
87883222
MW
209\definedescribecategory{meth}[method]{primary #1{method}}
210\definedescribecategory{ar-meth}[method]{\code{:around} #1{method}}
211\definedescribecategory{be-meth}[method]{\code{:before} #1{method}}
212\definedescribecategory{af-meth}[method]{\code{:after} #1{method}}
1f7d590d 213\definedescribecategory{cls}{class}
db6c3279 214\definedescribecategory{rst}{restart}
1f7d590d 215\definedescribecategory{ty}{type}
ddfe4265 216\definedescribecategory{type}{type}
b35ac53a 217\definedescribecategory{mac}{#1{macro}}
558e70ee 218\definedescribecategory{feat}{feature macro}
b35ac53a 219\definedescribecategory{lmac}{local #1{macro}}
95346c38
MW
220\definedescribecategory{parse}{parser spec}
221\definedescribecategory{parseform}{parser form}
222\definedescribecategory{opt}{option handler}
223\definedescribecategory{optmac}{option macro}
7cd50210 224\definedescribecategory{plug}{pluggable parser}
1f7d590d
MW
225\def\nlret{\\\hspace{4em}\returns}
226
19a89075 227\@namedef{modcat/}#1{#1}
22549a08
MW
228\@namedef{modlabel/}#1{#1}
229\@namedef{modindex/}#1{#1@\noexpand\code{#1}}
b35ac53a 230
19a89075 231\@namedef{modcat/setf}#1{\code{setf}-#1}
22549a08
MW
232\@namedef{modlabel/setf}#1{setf/#1}
233\@namedef{modindex/setf}#1{#1@\noexpand\code{#1}}
b35ac53a 234
63288801
MW
235\@namedef{modcat/muffs}#1{#1}
236\@namedef{modlabel/muffs}#1{*#1*}
237\@namedef{modindex/muffs}#1{#1@\noexpand\code{*#1*}}
238
239\@namedef{modcat/kwd}#1{#1}
240\@namedef{modlabel/kwd}#1{:#1}
241\@namedef{modindex/kwd}#1{#1@\noexpand\code{:#1}}
242
87883222 243\@namedef{descargs/plain}#1{#1{}}
22549a08 244\@namedef{desclabel/plain}#1#2#3{#1:\@mod@dispatch{modlabel}{#2}{#3}}
87883222 245\@namedef{descindex/plain}#1#2#3{%
22549a08 246 \@mod@dispatch{modindex}{#2}{#3}!%
87883222
MW
247 \protect\describecategoryname[#2]{#1}%
248}
249
250\@namedef{descargs/method}#1#2{#1{{#2}}}
22549a08
MW
251\@namedef{desclabel/method}#1#2#3#4%
252 {#1:\@mod@dispatch{modlabel}{#2}{#3}(#4)}
87883222 253\@namedef{descindex/method}#1#2#3#4{%
22549a08 254 \@mod@dispatch{modindex}{#2}{#3}!%
87883222
MW
255 \protect\describecategoryname[#2]{#1}%
256 \protect\fmtspecs{ specialized at }{#4}%
257}
258
1f7d590d 259\def\q@{\q@}
072f666e 260\def\@setf{setf}
2242bae8 261
87883222
MW
262\def\fmtspecs#1#2{%
263 \if!#2!\else\count@\z@\toks@{}#1\@fmtspecs@i#2,\q@,\fi}
264\def\@fmtspecs@i#1,{%
265 \def\@tempa{#1}%
266 \ifx\@tempa\q@%
267 \ifcase\count@(no args?!)%
268 \or% nothin' doin
269 \or \space and %
270 \else, and %
271 \fi%
272 \the\toks@%
273 \else%
274 \ifnum\count@>\@ne, \fi%
275 \the\toks@%
276 \toks@{\code{#1}}\advance\count@\@ne%
277 \expandafter\@fmtspecs@i%
278 \fi%
279}
280
be18b63c 281%% \parse@dhd{NEXT}[MOD]{CAT}{...}...[NAME]{SYNOPSIS}
87883222
MW
282%% call NEXT{MOD}{CAT}{{...}...}{NAME}{SYNOPSIS}
283%% #1 #2 #3 #4 #5
be18b63c 284\def\@setf{setf}
63288801 285\def\@starstar{**}
be18b63c
MW
286\def\parse@dhd#1{% {NEXT}
287 \@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}}
288\def\parse@dhd@a#1[#2]#3{% {NEXT}[MOD]{CAT}
289 \@desc@dispatch{descargs}{#3}{\parse@dhd@ab{#1}{#2}{#3}}}
290\def\parse@dhd@ab#1#2#3#4{% {NEXT}{MOD}{CAT}{{...}...}
291 \@ifnextchar[{\parse@dhd@ac{#1}{#2}{#3}{#4}}{\parse@dhd@ad{#1}{#2}{#3}{#4}}}
292\def\parse@dhd@ac#1#2#3#4[#5]#6{% {NEXT}{MOD}{CAT}{{...}...}[NAME]{SYNOPSIS}
293 #1{#2}{#3}{#4}{#5}{#6}}
294\def\parse@dhd@ad#1#2#3#4#5{% {NEXT}{MOD}{CAT}{{...}...}{NAME [ARGS...]}
295 \parse@dhd@ae{#1}{#2}{#3}{#4}{#5}#5 \q@}
296\def\parse@dhd@ae#1#2#3#4#5#6 #7\q@{%
297 % {NEXT}{MOD}{CAT}{{...}...}{SYNSOPSIS}NAME [ARGS...]\q@
298 #1{#2}{#3}{#4}{#6}{#5}}
299
300\def\parse@dhd@c#1#2{% {NEXT}{CAT}
87883222
MW
301 \@desc@dispatch{descargs}{#2}{\parse@dhd@cb{#1}{#2}}}
302\def\parse@dhd@cb#1#2#3{% {NEXT}{CAT}{{...}...}
303 \@ifnextchar[{\parse@dhd@cc{#1}{#2}{#3}}{\parse@dhd@cd{#1}{#2}{#3}}}
304\def\parse@dhd@cc#1#2#3[#4]#5{% {NEXT}{CAT}{{...}...}[NAME]{SYNOPSIS}
305 #1{}{#2}{#3}{#4}{#5}}
306\def\parse@dhd@cd#1#2#3#4{% {NEXT}{CAT}{{...}...}{SYNOPSIS}
307 \parse@dhd@ce{#1}{#2}{#3}{#4}#4 \q@}
308\def\parse@dhd@ce#1#2#3#4#5 #6\q@{%
309 % {NEXT}{CAT}{{...}...}{SYNOPSIS}NAME [ARGS...]\q@
310 \def\temp@{#5}%
311 \ifx\@setf\temp@\def\next@{\parse@dhd@csetf{#1}{#2}{#3}{#4}#6 \q@}%
63288801
MW
312 \else\def\temp@##1##2*##3\q@{\def\temp@{##1##3}}\temp@#5*\q@%
313 \ifx\temp@\@starstar\def\next@{\parse@dhd@cmuffs{#1}{#2}{#3}{#4}#5}%
314 \else\def\temp@##1##2\q@{\def\temp@{##1}}\temp@#5\q@%
315 \if:\temp@\def\next@{\parse@dhd@ckwd{#1}{#2}{#3}{#4}#5\q@}%
316 \else\def\next@{#1{}{#2}{#3}{#5}{#4}}\fi\fi\fi%
072f666e
MW
317 \next@%
318}
87883222
MW
319\def\parse@dhd@csetf#1#2#3#4(#5 #6\q@{%
320 % {NEXT}{CAT}{{...}...}{SYNOPSIS}(NAME [ARGS...])\q@
321 #1{setf}{#2}{#3}{#5}{#4}}
63288801
MW
322\def\parse@dhd@cmuffs#1#2#3#4*#5*{%
323 % {NEXT}{CAT}{{...}...}{SYNOPSIS}*NAME*
324 #1{muffs}{#2}{#3}{#5}{#4}}
325\def\parse@dhd@ckwd#1#2#3#4:#5\q@{%
326 % {NEXT}{CAT}{{...}...}{SYNOPSIS}:NAME\q@
327 #1{kwd}{#2}{#3}{#5}{#4}}
7e94c5fe
MW
328
329\newif\if@dheadfirst
330\def\dhead{\parse@dhd\dhead@}
87883222 331\def\dhead@#1#2#3#4#5{% {MOD}{CAT}{{...}...}{NAME}{SYNOPSIS}
79766c36 332 \if@dheadfirst\global\@dheadfirstfalse\else\relax\\*[\smallskipamount]\fi%
e8511505 333 \phantomsection%
072f666e 334 {\let\protect\@empty\let\@uscore\relax%
87883222
MW
335 \edef\temp@{\@desc@dispatch{desclabel}{#2}{#2}{#1}{#4}#3}%
336 \def\@uscore{_\@gobble}\expandafter\message\expandafter{\temp@}%
337 \def\@uscore{-\@gobble}\expandafter\label\expandafter{\temp@}}%
ddfe4265
MW
338 {\begingroup\lccode`\~=`\_\lowercase{\endgroup\def~{_}}%
339 \protected@edef\@tempa##1{%
87883222
MW
340 \noexpand\index{\@desc@dispatch{descindex}{#2}{#2}{#1}{#4}#3##1}}%
341 \toks@\expandafter{\@tempa{|)}}%
342 \toks\tw@\expandafter{\after@desc}%
343 \xdef\after@desc{\the\toks\tw@\the\toks@}%
072f666e 344 \@tempa{|(}}%
ac6e7a4e 345 \rlap{\hb@xt@\linewidth{\hfil\normalfont\bfseries
072f666e 346 [\describecategoryname[#1]{#2}]}}%
87883222 347 #5%
7e94c5fe
MW
348}
349
350\def\desc@begin#1{%
ddfe4265
MW
351 \let\saved@after@desc\after@desc%
352 \gdef\after@desc{}%
1f7d590d 353 \normalfont%
7e94c5fe
MW
354 \if@nobreak\else\par\goodbreak\fi%
355 \global\@dheadfirsttrue%
356 \begingroup%
7e94c5fe
MW
357 \let\@endparenv\relax%
358 \clubpenalty\@M \widowpenalty\@M \interlinepenalty50%
ebf5ae2e 359 \@prog#1\endtabbing%
7e94c5fe
MW
360 \endgroup%
361 \penalty\@M\@afterheading%
362 \list{}{\rightmargin\z@\topsep\z@}\item%
1f7d590d 363}
ddfe4265 364\def\desc@end{\endlist\after@desc\global\let\after@desc\saved@after@desc}
7e94c5fe 365
e8d70b1b
MW
366\def\@ifnextchar@preserve#1#2#3{%
367 \let\want@= #1\def\@tempa{#2}\def\@tempb{#3}%
368 \futurelet\nch@\@ifnch@p%
369}
370\def\@ifnch@p{%
371 \ifx\want@\nch@\expandafter\@tempa\else\expandafter\@tempb\fi}
372
7e94c5fe
MW
373\@namedef{describe*}#1{\desc@begin{#1}}
374\expandafter\let\csname enddescribe*\endcsname\desc@end
375\def\describe{\parse@dhd\desc@}
87883222 376\def\desc@#1#2#3#4#5{\desc@begin{\dhead@{#1}{#2}{#3}{#4}{#5}}}
7e94c5fe 377\let\enddescribe\desc@end
1f7d590d 378
ea214e5e
MW
379\def\descref{\@ifstar%
380 {\descref@i{}\@gobble{}}%
381 {\descref@i{ (}{\noexpand\autopageref}{)}}}
e8d70b1b
MW
382\def\descref@i#1#2#3#4#5{\@ifnextchar@preserve[%
383 {\descref@ii{#1}{#2}{#3}{#4}{#5}}%
384 {\descref@iii{#1}{#2}{#3}{#4}{#5}{}}}
385\def\descref@ii#1#2#3#4#5[#6]{\descref@iii{#1}{#2}{#3}{#4}{#5}{ #6}}
ea214e5e 386\def\descref@iii#1#2#3#4#5#6{%
5cf27cf1
MW
387 \begingroup%
388 \let\protect\@empty%
389 \def\@uscore{-\@gobble}%
390 \edef\@tempa##1{%
391 \endgroup%
e8d70b1b 392 \noexpand\hyperref[#4:#5]%
5cf27cf1 393 ##1%
e8d70b1b 394 #2{#4:#5}%
5cf27cf1 395 }%
e8d70b1b 396 \@tempa{{\code{#5}}#6#1}#3%
58f9b400
MW
397}
398
f1f17867
MW
399%%%----- That's all, folks --------------------------------------------------
400\endinput