-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconstants.lisp
363 lines (333 loc) · 12.2 KB
/
constants.lisp
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
;;;; HTML5 parser for Common Lisp
;;;;
;;;; Copyright (C) 2012 Thomas Bakketun <thomas.bakketun@copyleft.no>
;;;; Copyright (C) 2012 Asgeir Bjørlykke <asgeir@copyleft.no>
;;;; Copyright (C) 2012 Mathias Hellevang
;;;; Copyright (C) 2012 Stian Sletner <stian@copyleft.no>
;;;;
;;;; This library is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU Lesser General Public License as published
;;;; by the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This library 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 for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this library. If not, see <http://www.gnu.org/licenses/>.
(in-package :html5-constants)
(defmacro defglobal (name value &optional docstring)
(let ((docstring (and docstring (list docstring))))
;; SBCL evaluates the init value of a global at compile time.
#+sbcl `(progn (sb-ext:defglobal ,name nil ,@docstring)
(setq ,name ,value)
',name)
#+ccl `(ccl:defstatic ,name ,value ,@docstring)
#-(or sbcl ccl) `(defparameter ,name ,value ,@docstring)))
(defglobal +namespaces+
'(("html" . "http://www.w3.org/1999/xhtml")
("mathml" ."http://www.w3.org/1998/Math/MathML")
("svg" . "http://www.w3.org/2000/svg")
("xlink" . "http://www.w3.org/1999/xlink")
("xml" . "http://www.w3.org/XML/1998/namespace")
("xmlns" . "http://www.w3.org/2000/xmlns/")))
(defun find-namespace (prefix)
(cdr (assoc prefix +namespaces+ :test #'string=)))
(defun find-prefix (namespace)
(car (find namespace +namespaces+ :test #'string= :key #'cdr)))
(defglobal +scoping-elements+
`((,(find-namespace "html") . "applet")
(,(find-namespace "html") . "caption")
(,(find-namespace "html") . "html")
(,(find-namespace "html") . "marquee")
(,(find-namespace "html") . "object")
(,(find-namespace "html") . "table")
(,(find-namespace "html") . "td")
(,(find-namespace "html") . "th")
(,(find-namespace "mathml") . "mi")
(,(find-namespace "mathml") . "mo")
(,(find-namespace "mathml") . "mn")
(,(find-namespace "mathml") . "ms")
(,(find-namespace "mathml") . "mtext")
(,(find-namespace "mathml") . "annotation-xml")
(,(find-namespace "svg") . "foreignObject")
(,(find-namespace "svg") . "desc")
(,(find-namespace "svg") . "title")))
(defglobal +formatting-elements+
`((,(find-namespace "html") . "a")
(,(find-namespace "html") . "b")
(,(find-namespace "html") . "big")
(,(find-namespace "html") . "code")
(,(find-namespace "html") . "em")
(,(find-namespace "html") . "font")
(,(find-namespace "html") . "i")
(,(find-namespace "html") . "nobr")
(,(find-namespace "html") . "s")
(,(find-namespace "html") . "small")
(,(find-namespace "html") . "strike")
(,(find-namespace "html") . "strong")
(,(find-namespace "html") . "tt")
(,(find-namespace "html") . "u")))
(defglobal +special-elements+
`((,(find-namespace "html") . "address")
(,(find-namespace "html") . "applet")
(,(find-namespace "html") . "area")
(,(find-namespace "html") . "article")
(,(find-namespace "html") . "aside")
(,(find-namespace "html") . "base")
(,(find-namespace "html") . "basefont")
(,(find-namespace "html") . "bgsound")
(,(find-namespace "html") . "blockquote")
(,(find-namespace "html") . "body")
(,(find-namespace "html") . "br")
(,(find-namespace "html") . "button")
(,(find-namespace "html") . "caption")
(,(find-namespace "html") . "center")
(,(find-namespace "html") . "col")
(,(find-namespace "html") . "colgroup")
(,(find-namespace "html") . "command")
(,(find-namespace "html") . "dd")
(,(find-namespace "html") . "details")
(,(find-namespace "html") . "dir")
(,(find-namespace "html") . "div")
(,(find-namespace "html") . "dl")
(,(find-namespace "html") . "dt")
(,(find-namespace "html") . "embed")
(,(find-namespace "html") . "fieldset")
(,(find-namespace "html") . "figure")
(,(find-namespace "html") . "footer")
(,(find-namespace "html") . "form")
(,(find-namespace "html") . "frame")
(,(find-namespace "html") . "frameset")
(,(find-namespace "html") . "h1")
(,(find-namespace "html") . "h2")
(,(find-namespace "html") . "h3")
(,(find-namespace "html") . "h4")
(,(find-namespace "html") . "h5")
(,(find-namespace "html") . "h6")
(,(find-namespace "html") . "head")
(,(find-namespace "html") . "header")
(,(find-namespace "html") . "hr")
(,(find-namespace "html") . "html")
(,(find-namespace "html") . "iframe")
;; Note that image is commented out in the spec as "this isn't an
;; element that can end up on the stack, so it doesn't matter,"
(,(find-namespace "html") . "image")
(,(find-namespace "html") . "img")
(,(find-namespace "html") . "input")
(,(find-namespace "html") . "isindex")
(,(find-namespace "html") . "li")
(,(find-namespace "html") . "link")
(,(find-namespace "html") . "listing")
(,(find-namespace "html") . "marquee")
(,(find-namespace "html") . "menu")
(,(find-namespace "html") . "meta")
(,(find-namespace "html") . "nav")
(,(find-namespace "html") . "noembed")
(,(find-namespace "html") . "noframes")
(,(find-namespace "html") . "noscript")
(,(find-namespace "html") . "object")
(,(find-namespace "html") . "ol")
(,(find-namespace "html") . "p")
(,(find-namespace "html") . "param")
(,(find-namespace "html") . "plaintext")
(,(find-namespace "html") . "pre")
(,(find-namespace "html") . "script")
(,(find-namespace "html") . "section")
(,(find-namespace "html") . "select")
(,(find-namespace "html") . "style")
(,(find-namespace "html") . "table")
(,(find-namespace "html") . "tbody")
(,(find-namespace "html") . "td")
(,(find-namespace "html") . "textarea")
(,(find-namespace "html") . "tfoot")
(,(find-namespace "html") . "th")
(,(find-namespace "html") . "thead")
(,(find-namespace "html") . "title")
(,(find-namespace "html") . "tr")
(,(find-namespace "html") . "ul")
(,(find-namespace "html") . "wbr")
(,(find-namespace "html") . "xmp")
(,(find-namespace "svg") . "foreignObject")))
(defglobal +html-integration-point-elements+
`((,(find-namespace "mathml") . "annotation-xml")
(,(find-namespace "svg") . "foreignObject")
(,(find-namespace "svg") . "desc")
(,(find-namespace "svg") . "title")))
(defglobal +mathml-text-integration-point-elements+
`((,(find-namespace "mathml") . "mi")
(,(find-namespace "mathml") . "mo")
(,(find-namespace "mathml") . "mn")
(,(find-namespace "mathml") . "ms")
(,(find-namespace "mathml") . "mtext")))
(defconstant +eof+ '+eof+)
(defglobal +token-types+
'(:doctype 0
:characters 1
:space-characters 2
:star-ttag 3
:end-tag 4
:empty-tag 5
:comment 6
:parse-error 7))
(defglobal +tag-token-types+
'(:start-tag :end-tag :empty-tag))
(defglobal +space-characters+
'(#\Tab
#\Newline
#\u000C
#\Space
#\Return))
(defglobal +table-insert-mode-elements+
'("table"
"tbody"
"tfoot"
"thead"
"tr"))
(defglobal +ascii-lowercase+ "abcdefghijklmnopqrstuvwxyz")
(defglobal +ascii-uppercase+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
(defglobal +ascii-letters+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
(defglobal +digits+ "0123456789")
(defglobal +hex-digits+ "0123456789abcdefABCDEF")
(defun ascii-letter-p (c)
(when (characterp c)
(let ((code (char-code c)))
(or (<= #.(char-code #\a) code #.(char-code #\z))
(<= #.(char-code #\A) code #.(char-code #\Z))))))
(defun ascii-upper-2-lower (string)
(let ((out (copy-seq string)))
(dotimes (i (length string))
(let ((p (position (char out i) +ascii-uppercase+)))
(when p
(setf (char out i) (char +ascii-lowercase+ p)))))
out))
(defglobal +replacement-characters+
'(#x0 #\uFFFD
#x0d #\u000D
#x80 #\u20AC
#x81 #\u0081
#x81 #\u0081
#x82 #\u201A
#x83 #\u0192
#x84 #\u201E
#x85 #\u2026
#x86 #\u2020
#x87 #\u2021
#x88 #\u02C6
#x89 #\u2030
#x8A #\u0160
#x8B #\u2039
#x8C #\u0152
#x8D #\u008D
#x8E #\u017D
#x8F #\u008F
#x90 #\u0090
#x91 #\u2018
#x92 #\u2019
#x93 #\u201C
#x94 #\u201D
#x95 #\u2022
#x96 #\u2013
#x97 #\u2014
#x98 #\u02DC
#x99 #\u2122
#x9A #\u0161
#x9B #\u203A
#x9C #\u0153
#x9D #\u009D
#x9E #\u017E
#x9F #\u0178))
(defglobal +cdata-elements+
'("title"
"textarea"))
(defglobal +rcdata-elements+
'("style"
"script"
"xmp"
"iframe"
"noembed"
"noframes"
"noscript"))
(defglobal +html-integration-point-elements+
`((,(find-namespace "mathml") . "annotation-xml")
(,(find-namespace "svg") . "foreignObject")
(,(find-namespace "svg") . "desc")
(,(find-namespace "svg") . "title")))
(defglobal +mathml-text-integration-point-elements+
`((,(find-namespace "mathml") . "mi")
(,(find-namespace "mathml") . "mo")
(,(find-namespace "mathml") . "mn")
(,(find-namespace "mathml") . "ms")
(,(find-namespace "mathml") . "mtext")))
(defun make-hash-lookup (replacements)
(let ((rhash (make-hash-table :test #'equalp)))
(loop for (from to) in replacements
do (setf (gethash from rhash) to))))
(defglobal +quirks-mode-doctypes-regexp+
(cl-ppcre:create-scanner
'(:sequence :start-anchor
(:alternation
"+//silmaril//dtd html pro v0r11 19970101//"
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//"
"-//as//dtd html 3.0 aswedit + extensions//"
"-//ietf//dtd html 2.0 level 1//"
"-//ietf//dtd html 2.0 level 2//"
"-//ietf//dtd html 2.0 strict level 1//"
"-//ietf//dtd html 2.0 strict level 2//"
"-//ietf//dtd html 2.0 strict//"
"-//ietf//dtd html 2.0//"
"-//ietf//dtd html 2.1e//"
"-//ietf//dtd html 3.0//"
"-//ietf//dtd html 3.2 final//"
"-//ietf//dtd html 3.2//"
"-//ietf//dtd html 3//"
"-//ietf//dtd html level 0//"
"-//ietf//dtd html level 1//"
"-//ietf//dtd html level 2//"
"-//ietf//dtd html level 3//"
"-//ietf//dtd html strict level 0//"
"-//ietf//dtd html strict level 1//"
"-//ietf//dtd html strict level 2//"
"-//ietf//dtd html strict level 3//"
"-//ietf//dtd html strict//"
"-//ietf//dtd html//"
"-//metrius//dtd metrius presentational//"
"-//microsoft//dtd internet explorer 2.0 html strict//"
"-//microsoft//dtd internet explorer 2.0 html//"
"-//microsoft//dtd internet explorer 2.0 tables//"
"-//microsoft//dtd internet explorer 3.0 html strict//"
"-//microsoft//dtd internet explorer 3.0 html//"
"-//microsoft//dtd internet explorer 3.0 tables//"
"-//netscape comm. corp.//dtd html//"
"-//netscape comm. corp.//dtd strict html//"
"-//o'reilly and associates//dtd html 2.0//"
"-//o'reilly and associates//dtd html extended 1.0//"
"-//o'reilly and associates//dtd html extended relaxed 1.0//"
"-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//"
"-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//"
"-//spyglass//dtd html 2.0 extended//"
"-//sq//dtd html 2.0 hotmetal + extensions//"
"-//sun microsystems corp.//dtd hotjava html//"
"-//sun microsystems corp.//dtd hotjava strict html//"
"-//w3c//dtd html 3 1995-03-24//"
"-//w3c//dtd html 3.2 draft//"
"-//w3c//dtd html 3.2 final//"
"-//w3c//dtd html 3.2//"
"-//w3c//dtd html 3.2s draft//"
"-//w3c//dtd html 4.0 frameset//"
"-//w3c//dtd html 4.0 transitional//"
"-//w3c//dtd html experimental 19960712//"
"-//w3c//dtd html experimental 970421//"
"-//w3c//dtd w3 html//"
"-//w3o//dtd w3 html 3.0//"
"-//webtechs//dtd mozilla html 2.0//"
"-//webtechs//dtd mozilla html//"))))
(defglobal +heading-elements+
'("h1"
"h2"
"h3"
"h4"
"h5"
"h6"))