Commit 64f7f18696aeb359f1dc2e7cf2c20bcd34b6d189

Thomas de Grivel 2018-06-29T04:53:54

specialize on css-lexer not lexer

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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
diff --git a/css-lexer.lisp b/css-lexer.lisp
index 4ca8bb7..9cf5a04 100644
--- a/css-lexer.lisp
+++ b/css-lexer.lisp
@@ -3,40 +3,40 @@
 
 (defclass css-lexer (lexer) ())
 
-(defgeneric comment-token (lexer))
-(defgeneric match-newline (lexer))
-(defgeneric match-whitespace (lexer))
-(defgeneric match-hex-digit (lexer))
-(defgeneric match-escape (lexer))
-(defgeneric whitespace-token (lexer))
-(defgeneric match-ws* (lexer))
-(defgeneric match-ident-char (lexer))
-(defgeneric match-ident-char* (lexer))
-(defgeneric ident-token (lexer))
-(defgeneric function-token (lexer))
-(defgeneric at-keyword-token (lexer))
-(defgeneric match-string-char (lexer end-char))
-(defgeneric match-string (lexer end-char))
-(defgeneric string-token (lexer))
-(defgeneric match-non-printable (lexer))
-(defgeneric match-url-unquoted-char (lexer))
-(defgeneric match-url-unquoted (lexer))
-(defgeneric url-token (lexer))
-(defgeneric match-digit (lexer))
-(defgeneric match-digit+ (lexer))
-(defgeneric number-token (lexer))
-(defgeneric dimension-token (lexer))
-(defgeneric percentage-token (lexer))
-(defgeneric unicode-range-token (lexer))
-(defgeneric include-match-token (lexer))
-(defgeneric dash-match-token (lexer))
-(defgeneric prefix-match-token (lexer))
-(defgeneric suffix-match-token (lexer))
-(defgeneric substring-match-token (lexer))
-(defgeneric column-token (lexer))
-(defgeneric cdo-token (lexer))
-(defgeneric cdc-token (lexer))
-(defgeneric consume-token (lexer))
+(defgeneric comment-token (css-lexer))
+(defgeneric match-newline (css-lexer))
+(defgeneric match-whitespace (css-lexer))
+(defgeneric match-hex-digit (css-lexer))
+(defgeneric match-escape (css-lexer))
+(defgeneric whitespace-token (css-lexer))
+(defgeneric match-ws* (css-lexer))
+(defgeneric match-ident-char (css-lexer))
+(defgeneric match-ident-char* (css-lexer))
+(defgeneric ident-token (css-lexer))
+(defgeneric function-token (css-lexer))
+(defgeneric at-keyword-token (css-lexer))
+(defgeneric match-string-char (css-lexer end-char))
+(defgeneric match-string (css-lexer end-char))
+(defgeneric string-token (css-lexer))
+(defgeneric match-non-printable (css-lexer))
+(defgeneric match-url-unquoted-char (css-lexer))
+(defgeneric match-url-unquoted (css-lexer))
+(defgeneric url-token (css-lexer))
+(defgeneric match-digit (css-lexer))
+(defgeneric match-digit+ (css-lexer))
+(defgeneric number-token (css-lexer))
+(defgeneric dimension-token (css-lexer))
+(defgeneric percentage-token (css-lexer))
+(defgeneric unicode-range-token (css-lexer))
+(defgeneric include-match-token (css-lexer))
+(defgeneric dash-match-token (css-lexer))
+(defgeneric prefix-match-token (css-lexer))
+(defgeneric suffix-match-token (css-lexer))
+(defgeneric substring-match-token (css-lexer))
+(defgeneric column-token (css-lexer))
+(defgeneric cdo-token (css-lexer))
+(defgeneric cdc-token (css-lexer))
+(defgeneric consume-token (css-lexer))
 
 (defclass css-token (token) ())
 (defclass printable (token) ())
@@ -89,7 +89,7 @@
 (defclass eof-token (css-token) ())
 (defclass delim-token (printable css-token) ())
 
