1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Hevea code for syntax definitions of the ocaml manual %
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 % Important commands
5 % \token, for typesetting grammar terminals
6 % \nonterm, for typesetting grammar non-terminals
7 %
8 % Beware: \nonterm introduces either a local anchor or a local reference
9 % -Anchors are introduced when \nonterm occurs in the first column of
10 % syntax definitions (environment 'syntax')
11 % - References are introduced everywhere else
12 %
13 % For pure typesetting effect without links (eg. to typeset 'e' as 'expr')
14 % use the \nt command (eg. \nt{e}).
15 % In syntax definitions, the tool 'transf' translates @word@ into \nt{word}.
16 %
17 % Warnings are produced
18 % - For references to non-defined non terminals
19 % - For multiple definitions of the same non-terminal
20 % Warnings can be avoided for a given non-terminal 'expr' by issuing
21 % the command \stx@silent{'expr'}
22 %
23 %It is also possible to alias a nonterminal:
24 %\stx@alias{name}{othername}
25 %will make reference to 'name' point to the definition of non-terminal
26 %'othername'
27 \newif\ifspace
28 \def\addspace{\ifspace\;\spacefalse\fi}
29 \ifhtml
30 \newcommand{\token}[1]{\texttt{\blue#1}}
31 \else
32 \newcommand{\token}[1]{\texttt{#1}}
33 \fi
34 %%% warnings
35 \def\stx@warning#1#2{\@ifundefined{stx@#1@silent}{\hva@warn{#2}}{}}
36 \def\stx@silent#1{\def\csname stx@#1@silent\endcsname{}}
37 %%% Do not warn about those
38 %initial example
39 \stx@silent{like}\stx@silent{that}%
40 %Not defined
41 \stx@silent{regular-char}%
42 \stx@silent{regular-string-char}%
43 %\stx@silent{regular-char-str}%
44 \stx@silent{lowercase-ident}%
45 \stx@silent{capitalized-ident}%
46 \stx@silent{space}%
47 \stx@silent{tab}%
48 \stx@silent{newline}%
49 %Used in many places
50 \stx@silent{prefix}%
51 \stx@silent{name}%
52 \stx@silent{xname}%
53 %Not defined
54 \stx@silent{external-declaration}%
55 \stx@silent{unit-name}%
56 %%Redefined in exten.etex
57 \stx@silent{parameter}%
58 \stx@silent{pattern}%
59 \stx@silent{constr-decl}%
60 \stx@silent{type-param}%
61 \stx@silent{let-binding}%
62 \stx@silent{expr}%
63 \stx@silent{typexpr}%
64 \stx@silent{module-expr}%
65 \stx@silent{type-representation}%
66 \stx@silent{definition}%
67 \stx@silent{specification}%
68 \stx@silent{type-equation}%
69 \stx@silent{class-field}%
70 \stx@silent{mod-constraint}%
71 \stx@silent{module-type}%
72 \stx@silent{constant}%
73 %%Redefined in names.etex
74 \stx@silent{label-name}%
75 %%Not really defined in lexyacc.etex
76 \stx@silent{character-set}%
77 \stx@silent{symbol}%
78 %%Not defined in debugger.etex
79 \stx@silent{integer}
80 %%Not defined in ocamldoc.etex
81 \stx@silent{string}
82 \stx@silent{id}
83 \stx@silent{Exc}
84 \stx@silent{URL}
85 %%%%%%%%%%%%%
86 %% Aliases %%
87 %%%%%%%%%%%%%
88 \newcommand{\stx@alias}[2]{\def\csname stx@#1@alias\endcsname{#2}}
89 \stx@alias{typ}{typexpr}%
90 \stx@alias{met}{method-name}%
91 \stx@alias{tag}{tag-name}%
92 \stx@alias{lab}{label-name}%
93 \stx@alias{C}{constr-name}
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 %%special anchor
96 \newstyle{a.syntax:link}{color:maroon;text-decoration:underline}
97 \newstyle{a.syntax:visited}{color:maroon;text-decoration:underline}
98 \newstyle{a.syntax:hover}{color:black;text-decoration:none;background-color:\#FF6060}
99 %compatibility for hevea-1.1?/heeva-2.??
100 \ifu\@tr@url
101 \providecommand{\@tr@url}[1]{#1}\def\stx@id{NAME}\else
102 \def\stx@id{id}\fi
103 \newcommand{\@syntaxlocref}[2]
104 {\@aelement{href="\@print{#}\@tr@url{#1}" class="syntax"}{#2}}
105 \newcommand{\@syntaxaname}[2]
106 {\@aelement{\stx@id="#1" class="syntax"}{#2}}
107 %%Refer to anchor, internal :
108 %#1 -> anchor #2 -> visible tag
109 \def\@ref@anchor#1#2{%
110 \@ifundefined{stx@#1@exists}
111 {\stx@warning{#1}{Undefined non-terminal: '#1'}#2}
112 {\@syntaxlocref{#1}{#2}}}
113 %%Refer to anchor
114 \def\ref@anchor#1{%
115 \ifu\csname stx@#1@alias\endcsname
116 \@ref@anchor{#1}{#1}\else
117 \@ref@anchor{\csname stx@#1@alias\endcsname}{#1}\fi}
118 \def\stx@exists#1{\def\csname stx@#1@exists\endcsname{}}
119 %%Define anachor
120 \def\def@anchor#1{%
121 \@ifundefined{stx@#1}
122 {{\@nostyle\@auxdowrite{\string\stx@exists\{#1\}}}%
123 \gdef\csname stx@#1\endcsname{}\@syntaxaname{#1}{#1}}
124 {\@ifundefined{stx@#1@silent}
125 {\hva@warn{Redefinition of non-terminal '#1'}#1}
126 {\ref@anchor{#1}}}}
127 %%%Change \@anchor and initial definition, for html only, of course!
128 \ifhtml
129 \def\set@name{\let\@anchor\def@anchor}
130 \let\@anchor\ref@anchor
131 \else
132 \def\set@name{}
133 \def\@anchor{}
134 \fi
135 %%%Format non-terminal
136 \def\nt#1{\textit{\maroon#1}}
137 %%%Link for non-terminal and format
138 \def\nonterm#1{\addspace\nt{\@anchor{#1}}\spacetrue}
139 \def\brepet{\addspace\{}
140 \def\erepet{\}}
141 \def\boption{\addspace[}
142 \def\eoption{]}
143 \def\brepets{\addspace\{}
144 \def\erepets{\}^+}
145 \def\bparen{\addspace(}
146 \def\eparen{)}
147 \def\orelse{\mid \spacefalse}
148 \def\is{ & ::= & \spacefalse }
149 \def\alt{ \\ & \mid & \spacefalse }
150 \def\sep{ \\ \\ \spacefalse }
151 \def\cutline{}
152 \def\emptystring{\epsilon}
153 \def\syntax{\@open{div}{class="syntax"}$$\begin{array}{>{\set@name}rcl}\spacefalse}
154 \def\endsyntax{\end{array}$$\@close{div}}
155 \def\syntaxleft{\@open{div}{class="syntaxleft"}$\begin{array}{>{\set@name}rcl}\spacefalse}
156 \def\endsyntaxleft{\end{array}$\@close{div}}
157 \def\synt#1{$\spacefalse#1$}
158