forked from fvisin/thesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bnf.sty
123 lines (101 loc) · 2.56 KB
/
bnf.sty
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
%This _sty_ file was developed by Hugh Osborne at the University of
%Nijmegen, The Netherlands. It may be freely distributed under
%condition that this notice is always included in any copy distributed.
%No charge may be made for (copies of) this file, nor may any other
%remuneration be requested.
\typeout{Style-Option: `bnf' v1.1a <92/01/30> (Hugh Osborne/br)}
\def\@actifygrammarchars{%
\catcode`\"\active%
\catcode`\:\active%
\catcode`\,\active%
\catcode`\;\active%
\catcode`\.\active%
\catcode`\<\active%
\catcode`\>\active}
\def\@deactifygrammarchars{%
\@makeother\"%
\@makeother\:%
\@makeother\,%
\@makeother\;%
\@makeother\.%
\@makeother\<%
\@makeother\>}
\let\escapegrammar=\@deactifygrammarchars
\begingroup
\@deactifygrammarchars
\global\let\quotesymbol="
\global\let\lessthan=<
\global\let\greaterthan=>
\endgroup
\newif\if@outsidestring \@outsidestringtrue
\def\@first#1#2{#1}
\def\@second#1#2{#2}
\begingroup
\@actifygrammarchars
\gdef\@defcolon#1{
\catcode`\:\active
\def:{\def\newline{\hfill\break\hspace*{2em}}{\@deactifygrammarchars #1}}
\@makeother\:}
\gdef\@defcomma#1{
\catcode`\,\active
\def,{\def\newline{\hfill\break\hspace*{4em}}{\@deactifygrammarchars #1}}
\@makeother\,}
\gdef\@defsemicolon#1{
\catcode`\;\active
\def;{\def\newline{\hfill\break\hspace*{2em}}{\@deactifygrammarchars #1}}
\@makeother\;}
\gdef\@defperiod#1{
\catcode`\.\active
\def.{\def\newline{\vskip10pt plus10pt minus5pt}{\@deactifygrammarchars #1}}
\@makeother\.}
\gdef\@defnonterminal#1{
\catcode`\<\active
\catcode`\>\active
\def<{%
\begingroup%
\@first#1%
\@deactifygrammarchars%
\catcode`\>\active}
\def>{%
\@second#1%
\endgroup}
\@makeother\<
\@makeother\>}
\gdef\@defquote#1{
\catcode`\"\active
\def"{%
\if@outsidestring%
\@outsidestringfalse%
\begingroup%
\@deactifygrammarchars%
\catcode`\"\active%
\@first#1%
\else%
\@second#1%
\endgroup%
\@outsidestringtrue%
\fi}
\@makeother\"}
\endgroup
\let\@defterminal=\@defquote
\newenvironment{grammar}%
{\begin{quote}%
\@defaultchardefs%
\@dogrammarchars}%
{\@deactifygrammarchars%
\end{quote}}
\def\@dogrammarchars{
\@actifygrammarchars
\@ifnextchar [{\@deactifygrammarchars\@getchardef}{}}
\def\@getchardef[(#1)#2]{
\@dogrammarchar{#1}[#2]
\@dogrammarchars}
\def\@dogrammarchar#1[#2]{
\csname @def#1\endcsname{#2}}
\def\@defaultchardefs{
\@defquote{{``}{''}}%
\@defnonterminal{{$<$}{$>$}}%
\@defcolon{:\\}%
\@defsemicolon{;\\}%
\@defperiod{.\\}%
\@defcomma{, }}%