-(defmethod comment-token ((lx lexer))
+(defmethod comment-token ((lx css-lexer))
   (push-token lx)
   (or (and (match lx "/*")
            (match-until lx "*/")
@@ -97,25 +97,25 @@
       (discard-token lx)))
 
 (let ((rn (coerce '(#\Return #\Newline) 'string)))
-  (defmethod match-newline ((lx lexer))
+  (defmethod match-newline ((lx css-lexer))
     (or (match lx #\Newline)
         (match lx rn)
         (match lx #\Return)
         (match lx #\Linefeed))))
 
-(defmethod match-whitespace ((lx lexer))
+(defmethod match-whitespace ((lx css-lexer))
   (or (match lx #\Space)
       (match lx #\Tab)
       (match-newline lx)))
 
-(defmethod match-hex-digit ((lx lexer))
+(defmethod match-hex-digit ((lx css-lexer))
   (let ((c (the fixnum (lexer-match-char lx 0))))
     (when (or (<= (char-code #\0) c (char-code #\9))
 	      (<= (char-code #\a) c (char-code #\f))
 	      (<= (char-code #\A) c (char-code #\F)))
       (incf (the fixnum (lexer-match-start lx))))))
        
-(defmethod match-escape ((lx lexer))
+(defmethod match-escape ((lx css-lexer))
   (match-sequence lx
     (and (match lx #\\)
 	 (or (when (match-times lx #'match-hex-digit 1 6)
@@ -124,16 +124,16 @@
 	     (when (not (match-newline lx))
 	       (lexer-match-start lx))))))
 
-(defmethod whitespace-token ((lx lexer))
+(defmethod whitespace-token ((lx css-lexer))
   (push-token lx)
   (if (match-times lx #'match-whitespace 1 nil)
       (make-token lx 'whitespace-token)
       (discard-token lx)))
 
-(defmethod match-ws* ((lx lexer))
+(defmethod match-ws* ((lx css-lexer))
   (match-option lx #'whitespace-token))
 
-(defmethod match-ident-char ((lx lexer))
+(defmethod match-ident-char ((lx css-lexer))
   (or (match-escape lx)
       (let ((c (the character (lexer-match-char lx 0))))
 	(when (or (char<= #\a c #\z)
@@ -144,10 +144,10 @@
 		  (<  #x007F (char-code c)))
 	  (incf (the fixnum (lexer-match-start lx)))))))
 
-(defmethod match-ident-char* ((lx lexer))
+(defmethod match-ident-char* ((lx css-lexer))
   (match-times lx #'match-ident-char 0 nil))
 
-(defmethod ident-token ((lx lexer))
+(defmethod ident-token ((lx css-lexer))
   (match-sequence lx
     (push-token lx)
     (match lx #\-)
@@ -163,7 +163,7 @@
 	  (t
 	   (discard-token lx)))))
 
-(defmethod function-token ((lx lexer))
+(defmethod function-token ((lx css-lexer))
   (match-sequence lx
     (push-token lx)
     (let ((ident (ident-token lx)))
@@ -171,7 +171,7 @@
 	  (make-token lx 'function-token :ident ident)
 	  (discard-token lx)))))
 
-(defmethod at-keyword-token ((lx lexer))
+(defmethod at-keyword-token ((lx css-lexer))
   (match-sequence lx
     (push-token lx)
     (if (match lx #\@)
@@ -181,7 +181,7 @@
 	      (discard-token lx)))
 	(discard-token lx))))
 
-(defmethod hash-token ((lx lexer))
+(defmethod hash-token ((lx css-lexer))
   (match-sequence lx
     (push-token lx)
     (if (match lx #\#)
@@ -196,7 +196,7 @@
     (declare (type (vector character) string))
     (subseq string 1 (1- (length string)))))
 
-(defmethod match-string-char ((lx lexer) (end-char character))
+(defmethod match-string-char ((lx css-lexer) (end-char character))
   (or (match-sequence lx
 	(and (match lx #\\)
 	     (match-newline lx)))
@@ -206,19 +206,19 @@
                           (match lx #\\)
                           (match-newline lx))))))
 
-(defmethod match-string ((lx lexer) (end-char character))
+(defmethod match-string ((lx css-lexer) (end-char character))
   (match-sequence lx
     (and (match lx end-char)
          (match-times lx (lambda (lx) (match-string-char lx end-char)) 0 nil)
          (match lx end-char))))
 
-(defmethod string-token ((lx lexer))
+(defmethod string-token ((lx css-lexer))
   (push-token lx)
   (if (or (match-string lx #\")
 	  (match-string lx #\'))
       (make-token lx 'string-token)))
 
-(defmethod match-non-printable ((lx lexer))
+(defmethod match-non-printable ((lx css-lexer))
   (let ((c (the fixnum (lexer-match-char lx 0))))
     (when (or (<= #x0000 c #x0008)
 	      (=  #x000B c)
@@ -226,7 +226,7 @@
 	      (=  #x007F c))
       (incf (the fixnum (lexer-match-start lx))))))
 
-(defmethod match-url-unquoted-char ((lx lexer))
+(defmethod match-url-unquoted-char ((lx css-lexer))
   (or (match-escape lx)
       (match-not lx
 	(or (match lx #\")
@@ -237,13 +237,13 @@
 	    (match-whitespace lx)
 	    (match-non-printable lx)))))
 
-(defmethod match-url-unquoted ((lx lexer))
+(defmethod match-url-unquoted ((lx css-lexer))
   (push-token lx)
   (if (match-times lx #'match-url-unquoted-char 1 nil)
       (make-token lx 'token)
       (discard-token lx)))
 
-(defmethod url-token ((lx lexer))
+(defmethod url-token ((lx css-lexer))
   (push-token lx)
   (or (match-sequence lx
 	(let ((ident (ident-token lx)))
@@ -258,15 +258,15 @@
 		   (make-token lx 'url-token :ident ident :url url))))))
       (discard-token lx)))
 
-(defmethod match-digit ((lx lexer))
+(defmethod match-digit ((lx css-lexer))
   (let ((c (the character (lexer-match-char lx 0))))
     (when (char<= #\0 c #\9)
       (incf (the fixnum (lexer-match-start lx))))))
 
-(defmethod match-digit+ ((lx lexer))
+(defmethod match-digit+ ((lx css-lexer))
   (match-times lx #'match-digit 1 nil))
 
-(defmethod number-token ((lx lexer))
+(defmethod number-token ((lx css-lexer))
   (push-token lx)
   (if (match-sequence lx
 	(and (or (match lx #\-)
@@ -291,7 +291,7 @@
       (make-token lx 'number-token)
       (discard-token lx)))
 
-(defmethod dimension-token ((lx lexer))
+(defmethod dimension-token ((lx css-lexer))
   (push-token lx)
   (or (match-sequence lx
 	(let ((number (number-token lx)))
@@ -303,7 +303,7 @@
 			    :ident ident))))))
       (discard-token lx)))
 
-(defmethod percentage-token ((lx lexer))
+(defmethod percentage-token ((lx css-lexer))
   (push-token lx)
   (or (match-sequence lx
 	(let ((number (number-token lx)))
@@ -313,7 +313,7 @@
 			  :number number)))))
       (discard-token lx)))
 
-(defmethod unicode-range-token ((lx lexer))
+(defmethod unicode-range-token ((lx css-lexer))
   (push-token lx)
   (or (match-sequence lx
 	(and (or (match lx #\u)
@@ -336,109 +336,109 @@
 	     (make-token lx 'unicode-range-token)))
       (discard-token lx)))
 
-(defmethod include-match-token ((lx lexer))
+(defmethod include-match-token ((lx css-lexer))
   (push-token lx)
   (if (match lx "~=")
       (make-token lx 'include-match-token)
       (discard-token lx)))
 
-(defmethod dash-match-token ((lx lexer))
+(defmethod dash-match-token ((lx css-lexer))
   (push-token lx)
   (if (match lx "|=")
       (make-token lx 'dash-match-token)
       (discard-token lx)))
 
-(defmethod prefix-match-token ((lx lexer))
+(defmethod prefix-match-token ((lx css-lexer))
   (push-token lx)
   (if (match lx "^=")
       (make-token lx 'prefix-match-token)
       (discard-token lx)))
 
-(defmethod suffix-match-token ((lx lexer))
+(defmethod suffix-match-token ((lx css-lexer))
   (push-token lx)
   (if (match lx "$=")
       (make-token lx 'suffix-match-token)
       (discard-token lx)))
 
-(defmethod substring-match-token ((lx lexer))
+(defmethod substring-match-token ((lx css-lexer))
   (push-token lx)
   (if (match lx "*=")
       (make-token lx 'substring-match-token)
       (discard-token lx)))
 
-(defmethod column-token ((lx lexer))
+(defmethod column-token ((lx css-lexer))
   (push-token lx)
   (if (match lx "||")
       (make-token lx 'column-token)
       (discard-token lx)))
 
-(defmethod cdo-token ((lx lexer))
+(defmethod cdo-token ((lx css-lexer))
   (push-token lx)
   (if (match lx "<!--")
       (make-token lx 'cdo-token)
       (discard-token lx)))
 
-(defmethod cdc-token ((lx lexer))
+(defmethod cdc-token ((lx css-lexer))
   (push-token lx)
   (if (match lx "-->")
       (make-token lx 'cdc-token)
       (discard-token lx)))
 
-(defmethod left-paren-token ((lx lexer))
+(defmethod left-paren-token ((lx css-lexer))
   (push-token lx)
   (if (match lx #\()
       (make-token lx 'left-paren-token)
       (discard-token lx)))
 
-(defmethod right-paren-token ((lx lexer))
+(defmethod right-paren-token ((lx css-lexer))
   (push-token lx)
   (if (match lx #\))
       (make-token lx 'right-paren-token)
       (discard-token lx)))
 
-(defmethod comma-token ((lx lexer))
+(defmethod comma-token ((lx css-lexer))
   (push-token lx)
   (if (match lx #\,)
       (make-token lx 'comma-token)
       (discard-token lx)))
 
-(defmethod colon-token ((lx lexer))
+(defmethod colon-token ((lx css-lexer))
   (push-token lx)
   (if (match lx #\:)
       (make-token lx 'colon-token)
       (discard-token lx)))
 
-(defmethod semicolon-token ((lx lexer))
+(defmethod semicolon-token ((lx css-lexer))
   (push-token lx)
   (if (match lx #\;)
       (make-token lx 'semicolon-token)
       (discard-token lx)))
 
-(defmethod [-token ((lx lexer))
+(defmethod [-token ((lx css-lexer))
   (push-token lx)
   (if (match lx #\[)
       (make-token lx '[-token)
       (discard-token lx)))
 
-(defmethod ]-token ((lx lexer))
+(defmethod ]-token ((lx css-lexer))
   (push-token lx)
   (if (match lx #\])
       (make-token lx ']-token)
       (discard-token lx)))
 
-(defmethod {-token ((lx lexer))
+(defmethod {-token ((lx css-lexer))
   (push-token lx)
   (if (match lx #\{)
       (make-token lx '{-token)
       (discard-token lx)))
 
-(defmethod }-token ((lx lexer))
+(defmethod }-token ((lx css-lexer))
   (push-token lx)
   (if (match lx #\})
       (make-token lx '}-token)
       (discard-token lx)))
 
-(defmethod eof-token ((lx lexer))
+(defmethod eof-token ((lx css-lexer))
   (unless (lexer-input-n lx 1)
     (push-token lx)
     (cond ((and (lexer-input-ended lx)
@@ -449,7 +449,7 @@
           (t
            (discard-token lx)))))
 
-(defmethod delim-token ((lx lexer))
+(defmethod delim-token ((lx css-lexer))
   (push-token lx)
   (lexer-input-n lx 1)
   (incf (the fixnum (lexer-match-start lx)))