forked from backtracking/bibtex2html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
latex_accents.mll
228 lines (205 loc) · 10.3 KB
/
latex_accents.mll
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
(**************************************************************************)
(* bibtex2html - A BibTeX to HTML translator *)
(* Copyright (C) 1997-2014 Jean-Christophe Filliâtre and Claude Marché *)
(* *)
(* This software is free software; you can redistribute it and/or *)
(* modify it under the terms of the GNU General Public *)
(* License version 2, as published by the Free Software Foundation. *)
(* *)
(* This software is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *)
(* *)
(* See the GNU General Public License version 2 for more details *)
(* (enclosed in the file GPL). *)
(**************************************************************************)
(* Normalize both ISO-latin characters and LaTeX accents to HTML entities *)
{
let string_buf = Buffer.create 79
let add_string s = Buffer.add_string string_buf s
let add lexbuf = Buffer.add_string string_buf (Lexing.lexeme lexbuf)
let produce_regexp = ref false
}
let space = [ '\t']
rule next_char = parse
'\\'{ control lexbuf }
| '{' { next_char lexbuf }
| '}' { next_char lexbuf }
| 'ç' { add_string "ç" ; next_char lexbuf }
| 'Ç' { add_string "Ç" ; next_char lexbuf }
| 'ñ' { add_string "ñ"; next_char lexbuf }
| 'Ñ' { add_string "Ñ"; next_char lexbuf }
| 'ã' { add_string "ã"; next_char lexbuf }
| 'Ã' { add_string "Ã"; next_char lexbuf }
| 'õ' { add_string "õ"; next_char lexbuf }
| 'Õ' { add_string "Õ"; next_char lexbuf }
| 'ä' { add_string "ä"; next_char lexbuf }
| 'ö' { add_string "ö"; next_char lexbuf }
| 'ü' { add_string "ü"; next_char lexbuf }
| 'ë' { add_string "ë"; next_char lexbuf }
| 'Ä' { add_string "Ä"; next_char lexbuf }
| 'Ö' { add_string "Ö"; next_char lexbuf }
| 'Ü' { add_string "Ü"; next_char lexbuf }
| 'Ë' { add_string "Ë"; next_char lexbuf }
| 'ï' { add_string "ï"; next_char lexbuf }
| 'Ï' { add_string "Ï"; next_char lexbuf }
| 'á' { add_string "á"; next_char lexbuf }
| 'ó' { add_string "ó"; next_char lexbuf }
| 'ú' { add_string "ú"; next_char lexbuf }
| 'é' { add_string "é"; next_char lexbuf }
| 'Á' { add_string "Á"; next_char lexbuf }
| 'Ó' { add_string "Ó"; next_char lexbuf }
| 'Ú' { add_string "Ú"; next_char lexbuf }
| 'É' { add_string "É"; next_char lexbuf }
| 'í' { add_string "í"; next_char lexbuf }
| 'Í' { add_string "Í"; next_char lexbuf }
| 'à' { add_string "à"; next_char lexbuf }
| 'ò' { add_string "ò"; next_char lexbuf }
| 'ù' { add_string "ù"; next_char lexbuf }
| 'è' { add_string "è"; next_char lexbuf }
| 'À' { add_string "À"; next_char lexbuf }
| 'Ò' { add_string "Ò"; next_char lexbuf }
| 'Ù' { add_string "Ù"; next_char lexbuf }
| 'È' { add_string "È"; next_char lexbuf }
| 'ì' { add_string "ì"; next_char lexbuf }
| 'Ì' { add_string "Ì"; next_char lexbuf }
| 'â' { add_string "â"; next_char lexbuf }
| 'ô' { add_string "ô"; next_char lexbuf }
| 'û' { add_string "û"; next_char lexbuf }
| 'ê' { add_string "ê"; next_char lexbuf }
| 'î' { add_string "î"; next_char lexbuf }
| 'Â' { add_string "Â"; next_char lexbuf }
| 'Ô' { add_string "Ô"; next_char lexbuf }
| 'Û' { add_string "Û"; next_char lexbuf }
| 'Ê' { add_string "Ê"; next_char lexbuf }
| 'Î' { add_string "Î"; next_char lexbuf }
| _ { add lexbuf ; next_char lexbuf }
| eof { () }
(* called when we have seen "\\" *)
and control = parse
'"' { quote_char lexbuf }
| '\'' { right_accent lexbuf }
| '`' { left_accent lexbuf }
| '^' { hat lexbuf }
| "c{c}" { add_string "ç" ; next_char lexbuf }
| "c{C}" { add_string "Ç" ; next_char lexbuf }
| 'v' { czech lexbuf }
| 'u' { breve lexbuf }
| 'H' { hungarian lexbuf }
| '~' { tilde lexbuf }
| _ { add_string "\\" ; add lexbuf ; next_char lexbuf }
| eof { add_string "\\" }
(* called when we have seen "\\\"" *)
and quote_char = parse
('a'|"{a}") { add_string "ä" ; next_char lexbuf }
| ('o'|"{o}") { add_string "ö" ; next_char lexbuf }
| ('u'|"{u}") { add_string "ü" ; next_char lexbuf }
| ('e'|"{e}") { add_string "ë" ; next_char lexbuf }
| ('A'|"{A}") { add_string "Ä" ; next_char lexbuf }
| ('O'|"{O}") { add_string "Ö" ; next_char lexbuf }
| ('U'|"{U}") { add_string "Ü" ; next_char lexbuf }
| ('E'|"{E}") { add_string "Ë" ; next_char lexbuf }
| ('i'|"{i}"|"\\i" space*|"{\\i}")
{ add_string "ï" ; next_char lexbuf }
| ('I'|"{I}") { add_string "Ï" ; next_char lexbuf }
| _ { add_string "\\\"" ; add lexbuf }
| eof { add_string "\\\"" }
(* called when we have seen "\\'" *)
and right_accent = parse
| ('a'|"{a}") { add_string "á" ; next_char lexbuf }
| ('o'|"{o}") { add_string "ó" ; next_char lexbuf }
| ('u'|"{u}") { add_string "ú" ; next_char lexbuf }
| ('e'|"{e}") { add_string "é" ; next_char lexbuf }
| ('A'|"{A}") { add_string "Á" ; next_char lexbuf }
| ('O'|"{O}") { add_string "Ó" ; next_char lexbuf }
| ('U'|"{U}") { add_string "Ú" ; next_char lexbuf }
| ('E'|"{E}") { add_string "É" ; next_char lexbuf }
| ('\'') { add_string "”" ; next_char lexbuf }
| ('i'|"{i}"|"\\i" space*|"{\\i}")
{ add_string "í" ; next_char lexbuf }
| ('I'|"{I}") { add_string "Í" ; next_char lexbuf }
| _ { add_string "\\'" ; add lexbuf ; next_char lexbuf }
| eof { add_string "\\'" }
(* called when we have seen "\\`" *)
and left_accent = parse
('a'|"{a}") { add_string "à" ; next_char lexbuf }
| ('o'|"{o}") { add_string "ò" ; next_char lexbuf }
| ('u'|"{u}") { add_string "ù" ; next_char lexbuf }
| ('e'|"{e}") { add_string "è" ; next_char lexbuf }
| ('A'|"{A}") { add_string "À" ; next_char lexbuf }
| ('O'|"{O}") { add_string "Ò" ; next_char lexbuf }
| ('U'|"{U}") { add_string "Ù" ; next_char lexbuf }
| ('E'|"{E}") { add_string "È" ; next_char lexbuf }
| ('`') { add_string "“" ; next_char lexbuf }
| ('i'|"{i}"|"\\i" space* |"{\\i}")
{ add_string "ì" ; next_char lexbuf }
| ('I'|"{I}") { add_string "Ì" ; next_char lexbuf }
| _ { add_string "\\`" ; add lexbuf ; next_char lexbuf }
| eof { add_string "\\`" }
(* called when we have seen "\\^" *)
and hat = parse
('a'|"{a}") { add_string "â" ; next_char lexbuf }
| ('o'|"{o}") { add_string "ô" ; next_char lexbuf }
| ('u'|"{u}") { add_string "û" ; next_char lexbuf }
| ('e'|"{e}") { add_string "ê" ; next_char lexbuf }
| ('A'|"{A}") { add_string "Â" ; next_char lexbuf }
| ('O'|"{O}") { add_string "Ô" ; next_char lexbuf }
| ('U'|"{U}") { add_string "Û" ; next_char lexbuf }
| ('E'|"{E}") { add_string "Ê" ; next_char lexbuf }
| ('i'|"{i}"|"\\i" space* |"{\\i}")
{ add_string "î" ; next_char lexbuf }
| ('I'|"{I}") { add_string "Î" ; next_char lexbuf }
| _ { add_string "\\^" ; add lexbuf ; next_char lexbuf }
| eof { add_string "\\^" }
(* called when we have seen "\\~" *)
and tilde = parse
('a'|"{a}") { add_string "ã" ; next_char lexbuf }
| ('o'|"{o}") { add_string "õ" ; next_char lexbuf }
| ('A'|"{A}") { add_string "Ã" ; next_char lexbuf }
| ('O'|"{O}") { add_string "Õ" ; next_char lexbuf }
| ('n'|"{n}") { add_string "ñ" ; next_char lexbuf }
| ('N'|"{N}") { add_string "Ñ" ; next_char lexbuf }
| _ { add_string "\\~" ; add lexbuf ; next_char lexbuf }
| eof { add_string "\\~" }
(* called when we have seen "\\v" *)
and czech = parse
('r'|"{r}") { add_string "ř" ; next_char lexbuf }
| ('R'|"{R}") { add_string "Ř" ; next_char lexbuf }
| ('s'|"{s}") { add_string "š" ; next_char lexbuf }
| ('S'|"{S}") { add_string "Š" ; next_char lexbuf }
| ('i'|"{i}"|"\\i" space* |"{\\i}")
{ add_string "ĭ" ; next_char lexbuf }
| ('I'|"{I}") { add_string "Ĭ" ; next_char lexbuf }
| _ { add_string "\\^" ; add lexbuf ; next_char lexbuf }
| eof { add_string "\\^" }
(* called when we have seen "\\u" *)
and breve = parse
('a'|"{a}") { add_string "ă" ; next_char lexbuf }
| ('o'|"{o}") { add_string "ŏ" ; next_char lexbuf }
| ('u'|"{u}") { add_string "ŭ" ; next_char lexbuf }
| ('e'|"{e}") { add_string "ĕ" ; next_char lexbuf }
| ('A'|"{A}") { add_string "Ă" ; next_char lexbuf }
| ('O'|"{O}") { add_string "Ŏ" ; next_char lexbuf }
| ('U'|"{U}") { add_string "Ŭ" ; next_char lexbuf }
| ('E'|"{E}") { add_string "Ĕ" ; next_char lexbuf }
| ('i'|"{i}"|"\\i" space* |"{\\i}")
{ add_string "ĭ" ; next_char lexbuf }
| ('I'|"{I}") { add_string "Ĭ" ; next_char lexbuf }
| _ { add_string "\\u" ; add lexbuf ; next_char lexbuf }
| eof { add_string "\\u" }
(* called when we have seen "\\H" *)
and hungarian = parse
('o'|"{o}") { add_string "ő" ; next_char lexbuf }
| ('u'|"{u}") { add_string "ű" ; next_char lexbuf }
| ('O'|"{O}") { add_string "Ő" ; next_char lexbuf }
| ('U'|"{U}") { add_string "Ű" ; next_char lexbuf }
| _ { add_string "\\H" ; add lexbuf ; next_char lexbuf }
| eof { add_string "\\H" }
{
let normalize to_regexp s =
Buffer.clear string_buf;
produce_regexp := to_regexp;
next_char (Lexing.from_string s);
Buffer.contents string_buf
;;
}