-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathhtml5-tok.el
3436 lines (3296 loc) · 150 KB
/
html5-tok.el
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; html5-tok.el --- HTML Tokenizer
;; Copyright (C) 2010 Edward O'Connor
;; Author: Edward O'Connor <[email protected]>
;; Keywords: wp, hypermedia, comm, languages
;; Permission is hereby granted, free of charge, to any person obtaining
;; a copy of this software and associated documentation files (the
;; "Software"), to deal in the Software without restriction, including
;; without limitation the rights to use, copy, modify, merge, publish,
;; distribute, sublicense, and/or sell copies of the Software, and to
;; permit persons to whom the Software is furnished to do so, subject to
;; the following conditions:
;; The above copyright notice and this permission notice shall be
;; included in all copies or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;; Commentary:
;;
;;; History:
;;
;;; Code:
(require 'html5-ncr)
(defvar *h5-curtok* nil)
(defvar *h5-curattr* nil)
(defvar *h5-additional-allowed-character* nil)
(defvar *h5-last-tag-open* nil)
(defvar html5-tok-coalesce-character-tokens nil
"If nil, the tokenizer emits each character token separately.
If non-nil, it collects character tokens and emits strings of
consecutive ones.")
(defun h5-inside (thing)
"Mark the text from the last tag open state as a THING."
(when *h5-last-tag-open*
(put-text-property *h5-last-tag-open* (point)
'h5-inside thing))
(setq *h5-last-tag-open* nil))
;; (defvar h5-charbuf nil)
;; (defvar h5-charbuf-nonempty nil)
;; (defun h5-clear-charbuf ()
;; ""
;; (let (contents)
;; (unless (bufferp h5-charbuf)
;; (setq h5-charbuf (get-buffer-create " *h5-chars*")))
;; (with-current-buffer h5-charbuf
;; (setq contents
;; (buffer-substring-no-properties (point-min) (point-max)))
;; (delete-region (point-min) (point-max)))
;; contents))
;; (defun h5-append-to-charbuf (val)
;; ""
;; (with-current-buffer h5-charbuf
;; (insert val)))
(defun h5-parse-error (&optional reason)
""
(let ((here (point)))
(put-text-property (1- here) here 'h5-parse-error (or reason t)))
(h5-emit :parse-error))
(defsubst h5-space-p (str)
""
(and (stringp str)
(string-match "[\t\n\f ]" str)))
(defsubst h5-uppercase-p (str)
""
(and (stringp str)
(string-match "[A-Z]" str)))
(defsubst h5-lowercase-p (str)
""
(and (stringp str)
(string-match "[a-z]" str)))
(defun h5-consume-the-next-input-character ()
""
(condition-case nil
(progn
(forward-char 1)
(char-before))
(end-of-buffer
:eof)))
;; <h4><dfn>Tokenization</dfn></h4>
;;
;; Implementations must act as if they used the following state machine
;; to tokenize HTML.
(defvar *h5-curstate* nil)
(defvar *h5-prevstate* nil)
(defvar *h5-statestart* 1)
(defun h5-switch-state (state)
""
(when (eq state :previous)
(setq state *h5-prevstate*))
;; (message "STATE [[[%s]]]->[[[%s]]] at %d" *h5-curstate* state (point))
(when *h5-curstate*
(put-text-property *h5-statestart* (point)
'h5-state *h5-curstate*))
(setq *h5-prevstate* *h5-curstate*)
(setq *h5-curstate* state)
(setq *h5-statestart* (point)))
(defun h5-current-state ()
""
*h5-curstate*)
;; Most states consume a single character, which may have
;; various side-effects, and either switches the state machine to a new
;; state to <em>reconsume</em> the same character, or switches it to a
;; new state (to consume the next character), or repeats the same state
;; (to consume the next character). Some states have more complicated
;; behavior and can consume several characters before switching to
;; another state. In some cases, the tokenizer state is also changed by
;; the tree construction stage.
;;
;; The exact behavior of certain states depends on the <span>insertion
;; mode</span> and the <span>stack of open elements</span>.
(defvar h5-insertion-mode nil)
(defvar h5-stack-of-open-elements nil)
;; Certain states also use a <dfn><var>temporary buffer</var></dfn> to
;; track progress.
(defvar h5-tmpbuf nil)
(defun h5-clear-tmpbuf ()
""
(unless (bufferp h5-tmpbuf)
(setq h5-tmpbuf (get-buffer-create " *h5-tmp*")))
(with-current-buffer h5-tmpbuf
(delete-region (point-min) (point-max))))
(defun h5-append-to-tmpbuf (val)
""
(with-current-buffer h5-tmpbuf
(insert val)))
(defun h5-tmpbuf ()
""
(with-current-buffer h5-tmpbuf
(buffer-substring (point-min) (point-max))))
(defun h5-emit-tmpbuf ()
""
(h5-emit-string
(with-current-buffer h5-tmpbuf
(buffer-substring-no-properties (point-min) (point-max)))))
;; The output of the tokenization step is a series of zero or more of
;; the following tokens: DOCTYPE, start tag, end tag, comment,
;; character, end-of-file.
(defstruct h5-doctype-token
;; DOCTYPE tokens have a name, a public identifier, a system
;; identifier, and a <i>force-quirks flag</i>.
;; When a DOCTYPE token is created, its name, public identifier, and
;; system identifier must be marked as missing (which is a distinct
;; state from the empty string),
(name 'missing :type string)
(public-id 'missing :type string)
(system-id 'missing :type string)
;; and the <i>force-quirks flag</i> must be set to <i>off</i> (its
;; other state is <i>on</i>).
(force-quirks nil :type boolean))
;; and a list of attributes, each of which has a name and a value.
(defstruct h5-attr
(name "" :type string)
(value "" :type string)
;; internal to html5-tok.el
(duplicate nil :type boolean))
(defstruct h5-tag-token
;; Start and end tag tokens have a tag name,
(name "" :type string)
;; When a start or end tag token is created, its <i>self-closing
;; flag</i> must be unset (its other state is that it be set),
(self-closing nil :type boolean)
;; and its attributes list must be empty.
(attributes nil :type list))
(defstruct (h5-start-tag-token (:include h5-tag-token)))
(defstruct (h5-end-tag-token (:include h5-tag-token)))
;; Comment and character tokens have data.
(defstruct h5-comment-token
(data "" :type string))
;; (defun h5-emit-charbuf ()
;; ""
;; (let ((str (h5-clear-charbuf)))
;; (when (> (length str) 0)
;; (h5-emit str))))
(defun h5-emit (&optional token)
""
(unless token
(setq token *h5-curtok*))
(when token
(when (eq token *h5-curtok*)
(setq *h5-curtok* nil)
(setq *h5-curattr* nil))
;; We don't immediately emit character tokens, but accumulate them
;; for emitting en mass.
;; (when (and (not (numberp token))
;; (not (stringp token))
;; h5-charbuf-nonempty)
;; (h5-emit-charbuf))
(cond ((eq token :parse-error)
(throw 'h5-emit :parse-error))
((h5-start-tag-token-p token)
(h5-inside 'start-tag)
(setq h5-last-start-tag-emitted token)
;; When a start tag token is emitted with its <i>self-closing
;; flag</i> set, if the flag is not <dfn title="acknowledge
;; self-closing flag">acknowledged</dfn> when it is processed
;; by the tree construction stage, that is a <span>parse
;; error</span>.
(throw 'h5-emit token))
((h5-end-tag-token-p token)
(h5-inside 'end-tag)
;; When an end tag token is emitted with attributes, that is
;; a <span>parse error</span>.
(when (h5-tag-token-attributes token)
(h5-parse-error))
;; When an end tag token is emitted with its <i>self-closing
;; flag</i> set, that is a <span>parse error</span>.
(when (h5-tag-token-self-closing token)
(h5-parse-error))
(throw 'h5-emit token))
((h5-comment-token-p token)
(h5-inside 'comment)
(throw 'h5-emit token))
((h5-doctype-token-p token)
(h5-inside 'doctype)
(throw 'h5-emit token))
((eq token :eof)
(throw 'h5-emit :eof))
((numberp token)
;; (setq h5-charbuf-nonempty t)
;; (h5-append-to-charbuf token)
(throw 'h5-emit token)
)
(t
(throw 'h5-emit token)))))
(defun h5-emit-string (str)
""
(dolist (char (string-to-list str))
(h5-emit char)))
(defvar h5-last-start-tag-emitted nil)
;; An <dfn>appropriate end tag token</dfn> is an end tag token whose tag
;; name matches the tag name of the last start tag to have been emitted
;; from this tokenizer, if any.
(defun h5-appropriate-end-tag-token (tok)
""
(if h5-last-start-tag-emitted
(equal (h5-tag-token-name h5-last-start-tag-emitted)
(h5-tag-token-name tok))
;; If no start tag has been emitted from this tokenizer, then no end
;; tag token is appropriate.
nil))
;; Before each step of the tokenizer, the user agent must first check
;; the <span>parser pause flag</span>. If it is true, then the tokenizer
;; must abort the processing of any nested invocations of the tokenizer,
;; yielding control back to the caller.
(defun h5-data-state ()
""
;; Consume the <span>next input character</span>:
(let ((char (h5-consume-the-next-input-character)))
(cond ((eq char ?&) ;; <dt>U+0026 AMPERSAND (&)</dt>
;; <dd>Switch to the <span>character reference in data
;; state</span>.</dd>
(h5-switch-state
'h5-character-reference-in-data-state))
((eq char ?<) ;; <dt>U+003C LESS-THAN SIGN (<)</dt>
;; <dd>Switch to the <span>tag open state</span>.</dd>
(h5-switch-state 'h5-tag-open-state))
((eq char :eof) ;; <dt>EOF</dt>
;; <dd>Emit an end-of-file token.</dd>
(h5-emit :eof))
(t ;; <dt>Anything else</dt>
;; <dd>Emit the <span>current input character</span> as a
;; character token.</dd>
(h5-emit char)))))
(defun h5-character-reference-in-data-state ()
""
(let ((attempt
;; Attempt to <span>consume a character reference</span>,
;; with no <span>additional allowed character</span>.
(let ((*h5-additional-allowed-character* nil))
(h5-consume-a-character-reference))))
(cond ((eq attempt nil) ;; If nothing is returned,
;; emit a U+0026 AMPERSAND character (&) token.
(h5-emit ?&))
(t ;; Otherwise,
;; emit the character token that was returned.
(h5-emit attempt))))
;; Finally, switch to the <span>data state</span>.
(h5-switch-state 'h5-data-state))
(defun h5-RCDATA-state ()
""
;; Consume the <span>next input character</span>:
(let ((char (h5-consume-the-next-input-character)))
(cond ((eq char ?&) ;; <dt>U+0026 AMPERSAND (&)</dt>
;; <dd>Switch to the <span>character reference in RCDATA
;; state</span>.</dd>
(h5-switch-state
'h5-character-reference-in-RCDATA-state))
((eq char ?<) ;; <dt>U+003C LESS-THAN SIGN (<)</dt>
;; <dd>Switch to the <span>RCDATA less-than sign
;; state</span>.</dd>
(h5-switch-state 'h5-RCDATA-less-than-sign-state))
((eq char :eof) ;; <dt>EOF</dt>
;; <dd>Emit an end-of-file token.</dd>
(h5-emit :eof))
(t ;; <dt>Anything else</dt>
;; <dd>Emit the <span>current input character</span> as a
;; character token.</dd>
(h5-emit char)))))
(defun h5-character-reference-in-RCDATA-state ()
""
(let ((attempt
;; Attempt to <span>consume a character reference</span>,
;; with no <span>additional allowed character</span>.
(let ((*h5-additional-allowed-character* nil))
(h5-consume-a-character-reference))))
(cond ((eq attempt nil) ;; If nothing is returned,
;; emit a U+0026 AMPERSAND character (&) token.
(h5-emit ?&))
(t ;; Otherwise,
;; emit the character token that was returned.
(h5-emit attempt))))
;; Finally, switch to the <span>RCDATA state</span>.
(h5-switch-state 'h5-RCDATA-state))
(defun h5-RAWTEXT-state ()
""
;; Consume the <span>next input character</span>:
(let ((char (h5-consume-the-next-input-character)))
(cond ((eq char ?<) ;; <dt>U+003C LESS-THAN SIGN (<)</dt>
;; <dd>Switch to the <span>RAWTEXT less-than sign
;; state</span>.</dd>
(h5-switch-state 'h5-RAWTEXT-less-than-sign-state))
((eq char :eof) ;; <dt>EOF</dt>
;; <dd>Emit an end-of-file token.</dd>
(h5-emit :eof))
(t ;; <dt>Anything else</dt>
;; <dd>Emit the <span>current input character</span> as a
;; character token.</dd>
(h5-emit char)))))
(defun h5-script-data-state ()
""
;; Consume the <span>next input character</span>:
(let ((char (h5-consume-the-next-input-character)))
(cond ((eq char ?<) ;; <dt>U+003C LESS-THAN SIGN (<)</dt>
;; <dd>Switch to the <span>script data less-than sign
;; state</span>.</dd>
(h5-switch-state 'h5-script-data-less-than-sign-state))
((eq char :eof) ;; <dt>EOF</dt>
;; <dd>Emit an end-of-file token.</dd>
(h5-emit :eof))
(t ;; <dt>Anything else</dt>
;; <dd>Emit the <span>current input character</span> as a
;; character token.</dd>
(h5-emit char)))))
(defun h5-PLAINTEXT-state ()
""
;; Consume the <span>next input character</span>:
(let ((char (h5-consume-the-next-input-character)))
(cond ((eq char :eof) ;; <dt>EOF</dt>
;; <dd>Emit an end-of-file token.</dd>
(h5-emit :eof))
(t ;; <dt>Anything else</dt>
;; <dd>Emit the <span>current input character</span> as a
;; character token.</dd>
(h5-emit char)))))
(defun h5-tag-open-state ()
""
(setq *h5-last-tag-open* (1- (point)))
;; Consume the <span>next input character</span>:
(let* ((char (h5-consume-the-next-input-character))
(case-fold-search nil)
(char-str (if (numberp char) (string char) char)))
(cond ((eq char ?!) ;; <dt>U+0021 EXCLAMATION MARK (!)</dt>
;; (h5-emit-charbuf)
;; <dd>Switch to the <span>markup declaration open
;; state</span>.</dd>
(h5-switch-state 'h5-markup-declaration-open-state))
((eq char ?/) ;; <dt>U+002F SOLIDUS (/)</dt>
;; (h5-emit-charbuf)
;; <dd>Switch to the <span>end tag open state</span>.</dd>
(h5-switch-state 'h5-end-tag-open-state))
(;; <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN
;; CAPITAL LETTER Z</dt>
(h5-uppercase-p char-str)
;; (h5-emit-charbuf)
(setq *h5-curtok*
;; <dd>Create a new start tag token,
(make-h5-start-tag-token
;; set its tag name to the lowercase version of the
;; <span>current input character</span> (add 0x0020 to the
;; character's code point),
:name (downcase char-str)))
;; then switch to the <span>tag name state</span>.
(h5-switch-state 'h5-tag-name-state))
(;; <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN
;; SMALL LETTER Z</dt>
(h5-lowercase-p char-str)
;; (h5-emit-charbuf)
(setq *h5-curtok*
;; <dd>Create a new start tag token,
(make-h5-start-tag-token
;; set its tag name to the <span>current input
;; character</span>,
:name char-str))
;; then switch to the <span>tag name state</span>.
(h5-switch-state 'h5-tag-name-state))
((eq char ??) ;; <dt>U+003F QUESTION MARK (?)</dt>
;; (h5-emit-charbuf)
;; <dd><span>Parse error</span>.
(h5-parse-error)
;; Switch to the <span>bogus comment state</span>.</dd>
(h5-switch-state 'h5-bogus-comment-state))
(t ;; <dt>Anything else</dt>
;; <dd><span>Parse error</span>.
(h5-parse-error)
;; Emit a U+003C LESS-THAN SIGN character token
(h5-emit ?<)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>data state</span>.</dd>
(h5-switch-state 'h5-data-state)))))
(defun h5-end-tag-open-state ()
""
;; Consume the <span>next input character</span>:
(let* ((case-fold-search nil)
(char (h5-consume-the-next-input-character))
(char-str (if (numberp char) (string char) char)))
(cond (;; <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN
;; CAPITAL LETTER Z</dt>
(h5-uppercase-p char-str)
(setq *h5-curtok*
;; <dd>Create a new end tag token,
(make-h5-end-tag-token
;; set its tag name to the lowercase version of the
;; <span>current input character</span> (add 0x0020 to the
;; character's code point),
:name (downcase char-str)))
;; then switch to the <span>tag name state</span>.
(h5-switch-state 'h5-tag-name-state))
(;; <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN
;; SMALL LETTER Z</dt>
(h5-lowercase-p char-str)
(setq *h5-curtok*
;; <dd>Create a new end tag token,
(make-h5-end-tag-token
;; set its tag name to the <span>current input
;; character</span>,
:name char-str))
;; then switch to the <span>tag name state</span>.
(h5-switch-state 'h5-tag-name-state))
((eq char ?>) ;; <dt>U+003E GREATER-THAN SIGN (>)</dt>
;; <dd><span>Parse error</span>.
(h5-parse-error)
;; Switch to the <span>data state</span>.</dd>
(h5-switch-state 'h5-data-state))
((eq char :eof) ;; <dt>EOF</dt>
;; <dd><span>Parse error</span>.
(h5-parse-error)
;; Emit a U+003C LESS-THAN SIGN character token
(h5-emit ?<)
;; and a U+002F SOLIDUS character token.
(h5-emit ?/)
;; Reconsume the EOF character
(backward-char 1)
;; in the <span>data state</span>.</dd>
(h5-switch-state 'h5-data-state))
(t ;; <dt>Anything else</dt>
;; <dd><span>Parse error</span>.
(h5-parse-error)
;; Switch to the <span>bogus comment state</span>.</dd>
(h5-switch-state 'h5-bogus-comment-state)))))
(defun h5-tag-name-state () ;; <dfn>Tag name state</dfn>
""
;; Consume the <span>next input character</span>:
(let* ((case-fold-search nil)
(char (h5-consume-the-next-input-character))
(char-str (if (numberp char) (string char) char))
(tok *h5-curtok*))
(cond (;; <dt>U+0009 CHARACTER TABULATION</dt>
;; <dt>U+000A LINE FEED (LF)</dt>
;; <dt>U+000C FORM FEED (FF)</dt>
;; <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
;; <dt>U+0020 SPACE</dt>
(h5-space-p char-str)
;; <dd>Switch to the <span>before attribute name
;; state</span>.</dd>
(h5-switch-state 'h5-before-attribute-name-state))
((eq char ?/) ;; <dt>U+002F SOLIDUS (/)</dt>
;; <dd>Switch to the <span>self-closing start tag
;; state</span>.</dd>
(h5-switch-state 'h5-self-closing-start-tag-state))
((eq char ?>) ;; <dt>U+003E GREATER-THAN SIGN (>)</dt>
;; <dd>Switch to the <span>data state</span>.
(h5-switch-state 'h5-data-state)
;; Emit the current tag token.</dd>
(h5-emit))
(;; <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN
;; CAPITAL LETTER Z</dt>
(h5-uppercase-p char-str)
;; <dd>Append the lowercase version of the <span>current
;; input character</span> (add 0x0020 to the character's code
;; point) to the current tag token's tag name.</dd>
(setf (h5-tag-token-name tok)
(concat (h5-tag-token-name tok)
(downcase char-str))))
((eq char :eof) ;; <dt>EOF</dt>
;; <dd><span>Parse error</span>.
(h5-parse-error)
;; Reconsume the EOF character
(backward-char 1)
;; in the <span>data state</span>.</dd>
(h5-switch-state 'h5-data-state))
(t ;; <dt>Anything else</dt>
;; <dd>Append the <span>current input character</span> to the
;; current tag token's tag name.</dd>
(setf (h5-tag-token-name tok)
(concat (h5-tag-token-name tok)
char-str))))))
(defun h5-RCDATA-less-than-sign-state ()
""
;; <!-- identical to the RAWTEXT less-than sign state, except s/RAWTEXT/RCDATA/g -->
;; Consume the <span>next input character</span>:
(let ((char (h5-consume-the-next-input-character)))
(cond ((eq char ?/) ;; <dt>U+002F SOLIDUS (/)</dt>
;; <dd>Set the <var>temporary buffer</var> to the empty string.
(h5-clear-tmpbuf)
;; Switch to the <span>RCDATA end tag open state</span>.</dd>
(h5-switch-state 'h5-RCDATA-end-tag-open-state))
(t ;; <dt>Anything else</dt>
;; <dd>Emit a U+003C LESS-THAN SIGN character token
(h5-emit ?<)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>RCDATA state</span>.</dd>
(h5-switch-state 'h5-RCDATA-state)))))
(defun h5-RCDATA-end-tag-open-state ()
""
;; <!-- identical to the RAWTEXT (and Script data) end tag open state, except s/RAWTEXT/RCDATA/g -->
;; Consume the <span>next input character</span>:
(let* ((case-fold-search nil)
(char (h5-consume-the-next-input-character))
(char-str (if (numberp char) (string char) char)))
(cond (;; <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN
;; CAPITAL LETTER Z</dt>
(h5-uppercase-p char-str)
(setq *h5-curtok*
;; <dd>Create a new end tag token,
(make-h5-end-tag-token
;; and set its tag name to the lowercase version of the
;; <span>current input character</span> (add 0x0020 to the
;; character's code point).
:name (downcase char-str)))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.
(h5-append-to-tmpbuf char-str)
;; Finally, switch to the <span>RCDATA end tag name
;; state</span>.
(h5-switch-state 'h5-RCDATA-end-tag-name-state))
(;; <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN
;; SMALL LETTER Z</dt>
(h5-lowercase-p char-str)
(setq *h5-curtok*
;; <dd>Create a new end tag token,
(make-h5-end-tag-token
;; and set its tag name to the <span>current input
;; character</span>.
:name char-str))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.
(h5-append-to-tmpbuf char-str)
;; Finally, switch to the <span>RCDATA end tag name
;; state</span>.
(h5-switch-state 'h5-RCDATA-end-tag-name-state))
(t ;; <dt>Anything else</dt>
;; <dd>Emit a U+003C LESS-THAN SIGN character token,
(h5-emit ?<)
;; a U+002F SOLIDUS character token,
(h5-emit ?/)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>RCDATA state</span>.</dd>
(h5-switch-state 'h5-RCDATA-state)))))
(defun h5-RCDATA-end-tag-name-state ()
""
;; <!-- identical to the RAWTEXT (and Script data) end tag name state, except s/RAWTEXT/RCDATA/g -->
;; Consume the <span>next input character</span>:
(let* ((case-fold-search nil)
(char (h5-consume-the-next-input-character))
(char-str (if (numberp char) (string char) char))
(tok *h5-curtok*)
(anything-else
(lambda ()
;; <dd>Emit a U+003C LESS-THAN SIGN character token,
(h5-emit ?<)
;; a U+002F SOLIDUS character token,
(h5-emit ?/)
;; a character token for each of the characters in the
;; <var>temporary buffer</var> (in the order they were added
;; to the buffer),
(h5-emit-tmpbuf)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>RCDATA state</span>.</dd>
(h5-switch-state 'h5-RCDATA-state))))
(cond (;; <dt>U+0009 CHARACTER TABULATION</dt>
;; <dt>U+000A LINE FEED (LF)</dt>
;; <dt>U+000C FORM FEED (FF)</dt>
;; <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
;; <dt>U+0020 SPACE</dt>
(h5-space-p char-str)
;; <dd>If the current end tag token is an <span>appropriate
;; end tag token</span>,
(if (h5-appropriate-end-tag-token tok)
;; then switch to the <span>before attribute name
;; state</span>.
(h5-switch-state 'h5-before-attribute-name-state)
;; Otherwise, treat it as per the "anything else" entry
;; below.</dd>
(funcall anything-else)))
((eq char ?/) ;; <dt>U+002F SOLIDUS (/)</dt>
;; <dd>If the current end tag token is an <span>appropriate
;; end tag token</span>,
(if (h5-appropriate-end-tag-token tok)
;; then switch to the <span>self-closing start tag
;; state</span>.
(h5-switch-state 'h5-self-closing-start-tag-state)
;; Otherwise, treat it as per the "anything else" entry
;; below.</dd>
(funcall anything-else)))
((eq char ?>) ;; <dt>U+003E GREATER-THAN SIGN (>)</dt>
;; <dd>If the current end tag token is an <span>appropriate
;; end tag token</span>,
(if (h5-appropriate-end-tag-token tok)
(progn
;; then emit the current tag token
(h5-emit tok)
;; and switch to the <span>data state</span>.
(h5-switch-state 'h5-data-state))
;; Otherwise, treat it as per the "anything else" entry
;; below.</dd>
(funcall anything-else)))
(;; <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN
;; CAPITAL LETTER Z</dt>
(h5-uppercase-p char-str)
;; <dd>Append the lowercase version of the <span>current
;; input character</span> (add 0x0020 to the character's code
;; point) to the current tag token's tag name.
(setf (h5-tag-token-name tok)
(concat (h5-tag-token-name tok)
(downcase char-str)))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.</dd>
(h5-append-to-tmpbuf char-str))
(;; <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN
;; SMALL LETTER Z</dt>
(h5-lowercase-p char-str)
;; <dd>Append the <span>current input character</span> to the
;; current tag token's tag name.
(setf (h5-tag-token-name tok)
(concat (h5-tag-token-name tok)
char-str))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.</dd>
(h5-append-to-tmpbuf char-str))
(t ;; <dt>Anything else</dt>
(funcall anything-else)))))
(defun h5-RAWTEXT-less-than-sign-state ()
""
;; <!-- identical to the RCDATA less-than sign state, except s/RCDATA/RAWTEXT/g -->
;; Consume the <span>next input character</span>:
(let ((char (h5-consume-the-next-input-character)))
(cond ((eq char ?/) ;; <dt>U+002F SOLIDUS (/)</dt>
;; <dd>Set the <var>temporary buffer</var> to the empty
;; string.
(h5-clear-tmpbuf)
;; Switch to the <span>RAWTEXT end tag open
;; state</span>.</dd>
(h5-switch-state 'h5-RAWTEXT-end-tag-open-state))
(t ;; <dt>Anything else</dt>
;; <dd>Emit a U+003C LESS-THAN SIGN character token
(h5-emit ?<)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>RAWTEXT state</span>.</dd>
(h5-switch-state 'h5-RAWTEXT-state)))))
(defun h5-RAWTEXT-end-tag-open-state ()
""
;; <!-- identical to the RCDATA (and Script data) end tag open state, except s/RCDATA/RAWTEXT/g -->
;; Consume the <span>next input character</span>:
(let* ((case-fold-search nil)
(char (h5-consume-the-next-input-character))
(char-str (if (numberp char) (string char) char)))
(cond (;; <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN
;; CAPITAL LETTER Z</dt>
(h5-uppercase-p char-str)
(setq *h5-curtok*
;; <dd>Create a new end tag token,
(make-h5-end-tag-token
;; and set its tag name to the lowercase version of the
;; <span>current input character</span> (add 0x0020 to the
;; character's code point).
:name (downcase char-str)))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.
(h5-append-to-tmpbuf char-str)
;; Finally, switch to the <span>RAWTEXT end tag name
;; state</span>.
(h5-switch-state 'h5-RAWTEXT-end-tag-name-state))
(;; <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN
;; SMALL LETTER Z</dt>
(h5-lowercase-p char-str)
(setq *h5-curtok*
;; <dd>Create a new end tag token,
(make-h5-end-tag-token
;; and set its tag name to the <span>current input
;; character</span>.
:name char-str))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.
(h5-append-to-tmpbuf char-str)
;; Finally, switch to the <span>RAWTEXT end tag name
;; state</span>.
(h5-switch-state 'h5-RAWTEXT-end-tag-name-state))
(t ;; <dt>Anything else</dt>
;; <dd>Emit a U+003C LESS-THAN SIGN character token,
(h5-emit ?<)
;; a U+002F SOLIDUS character token,
(h5-emit ?/)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>RAWTEXT state</span>.</dd>
(h5-switch-state 'h5-RAWTEXT-state)))))
(defun h5-RAWTEXT-end-tag-name-state ()
""
;; <!-- identical to the RCDATA (and Script data) end tag name state, except s/RCDATA/RAWTEXT/g -->
;; Consume the <span>next input character</span>:
(let* ((case-fold-search nil)
(char (h5-consume-the-next-input-character))
(char-str (if (numberp char) (string char) char))
(tok *h5-curtok*)
(anything-else
(lambda ()
;; <dd>Emit a U+003C LESS-THAN SIGN character token,
(h5-emit ?<)
;; a U+002F SOLIDUS character token,
(h5-emit ?/)
;; a character token for each of the characters in the
;; <var>temporary buffer</var> (in the order they were added
;; to the buffer),
(h5-emit-tmpbuf)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>RAWTEXT state</span>.</dd>
(h5-switch-state 'h5-RAWTEXT-state))))
(cond (;; <dt>U+0009 CHARACTER TABULATION</dt>
;; <dt>U+000A LINE FEED (LF)</dt>
;; <dt>U+000C FORM FEED (FF)</dt>
;; <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
;; <dt>U+0020 SPACE</dt>
(h5-space-p char-str)
;; <dd>If the current end tag token is an <span>appropriate
;; end tag token</span>,
(if (h5-appropriate-end-tag-token tok)
;; then switch to the <span>before attribute name
;; state</span>.
(h5-switch-state 'h5-before-attribute-name-state)
;; Otherwise, treat it as per the "anything else" entry
;; below.</dd>
(funcall anything-else)))
((eq char ?/) ;; <dt>U+002F SOLIDUS (/)</dt>
;; <dd>If the current end tag token is an <span>appropriate
;; end tag token</span>,
(if (h5-appropriate-end-tag-token tok)
;; then switch to the <span>self-closing start tag
;; state</span>.
(h5-switch-state 'h5-self-closing-start-tag-state)
;; Otherwise, treat it as per the "anything else" entry
;; below.</dd>
(funcall anything-else)))
((eq char ?>) ;; <dt>U+003E GREATER-THAN SIGN (>)</dt>
;; <dd>If the current end tag token is an <span>appropriate
;; end tag token</span>,
(if (h5-appropriate-end-tag-token tok)
(progn
;; then emit the current tag token
(h5-emit)
;; and switch to the <span>data state</span>.
(h5-switch-state 'h5-data-state))
;; Otherwise, treat it as per the "anything else" entry
;; below.</dd>
(funcall anything-else)))
(;; <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN
;; CAPITAL LETTER Z</dt>
(h5-uppercase-p char-str)
;; <dd>Append the lowercase version of the <span>current
;; input character</span> (add 0x0020 to the character's code
;; point) to the current tag token's tag name.
(setf (h5-tag-token-name tok)
(concat (h5-tag-token-name tok)
(downcase char-str)))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.</dd>
(h5-append-to-tmpbuf char-str))
(;; <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN
;; SMALL LETTER Z</dt>
(h5-lowercase-p char-str)
;; <dd>Append the <span>current input character</span> to the
;; current tag token's tag name.
(setf (h5-tag-token-name tok)
(concat (h5-tag-token-name tok)
char-str))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.</dd>
(h5-append-to-tmpbuf char-str))
(t ;; <dt>Anything else</dt>
(funcall anything-else)))))
(defun h5-script-data-less-than-sign-state ()
""
;; Consume the <span>next input character</span>:
(let* ((case-fold-search nil)
(char (h5-consume-the-next-input-character))
(char-str (if (numberp char) (string char) char)))
(cond ((eq char ?/) ;; <dt>U+002F SOLIDUS (/)</dt>
;; <dd>Set the <var>temporary buffer</var> to the empty
;; string.
(h5-clear-tmpbuf)
;; Switch to the <span>script data end tag open
;; state</span>.</dd>
(h5-switch-state 'h5-script-data-end-tag-open-state))
((eq char ?!) ;; <dt>U+0021 EXCLAMATION MARK (!)</dt>
;; <dd>Switch to the <span>script data escape start
;; state</span>.
(h5-switch-state 'h5-script-data-escape-start-state)
;; Emit a U+003C LESS-THAN SIGN character token
(h5-emit ?<)
;; and a U+0021 EXCLAMATION MARK character token.</dd>
(h5-emit ?!))
(t ;; <dt>Anything else</dt>
;; <dd>Emit a U+003C LESS-THAN SIGN character token
(h5-emit ?<)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>script data state</span>.</dd>
(h5-switch-state 'h5-script-data-state)))))
(defun h5-script-data-end-tag-open-state ()
""
;; <!-- identical to the RCDATA (and RAWTEXT) end tag open state, except s/RCDATA/Script data/g -->
;; Consume the <span>next input character</span>:
(let* ((case-fold-search nil)
(char (h5-consume-the-next-input-character))
(char-str (if (numberp char) (string char) char)))
(cond (;; <dt>U+0041 LATIN CAPITAL LETTER A through to U+005A LATIN
;; CAPITAL LETTER Z</dt>
(h5-uppercase-p char-str)
(setq *h5-curtok*
;; <dd>Create a new end tag token,
(make-h5-end-tag-token
;; and set its tag name to the lowercase version of the
;; <span>current input character</span> (add 0x0020 to the
;; character's code point).
:name (downcase char-str)))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.
(h5-append-to-tmpbuf char-str)
;; Finally, switch to the <span>script data end tag name
;; state</span>.
(h5-switch-state 'h5-script-data-end-tag-name-state))
(;; <dt>U+0061 LATIN SMALL LETTER A through to U+007A LATIN
;; SMALL LETTER Z</dt>
(h5-lowercase-p char-str)
(setq *h5-curtok*
;; <dd>Create a new end tag token,
(make-h5-end-tag-token
;; and set its tag name to the <span>current input
;; character</span>.
:name char-str))
;; Append the <span>current input character</span> to the
;; <var>temporary buffer</var>.
(h5-append-to-tmpbuf char-str)
;; Finally, switch to the <span>script data end tag name
;; state</span>.
(h5-switch-state 'h5-script-data-end-tag-name-state))
(t ;; <dt>Anything else</dt>
;; <dd>Emit a U+003C LESS-THAN SIGN character token,
(h5-emit ?<)
;; a U+002F SOLIDUS character token,
(h5-emit ?/)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>script data state</span>.</dd>
(h5-switch-state 'h5-script-data-state)))))
(defun h5-script-data-end-tag-name-state ()
""
;; <!-- identical to the RCDATA (and RAWTEXT) end tag name state, except s/RCDATA/Script data/g -->
;; Consume the <span>next input character</span>:
(let* ((case-fold-search nil)
(char (h5-consume-the-next-input-character))
(char-str (if (numberp char) (string char) char))
(tok *h5-curtok*)
(anything-else
(lambda ()
;; <dd>Emit a U+003C LESS-THAN SIGN character token,
(h5-emit ?<)
;; a U+002F SOLIDUS character token,
(h5-emit ?/)
;; a character token for each of the characters in the
;; <var>temporary buffer</var> (in the order they were added
;; to the buffer),
(h5-emit-tmpbuf)
;; and reconsume the <span>current input character</span>
(backward-char 1)
;; in the <span>script data state</span>.</dd>
(h5-switch-state 'h5-script-data-state))))
(cond (;; <dt>U+0009 CHARACTER TABULATION</dt>
;; <dt>U+000A LINE FEED (LF)</dt>
;; <dt>U+000C FORM FEED (FF)</dt>
;; <!--<dt>U+000D CARRIAGE RETURN (CR)</dt>-->
;; <dt>U+0020 SPACE</dt>
(h5-space-p char-str)
;; <dd>If the current end tag token is an <span>appropriate
;; end tag token</span>,
(if (h5-appropriate-end-tag-token tok)
;; then switch to the <span>before attribute name
;; state</span>.
(h5-switch-state 'h5-before-attribute-name-state)
;; Otherwise, treat it as per the "anything else" entry
;; below.</dd>
(funcall anything-else)))
((eq char ?/) ;; <dt>U+002F SOLIDUS (/)</dt> <dd>If the
;; current end tag token is an <span>appropriate end tag
;; token</span>,
(if (h5-appropriate-end-tag-token tok)
;; then switch to the <span>self-closing start tag
;; state</span>.
(h5-switch-state 'h5-self-closing-start-tag-state)
;; Otherwise, treat it as per the "anything else" entry
;; below.</dd>