summaryrefslogtreecommitdiff
path: root/manual/styles/syntaxdef.hva
blob: a886fa7b39cd47572cd889a384fb0dbd8e196166 (plain)
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
159
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hevea code for syntax definitions of the ocaml manual %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Important commands
% \token, for typesetting grammar terminals
% \nonterm, for typesetting grammar non-terminals
%
% Beware: \nonterm introduces either a local anchor or a local reference
%   -Anchors are introduced when \nonterm occurs in the first column of
%    syntax definitions (environment 'syntax')
%   - References are introduced everywhere else
%
% For pure typesetting effect without links (eg. to typeset 'e' as 'expr') 
% use the \nt command (eg. \nt{e}).
% In syntax definitions, the tool 'transf' translates @word@ into \nt{word}.
%
% Warnings are produced
%  - For references to non-defined non terminals
%  - For multiple definitions of the same non-terminal
% Warnings can be avoided for a given non-terminal 'expr' by issuing
% the command \stx@silent{'expr'}
%
%It is also possible to alias a nonterminal:
%\stx@alias{name}{othername}
%will make reference to 'name' point to the definition of non-terminal
%'othername'
\newif\ifspace
\def\addspace{\ifspace\;\spacefalse\fi}
\ifhtml
\newcommand{\token}[1]{\textnormal{\@span{class=syntax-token}#1}}
\newstyle{.syntax-token}{color:blue;font-family:monospace}
\else
\newcommand{\token}[1]{\texttt{#1}}
\fi
%%% warnings
\def\stx@warning#1#2{\@ifundefined{stx@#1@silent}{\hva@warn{#2}}{}}
\def\stx@silent#1{\def\csname stx@#1@silent\endcsname{}}
%%% Do not warn about those
%initial example
\stx@silent{like}\stx@silent{that}%
%Not defined
\stx@silent{regular-char}%
\stx@silent{regular-string-char}%
%\stx@silent{regular-char-str}%
\stx@silent{lowercase-ident}%
\stx@silent{capitalized-ident}%
\stx@silent{space}%
\stx@silent{tab}%
\stx@silent{newline}%
%Used in many places
\stx@silent{prefix}%
\stx@silent{name}%
\stx@silent{xname}%
%Not defined
\stx@silent{external-declaration}%
\stx@silent{unit-name}%
%%Redefined in exten.etex
\stx@silent{parameter}%
\stx@silent{pattern}%
\stx@silent{constr-decl}%
\stx@silent{type-param}%
\stx@silent{let-binding}%
\stx@silent{expr}%
\stx@silent{typexpr}%
\stx@silent{module-expr}%
\stx@silent{type-representation}%
\stx@silent{definition}%
\stx@silent{specification}%
\stx@silent{type-equation}%
\stx@silent{class-field}%
\stx@silent{mod-constraint}%
\stx@silent{module-type}%
\stx@silent{constant}%
%%Redefined in names.etex
\stx@silent{label-name}%
%%Not really defined in lexyacc.etex
\stx@silent{character-set}%
\stx@silent{symbol}%
%%Not defined in debugger.etex
\stx@silent{integer}
%%Not defined in ocamldoc.etex
\stx@silent{string}
\stx@silent{id}
\stx@silent{Exc}
\stx@silent{URL}
%%%%%%%%%%%%%
%% Aliases %%
%%%%%%%%%%%%%
\newcommand{\stx@alias}[2]{\def\csname stx@#1@alias\endcsname{#2}}
\stx@alias{typ}{typexpr}%
\stx@alias{met}{method-name}%
\stx@alias{tag}{tag-name}%
\stx@alias{lab}{label-name}%
\stx@alias{C}{constr-name}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%special anchor
\newstyle{a.syntax:link}{color:maroon;text-decoration:underline}
\newstyle{a.syntax:visited}{color:maroon;text-decoration:underline}
\newstyle{a.syntax:hover}{color:black;text-decoration:none;background-color:\#FF6060}
%compatibility for hevea-1.1?/heeva-2.??
\ifu\@tr@url
\providecommand{\@tr@url}[1]{#1}\def\stx@id{NAME}\else
\def\stx@id{id}\fi
\newcommand{\@syntaxlocref}[2]
{\@aelement{href="\@print{#}\@tr@url{#1}" class="syntax"}{#2}}
\newcommand{\@syntaxaname}[2]
{\@aelement{\stx@id="#1" class="syntax"}{#2}}
%%Refer to anchor, internal :
%#1 -> anchor #2 -> visible tag
\def\@ref@anchor#1#2{%
\@ifundefined{stx@#1@exists}
{\stx@warning{#1}{Undefined non-terminal: '#1'}#2}
{\@syntaxlocref{#1}{#2}}}
%%Refer to anchor
\def\ref@anchor#1{%
\ifu\csname stx@#1@alias\endcsname
\@ref@anchor{#1}{#1}\else
\@ref@anchor{\csname stx@#1@alias\endcsname}{#1}\fi}
\def\stx@exists#1{\def\csname stx@#1@exists\endcsname{}}
%%Define anachor
\def\def@anchor#1{%
\@ifundefined{stx@#1}
{{\@nostyle\@auxdowrite{\string\stx@exists\{#1\}}}%
\gdef\csname stx@#1\endcsname{}\@syntaxaname{#1}{#1}}
{\@ifundefined{stx@#1@silent}
{\hva@warn{Redefinition of non-terminal '#1'}#1}
{\ref@anchor{#1}}}}
%%%Change \@anchor and initial definition, for html only, of course!
\ifhtml
\def\set@name{\let\@anchor\def@anchor}
\let\@anchor\ref@anchor
\else
\def\set@name{}
\def\@anchor{}
\fi
%%%Format non-terminal
\def\nt#1{\textnormal{\@span{class=nonterminal}#1}}
\newstyle{.nonterminal}{color:maroon;font-style:oblique}
%%%Link for non-terminal and format
\def\nonterm#1{\addspace\nt{\@anchor{#1}}\spacetrue}
\def\brepet{\addspace\{}
\def\erepet{\}}
\def\boption{\addspace[}
\def\eoption{]}
\def\brepets{\addspace\{}
\def\erepets{\}^+}
\def\bparen{\addspace(}
\def\eparen{)}
\def\orelse{\mid \spacefalse}
\def\is{ & ::= & \spacefalse }
\def\alt{ \\ & \mid & \spacefalse }
\def\sep{ \\ \\ \spacefalse }
\def\cutline{}
\def\emptystring{\epsilon}
\def\syntax{\@open{div}{class="syntax"}$$\begin{array}{>{\set@name}rcl}\spacefalse}
\def\endsyntax{\end{array}$$\@close{div}}
\def\syntaxleft{\@open{div}{class="syntaxleft"}$\begin{array}{>{\set@name}rcl}\spacefalse}
\def\endsyntaxleft{\end{array}$\@close{div}}
\def\synt#1{$\spacefalse#1$}