| 2 |
use strict; |
use strict; |
| 3 |
our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
our $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 4 |
|
|
| 5 |
## This is an early version of an HTML parser. |
## ISSUE: |
| 6 |
|
## var doc = implementation.createDocument (null, null, null); |
| 7 |
|
## doc.write (''); |
| 8 |
|
## alert (doc.compatMode); |
| 9 |
|
|
| 10 |
my $permitted_slash_tag_name = { |
my $permitted_slash_tag_name = { |
| 11 |
base => 1, |
base => 1, |
| 21 |
input => 1, |
input => 1, |
| 22 |
}; |
}; |
| 23 |
|
|
|
my $entity_char = { |
|
|
AElig => "\x{00C6}", |
|
|
Aacute => "\x{00C1}", |
|
|
Acirc => "\x{00C2}", |
|
|
Agrave => "\x{00C0}", |
|
|
Alpha => "\x{0391}", |
|
|
Aring => "\x{00C5}", |
|
|
Atilde => "\x{00C3}", |
|
|
Auml => "\x{00C4}", |
|
|
Beta => "\x{0392}", |
|
|
Ccedil => "\x{00C7}", |
|
|
Chi => "\x{03A7}", |
|
|
Dagger => "\x{2021}", |
|
|
Delta => "\x{0394}", |
|
|
ETH => "\x{00D0}", |
|
|
Eacute => "\x{00C9}", |
|
|
Ecirc => "\x{00CA}", |
|
|
Egrave => "\x{00C8}", |
|
|
Epsilon => "\x{0395}", |
|
|
Eta => "\x{0397}", |
|
|
Euml => "\x{00CB}", |
|
|
Gamma => "\x{0393}", |
|
|
Iacute => "\x{00CD}", |
|
|
Icirc => "\x{00CE}", |
|
|
Igrave => "\x{00CC}", |
|
|
Iota => "\x{0399}", |
|
|
Iuml => "\x{00CF}", |
|
|
Kappa => "\x{039A}", |
|
|
Lambda => "\x{039B}", |
|
|
Mu => "\x{039C}", |
|
|
Ntilde => "\x{00D1}", |
|
|
Nu => "\x{039D}", |
|
|
OElig => "\x{0152}", |
|
|
Oacute => "\x{00D3}", |
|
|
Ocirc => "\x{00D4}", |
|
|
Ograve => "\x{00D2}", |
|
|
Omega => "\x{03A9}", |
|
|
Omicron => "\x{039F}", |
|
|
Oslash => "\x{00D8}", |
|
|
Otilde => "\x{00D5}", |
|
|
Ouml => "\x{00D6}", |
|
|
Phi => "\x{03A6}", |
|
|
Pi => "\x{03A0}", |
|
|
Prime => "\x{2033}", |
|
|
Psi => "\x{03A8}", |
|
|
Rho => "\x{03A1}", |
|
|
Scaron => "\x{0160}", |
|
|
Sigma => "\x{03A3}", |
|
|
THORN => "\x{00DE}", |
|
|
Tau => "\x{03A4}", |
|
|
Theta => "\x{0398}", |
|
|
Uacute => "\x{00DA}", |
|
|
Ucirc => "\x{00DB}", |
|
|
Ugrave => "\x{00D9}", |
|
|
Upsilon => "\x{03A5}", |
|
|
Uuml => "\x{00DC}", |
|
|
Xi => "\x{039E}", |
|
|
Yacute => "\x{00DD}", |
|
|
Yuml => "\x{0178}", |
|
|
Zeta => "\x{0396}", |
|
|
aacute => "\x{00E1}", |
|
|
acirc => "\x{00E2}", |
|
|
acute => "\x{00B4}", |
|
|
aelig => "\x{00E6}", |
|
|
agrave => "\x{00E0}", |
|
|
alefsym => "\x{2135}", |
|
|
alpha => "\x{03B1}", |
|
|
amp => "\x{0026}", |
|
|
AMP => "\x{0026}", |
|
|
and => "\x{2227}", |
|
|
ang => "\x{2220}", |
|
|
apos => "\x{0027}", |
|
|
aring => "\x{00E5}", |
|
|
asymp => "\x{2248}", |
|
|
atilde => "\x{00E3}", |
|
|
auml => "\x{00E4}", |
|
|
bdquo => "\x{201E}", |
|
|
beta => "\x{03B2}", |
|
|
brvbar => "\x{00A6}", |
|
|
bull => "\x{2022}", |
|
|
cap => "\x{2229}", |
|
|
ccedil => "\x{00E7}", |
|
|
cedil => "\x{00B8}", |
|
|
cent => "\x{00A2}", |
|
|
chi => "\x{03C7}", |
|
|
circ => "\x{02C6}", |
|
|
clubs => "\x{2663}", |
|
|
cong => "\x{2245}", |
|
|
copy => "\x{00A9}", |
|
|
COPY => "\x{00A9}", |
|
|
crarr => "\x{21B5}", |
|
|
cup => "\x{222A}", |
|
|
curren => "\x{00A4}", |
|
|
dArr => "\x{21D3}", |
|
|
dagger => "\x{2020}", |
|
|
darr => "\x{2193}", |
|
|
deg => "\x{00B0}", |
|
|
delta => "\x{03B4}", |
|
|
diams => "\x{2666}", |
|
|
divide => "\x{00F7}", |
|
|
eacute => "\x{00E9}", |
|
|
ecirc => "\x{00EA}", |
|
|
egrave => "\x{00E8}", |
|
|
empty => "\x{2205}", |
|
|
emsp => "\x{2003}", |
|
|
ensp => "\x{2002}", |
|
|
epsilon => "\x{03B5}", |
|
|
equiv => "\x{2261}", |
|
|
eta => "\x{03B7}", |
|
|
eth => "\x{00F0}", |
|
|
euml => "\x{00EB}", |
|
|
euro => "\x{20AC}", |
|
|
exist => "\x{2203}", |
|
|
fnof => "\x{0192}", |
|
|
forall => "\x{2200}", |
|
|
frac12 => "\x{00BD}", |
|
|
frac14 => "\x{00BC}", |
|
|
frac34 => "\x{00BE}", |
|
|
frasl => "\x{2044}", |
|
|
gamma => "\x{03B3}", |
|
|
ge => "\x{2265}", |
|
|
gt => "\x{003E}", |
|
|
GT => "\x{003E}", |
|
|
hArr => "\x{21D4}", |
|
|
harr => "\x{2194}", |
|
|
hearts => "\x{2665}", |
|
|
hellip => "\x{2026}", |
|
|
iacute => "\x{00ED}", |
|
|
icirc => "\x{00EE}", |
|
|
iexcl => "\x{00A1}", |
|
|
igrave => "\x{00EC}", |
|
|
image => "\x{2111}", |
|
|
infin => "\x{221E}", |
|
|
int => "\x{222B}", |
|
|
iota => "\x{03B9}", |
|
|
iquest => "\x{00BF}", |
|
|
isin => "\x{2208}", |
|
|
iuml => "\x{00EF}", |
|
|
kappa => "\x{03BA}", |
|
|
lArr => "\x{21D0}", |
|
|
lambda => "\x{03BB}", |
|
|
lang => "\x{2329}", |
|
|
laquo => "\x{00AB}", |
|
|
larr => "\x{2190}", |
|
|
lceil => "\x{2308}", |
|
|
ldquo => "\x{201C}", |
|
|
le => "\x{2264}", |
|
|
lfloor => "\x{230A}", |
|
|
lowast => "\x{2217}", |
|
|
loz => "\x{25CA}", |
|
|
lrm => "\x{200E}", |
|
|
lsaquo => "\x{2039}", |
|
|
lsquo => "\x{2018}", |
|
|
lt => "\x{003C}", |
|
|
LT => "\x{003C}", |
|
|
macr => "\x{00AF}", |
|
|
mdash => "\x{2014}", |
|
|
micro => "\x{00B5}", |
|
|
middot => "\x{00B7}", |
|
|
minus => "\x{2212}", |
|
|
mu => "\x{03BC}", |
|
|
nabla => "\x{2207}", |
|
|
nbsp => "\x{00A0}", |
|
|
ndash => "\x{2013}", |
|
|
ne => "\x{2260}", |
|
|
ni => "\x{220B}", |
|
|
not => "\x{00AC}", |
|
|
notin => "\x{2209}", |
|
|
nsub => "\x{2284}", |
|
|
ntilde => "\x{00F1}", |
|
|
nu => "\x{03BD}", |
|
|
oacute => "\x{00F3}", |
|
|
ocirc => "\x{00F4}", |
|
|
oelig => "\x{0153}", |
|
|
ograve => "\x{00F2}", |
|
|
oline => "\x{203E}", |
|
|
omega => "\x{03C9}", |
|
|
omicron => "\x{03BF}", |
|
|
oplus => "\x{2295}", |
|
|
or => "\x{2228}", |
|
|
ordf => "\x{00AA}", |
|
|
ordm => "\x{00BA}", |
|
|
oslash => "\x{00F8}", |
|
|
otilde => "\x{00F5}", |
|
|
otimes => "\x{2297}", |
|
|
ouml => "\x{00F6}", |
|
|
para => "\x{00B6}", |
|
|
part => "\x{2202}", |
|
|
permil => "\x{2030}", |
|
|
perp => "\x{22A5}", |
|
|
phi => "\x{03C6}", |
|
|
pi => "\x{03C0}", |
|
|
piv => "\x{03D6}", |
|
|
plusmn => "\x{00B1}", |
|
|
pound => "\x{00A3}", |
|
|
prime => "\x{2032}", |
|
|
prod => "\x{220F}", |
|
|
prop => "\x{221D}", |
|
|
psi => "\x{03C8}", |
|
|
quot => "\x{0022}", |
|
|
QUOT => "\x{0022}", |
|
|
rArr => "\x{21D2}", |
|
|
radic => "\x{221A}", |
|
|
rang => "\x{232A}", |
|
|
raquo => "\x{00BB}", |
|
|
rarr => "\x{2192}", |
|
|
rceil => "\x{2309}", |
|
|
rdquo => "\x{201D}", |
|
|
real => "\x{211C}", |
|
|
reg => "\x{00AE}", |
|
|
REG => "\x{00AE}", |
|
|
rfloor => "\x{230B}", |
|
|
rho => "\x{03C1}", |
|
|
rlm => "\x{200F}", |
|
|
rsaquo => "\x{203A}", |
|
|
rsquo => "\x{2019}", |
|
|
sbquo => "\x{201A}", |
|
|
scaron => "\x{0161}", |
|
|
sdot => "\x{22C5}", |
|
|
sect => "\x{00A7}", |
|
|
shy => "\x{00AD}", |
|
|
sigma => "\x{03C3}", |
|
|
sigmaf => "\x{03C2}", |
|
|
sim => "\x{223C}", |
|
|
spades => "\x{2660}", |
|
|
sub => "\x{2282}", |
|
|
sube => "\x{2286}", |
|
|
sum => "\x{2211}", |
|
|
sup => "\x{2283}", |
|
|
sup1 => "\x{00B9}", |
|
|
sup2 => "\x{00B2}", |
|
|
sup3 => "\x{00B3}", |
|
|
supe => "\x{2287}", |
|
|
szlig => "\x{00DF}", |
|
|
tau => "\x{03C4}", |
|
|
there4 => "\x{2234}", |
|
|
theta => "\x{03B8}", |
|
|
thetasym => "\x{03D1}", |
|
|
thinsp => "\x{2009}", |
|
|
thorn => "\x{00FE}", |
|
|
tilde => "\x{02DC}", |
|
|
times => "\x{00D7}", |
|
|
trade => "\x{2122}", |
|
|
uArr => "\x{21D1}", |
|
|
uacute => "\x{00FA}", |
|
|
uarr => "\x{2191}", |
|
|
ucirc => "\x{00FB}", |
|
|
ugrave => "\x{00F9}", |
|
|
uml => "\x{00A8}", |
|
|
upsih => "\x{03D2}", |
|
|
upsilon => "\x{03C5}", |
|
|
uuml => "\x{00FC}", |
|
|
weierp => "\x{2118}", |
|
|
xi => "\x{03BE}", |
|
|
yacute => "\x{00FD}", |
|
|
yen => "\x{00A5}", |
|
|
yuml => "\x{00FF}", |
|
|
zeta => "\x{03B6}", |
|
|
zwj => "\x{200D}", |
|
|
zwnj => "\x{200C}", |
|
|
}; # $entity_char |
|
|
|
|
| 24 |
my $c1_entity_char = { |
my $c1_entity_char = { |
| 25 |
0x80 => 0x20AC, |
0x80 => 0x20AC, |
| 26 |
0x81 => 0xFFFD, |
0x81 => 0xFFFD, |
| 102 |
$line++; |
$line++; |
| 103 |
$column = 0; |
$column = 0; |
| 104 |
} elsif ($self->{next_input_character} == 0x000D) { # CR |
} elsif ($self->{next_input_character} == 0x000D) { # CR |
| 105 |
if ($i >= length $$s) { |
$i++ if substr ($$s, $i, 1) eq "\x0A"; |
|
# |
|
|
} else { |
|
|
my $next_char = ord substr $$s, $i++, 1; |
|
|
if ($next_char == 0x000A) { # LF |
|
|
# |
|
|
} else { |
|
|
push @{$self->{char}}, $next_char; |
|
|
} |
|
|
} |
|
| 106 |
$self->{next_input_character} = 0x000A; # LF # MUST |
$self->{next_input_character} = 0x000A; # LF # MUST |
| 107 |
$line++; |
$line++; |
| 108 |
$column = 0; |
$column = 0; |
| 158 |
# $self->{next_input_character} |
# $self->{next_input_character} |
| 159 |
!!!next-input-character; |
!!!next-input-character; |
| 160 |
$self->{token} = []; |
$self->{token} = []; |
| 161 |
|
# $self->{escape} |
| 162 |
} # _initialize_tokenizer |
} # _initialize_tokenizer |
| 163 |
|
|
| 164 |
## A token has: |
## A token has: |
| 165 |
## ->{type} eq 'DOCTYPE', 'start tag', 'end tag', 'comment', |
## ->{type} eq 'DOCTYPE', 'start tag', 'end tag', 'comment', |
| 166 |
## 'character', or 'end-of-file' |
## 'character', or 'end-of-file' |
| 167 |
## ->{name} (DOCTYPE, start tag (tagname), end tag (tagname)) |
## ->{name} (DOCTYPE, start tag (tag name), end tag (tag name)) |
| 168 |
## ISSUE: the spec need s/tagname/tag name/ |
## ->{public_identifier} (DOCTYPE) |
| 169 |
## ->{error} == 1 or 0 (DOCTYPE) |
## ->{system_identifier} (DOCTYPE) |
| 170 |
|
## ->{correct} == 1 or 0 (DOCTYPE) |
| 171 |
## ->{attributes} isa HASH (start tag, end tag) |
## ->{attributes} isa HASH (start tag, end tag) |
| 172 |
## ->{data} (comment, character) |
## ->{data} (comment, character) |
| 173 |
|
|
|
## Macros |
|
|
## Macros MUST be preceded by three EXCLAMATION MARKs. |
|
|
## emit ($token) |
|
|
## Emits the specified token. |
|
|
|
|
| 174 |
## Emitted token MUST immediately be handled by the tree construction state. |
## Emitted token MUST immediately be handled by the tree construction state. |
| 175 |
|
|
| 176 |
## Before each step, UA MAY check to see if either one of the scripts in |
## Before each step, UA MAY check to see if either one of the scripts in |
| 335 |
!!!next-input-character; |
!!!next-input-character; |
| 336 |
next TAGNAME; |
next TAGNAME; |
| 337 |
} else { |
} else { |
|
!!!parse-error (type => 'unmatched end tag'); |
|
| 338 |
$self->{next_input_character} = shift @next_char; # reconsume |
$self->{next_input_character} = shift @next_char; # reconsume |
| 339 |
!!!back-next-input-character (@next_char); |
!!!back-next-input-character (@next_char); |
| 340 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 353 |
$self->{next_input_character} == 0x0020 or # SP |
$self->{next_input_character} == 0x0020 or # SP |
| 354 |
$self->{next_input_character} == 0x003E or # > |
$self->{next_input_character} == 0x003E or # > |
| 355 |
$self->{next_input_character} == 0x002F or # / |
$self->{next_input_character} == 0x002F or # / |
|
$self->{next_input_character} == 0x003C or # < |
|
| 356 |
$self->{next_input_character} == -1) { |
$self->{next_input_character} == -1) { |
|
!!!parse-error (type => 'unmatched end tag'); |
|
| 357 |
$self->{next_input_character} = shift @next_char; # reconsume |
$self->{next_input_character} = shift @next_char; # reconsume |
| 358 |
!!!back-next-input-character (@next_char); |
!!!back-next-input-character (@next_char); |
| 359 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 435 |
## Stay in this state |
## Stay in this state |
| 436 |
!!!next-input-character; |
!!!next-input-character; |
| 437 |
redo A; |
redo A; |
| 438 |
} elsif ($self->{next_input_character} == 0x003C or # < |
} elsif ($self->{next_input_character} == -1) { |
|
$self->{next_input_character} == -1) { |
|
| 439 |
!!!parse-error (type => 'unclosed tag'); |
!!!parse-error (type => 'unclosed tag'); |
| 440 |
if ($self->{current_token}->{type} eq 'start tag') { |
if ($self->{current_token}->{type} eq 'start tag') { |
| 441 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 521 |
## Stay in the state |
## Stay in the state |
| 522 |
# next-input-character is already done |
# next-input-character is already done |
| 523 |
redo A; |
redo A; |
| 524 |
} elsif ($self->{next_input_character} == 0x003C or # < |
} elsif ($self->{next_input_character} == -1) { |
|
$self->{next_input_character} == -1) { |
|
| 525 |
!!!parse-error (type => 'unclosed tag'); |
!!!parse-error (type => 'unclosed tag'); |
| 526 |
if ($self->{current_token}->{type} eq 'start tag') { |
if ($self->{current_token}->{type} eq 'start tag') { |
| 527 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 612 |
$self->{state} = 'before attribute name'; |
$self->{state} = 'before attribute name'; |
| 613 |
# next-input-character is already done |
# next-input-character is already done |
| 614 |
redo A; |
redo A; |
| 615 |
} elsif ($self->{next_input_character} == 0x003C or # < |
} elsif ($self->{next_input_character} == -1) { |
|
$self->{next_input_character} == -1) { |
|
| 616 |
!!!parse-error (type => 'unclosed tag'); |
!!!parse-error (type => 'unclosed tag'); |
| 617 |
$before_leave->(); |
$before_leave->(); |
| 618 |
if ($self->{current_token}->{type} eq 'start tag') { |
if ($self->{current_token}->{type} eq 'start tag') { |
| 689 |
$self->{state} = 'before attribute name'; |
$self->{state} = 'before attribute name'; |
| 690 |
# next-input-character is already done |
# next-input-character is already done |
| 691 |
redo A; |
redo A; |
| 692 |
} elsif ($self->{next_input_character} == 0x003C or # < |
} elsif ($self->{next_input_character} == -1) { |
|
$self->{next_input_character} == -1) { |
|
| 693 |
!!!parse-error (type => 'unclosed tag'); |
!!!parse-error (type => 'unclosed tag'); |
| 694 |
if ($self->{current_token}->{type} eq 'start tag') { |
if ($self->{current_token}->{type} eq 'start tag') { |
| 695 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 754 |
undef $self->{current_token}; |
undef $self->{current_token}; |
| 755 |
|
|
| 756 |
redo A; |
redo A; |
| 757 |
} elsif ($self->{next_input_character} == 0x003C or # < |
} elsif ($self->{next_input_character} == -1) { |
|
$self->{next_input_character} == -1) { |
|
| 758 |
!!!parse-error (type => 'unclosed tag'); |
!!!parse-error (type => 'unclosed tag'); |
| 759 |
if ($self->{current_token}->{type} eq 'start tag') { |
if ($self->{current_token}->{type} eq 'start tag') { |
| 760 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 881 |
undef $self->{current_token}; |
undef $self->{current_token}; |
| 882 |
|
|
| 883 |
redo A; |
redo A; |
| 884 |
} elsif ($self->{next_input_character} == 0x003C or # < |
} elsif ($self->{next_input_character} == -1) { |
|
$self->{next_input_character} == -1) { |
|
| 885 |
!!!parse-error (type => 'unclosed tag'); |
!!!parse-error (type => 'unclosed tag'); |
| 886 |
if ($self->{current_token}->{type} eq 'start tag') { |
if ($self->{current_token}->{type} eq 'start tag') { |
| 887 |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
$self->{last_emitted_start_tag_name} = $self->{current_token}->{tag_name}; |
| 1101 |
## Stay in the state |
## Stay in the state |
| 1102 |
!!!next-input-character; |
!!!next-input-character; |
| 1103 |
redo A; |
redo A; |
|
} elsif (0x0061 <= $self->{next_input_character} and |
|
|
$self->{next_input_character} <= 0x007A) { # a..z |
|
|
## ISSUE: "Set the token's name name to the" in the spec |
|
|
$self->{current_token} = {type => 'DOCTYPE', |
|
|
name => chr ($self->{next_input_character} - 0x0020), |
|
|
error => 1}; |
|
|
$self->{state} = 'DOCTYPE name'; |
|
|
!!!next-input-character; |
|
|
redo A; |
|
| 1104 |
} elsif ($self->{next_input_character} == 0x003E) { # > |
} elsif ($self->{next_input_character} == 0x003E) { # > |
| 1105 |
!!!parse-error (type => 'no DOCTYPE name'); |
!!!parse-error (type => 'no DOCTYPE name'); |
| 1106 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1107 |
!!!next-input-character; |
!!!next-input-character; |
| 1108 |
|
|
| 1109 |
!!!emit ({type => 'DOCTYPE', name => '', error => 1}); |
!!!emit ({type => 'DOCTYPE'}); # incorrect |
| 1110 |
|
|
| 1111 |
redo A; |
redo A; |
| 1112 |
} elsif ($self->{next_input_character} == -1) { |
} elsif ($self->{next_input_character} == -1) { |
| 1114 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1115 |
## reconsume |
## reconsume |
| 1116 |
|
|
| 1117 |
!!!emit ({type => 'DOCTYPE', name => '', error => 1}); |
!!!emit ({type => 'DOCTYPE'}); # incorrect |
| 1118 |
|
|
| 1119 |
redo A; |
redo A; |
| 1120 |
} else { |
} else { |
| 1121 |
$self->{current_token} = {type => 'DOCTYPE', |
$self->{current_token} |
| 1122 |
name => chr ($self->{next_input_character}), |
= {type => 'DOCTYPE', |
| 1123 |
error => 1}; |
name => chr ($self->{next_input_character}), |
| 1124 |
|
correct => 1}; |
| 1125 |
## ISSUE: "Set the token's name name to the" in the spec |
## ISSUE: "Set the token's name name to the" in the spec |
| 1126 |
$self->{state} = 'DOCTYPE name'; |
$self->{state} = 'DOCTYPE name'; |
| 1127 |
!!!next-input-character; |
!!!next-input-character; |
| 1128 |
redo A; |
redo A; |
| 1129 |
} |
} |
| 1130 |
} elsif ($self->{state} eq 'DOCTYPE name') { |
} elsif ($self->{state} eq 'DOCTYPE name') { |
| 1131 |
|
## ISSUE: Redundant "First," in the spec. |
| 1132 |
if ($self->{next_input_character} == 0x0009 or # HT |
if ($self->{next_input_character} == 0x0009 or # HT |
| 1133 |
$self->{next_input_character} == 0x000A or # LF |
$self->{next_input_character} == 0x000A or # LF |
| 1134 |
$self->{next_input_character} == 0x000B or # VT |
$self->{next_input_character} == 0x000B or # VT |
| 1135 |
$self->{next_input_character} == 0x000C or # FF |
$self->{next_input_character} == 0x000C or # FF |
| 1136 |
$self->{next_input_character} == 0x0020) { # SP |
$self->{next_input_character} == 0x0020) { # SP |
|
$self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML'); # DOCTYPE |
|
| 1137 |
$self->{state} = 'after DOCTYPE name'; |
$self->{state} = 'after DOCTYPE name'; |
| 1138 |
!!!next-input-character; |
!!!next-input-character; |
| 1139 |
redo A; |
redo A; |
| 1140 |
} elsif ($self->{next_input_character} == 0x003E) { # > |
} elsif ($self->{next_input_character} == 0x003E) { # > |
|
$self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML'); # DOCTYPE |
|
| 1141 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1142 |
!!!next-input-character; |
!!!next-input-character; |
| 1143 |
|
|
| 1145 |
undef $self->{current_token}; |
undef $self->{current_token}; |
| 1146 |
|
|
| 1147 |
redo A; |
redo A; |
|
} elsif (0x0061 <= $self->{next_input_character} and |
|
|
$self->{next_input_character} <= 0x007A) { # a..z |
|
|
$self->{current_token}->{name} .= chr ($self->{next_input_character} - 0x0020); # DOCTYPE |
|
|
#$self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML'); |
|
|
## Stay in the state |
|
|
!!!next-input-character; |
|
|
redo A; |
|
| 1148 |
} elsif ($self->{next_input_character} == -1) { |
} elsif ($self->{next_input_character} == -1) { |
| 1149 |
!!!parse-error (type => 'unclosed DOCTYPE'); |
!!!parse-error (type => 'unclosed DOCTYPE'); |
|
$self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML'); # DOCTYPE |
|
| 1150 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1151 |
## reconsume |
## reconsume |
| 1152 |
|
|
| 1153 |
!!!emit ($self->{current_token}); |
delete $self->{current_token}->{correct}; |
| 1154 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1155 |
undef $self->{current_token}; |
undef $self->{current_token}; |
| 1156 |
|
|
| 1157 |
redo A; |
redo A; |
| 1158 |
} else { |
} else { |
| 1159 |
$self->{current_token}->{name} |
$self->{current_token}->{name} |
| 1160 |
.= chr ($self->{next_input_character}); # DOCTYPE |
.= chr ($self->{next_input_character}); # DOCTYPE |
|
#$self->{current_token}->{error} = ($self->{current_token}->{name} ne 'HTML'); |
|
| 1161 |
## Stay in the state |
## Stay in the state |
| 1162 |
!!!next-input-character; |
!!!next-input-character; |
| 1163 |
redo A; |
redo A; |
| 1184 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1185 |
## reconsume |
## reconsume |
| 1186 |
|
|
| 1187 |
|
delete $self->{current_token}->{correct}; |
| 1188 |
!!!emit ($self->{current_token}); # DOCTYPE |
!!!emit ($self->{current_token}); # DOCTYPE |
| 1189 |
undef $self->{current_token}; |
undef $self->{current_token}; |
| 1190 |
|
|
| 1191 |
redo A; |
redo A; |
| 1192 |
|
} elsif ($self->{next_input_character} == 0x0050 or # P |
| 1193 |
|
$self->{next_input_character} == 0x0070) { # p |
| 1194 |
|
!!!next-input-character; |
| 1195 |
|
if ($self->{next_input_character} == 0x0055 or # U |
| 1196 |
|
$self->{next_input_character} == 0x0075) { # u |
| 1197 |
|
!!!next-input-character; |
| 1198 |
|
if ($self->{next_input_character} == 0x0042 or # B |
| 1199 |
|
$self->{next_input_character} == 0x0062) { # b |
| 1200 |
|
!!!next-input-character; |
| 1201 |
|
if ($self->{next_input_character} == 0x004C or # L |
| 1202 |
|
$self->{next_input_character} == 0x006C) { # l |
| 1203 |
|
!!!next-input-character; |
| 1204 |
|
if ($self->{next_input_character} == 0x0049 or # I |
| 1205 |
|
$self->{next_input_character} == 0x0069) { # i |
| 1206 |
|
!!!next-input-character; |
| 1207 |
|
if ($self->{next_input_character} == 0x0043 or # C |
| 1208 |
|
$self->{next_input_character} == 0x0063) { # c |
| 1209 |
|
$self->{state} = 'before DOCTYPE public identifier'; |
| 1210 |
|
!!!next-input-character; |
| 1211 |
|
redo A; |
| 1212 |
|
} |
| 1213 |
|
} |
| 1214 |
|
} |
| 1215 |
|
} |
| 1216 |
|
} |
| 1217 |
|
|
| 1218 |
|
# |
| 1219 |
|
} elsif ($self->{next_input_character} == 0x0053 or # S |
| 1220 |
|
$self->{next_input_character} == 0x0073) { # s |
| 1221 |
|
!!!next-input-character; |
| 1222 |
|
if ($self->{next_input_character} == 0x0059 or # Y |
| 1223 |
|
$self->{next_input_character} == 0x0079) { # y |
| 1224 |
|
!!!next-input-character; |
| 1225 |
|
if ($self->{next_input_character} == 0x0053 or # S |
| 1226 |
|
$self->{next_input_character} == 0x0073) { # s |
| 1227 |
|
!!!next-input-character; |
| 1228 |
|
if ($self->{next_input_character} == 0x0054 or # T |
| 1229 |
|
$self->{next_input_character} == 0x0074) { # t |
| 1230 |
|
!!!next-input-character; |
| 1231 |
|
if ($self->{next_input_character} == 0x0045 or # E |
| 1232 |
|
$self->{next_input_character} == 0x0065) { # e |
| 1233 |
|
!!!next-input-character; |
| 1234 |
|
if ($self->{next_input_character} == 0x004D or # M |
| 1235 |
|
$self->{next_input_character} == 0x006D) { # m |
| 1236 |
|
$self->{state} = 'before DOCTYPE system identifier'; |
| 1237 |
|
!!!next-input-character; |
| 1238 |
|
redo A; |
| 1239 |
|
} |
| 1240 |
|
} |
| 1241 |
|
} |
| 1242 |
|
} |
| 1243 |
|
} |
| 1244 |
|
|
| 1245 |
|
# |
| 1246 |
} else { |
} else { |
| 1247 |
!!!parse-error (type => 'string after DOCTYPE name'); |
!!!next-input-character; |
| 1248 |
$self->{current_token}->{error} = 1; # DOCTYPE |
# |
| 1249 |
|
} |
| 1250 |
|
|
| 1251 |
|
!!!parse-error (type => 'string after DOCTYPE name'); |
| 1252 |
|
$self->{state} = 'bogus DOCTYPE'; |
| 1253 |
|
# next-input-character is already done |
| 1254 |
|
redo A; |
| 1255 |
|
} elsif ($self->{state} eq 'before DOCTYPE public identifier') { |
| 1256 |
|
if ({ |
| 1257 |
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
| 1258 |
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
| 1259 |
|
}->{$self->{next_input_character}}) { |
| 1260 |
|
## Stay in the state |
| 1261 |
|
!!!next-input-character; |
| 1262 |
|
redo A; |
| 1263 |
|
} elsif ($self->{next_input_character} eq 0x0022) { # " |
| 1264 |
|
$self->{current_token}->{public_identifier} = ''; # DOCTYPE |
| 1265 |
|
$self->{state} = 'DOCTYPE public identifier (double-quoted)'; |
| 1266 |
|
!!!next-input-character; |
| 1267 |
|
redo A; |
| 1268 |
|
} elsif ($self->{next_input_character} eq 0x0027) { # ' |
| 1269 |
|
$self->{current_token}->{public_identifier} = ''; # DOCTYPE |
| 1270 |
|
$self->{state} = 'DOCTYPE public identifier (single-quoted)'; |
| 1271 |
|
!!!next-input-character; |
| 1272 |
|
redo A; |
| 1273 |
|
} elsif ($self->{next_input_character} eq 0x003E) { # > |
| 1274 |
|
!!!parse-error (type => 'no PUBLIC literal'); |
| 1275 |
|
|
| 1276 |
|
$self->{state} = 'data'; |
| 1277 |
|
!!!next-input-character; |
| 1278 |
|
|
| 1279 |
|
delete $self->{current_token}->{correct}; |
| 1280 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1281 |
|
undef $self->{current_token}; |
| 1282 |
|
|
| 1283 |
|
redo A; |
| 1284 |
|
} elsif ($self->{next_input_character} == -1) { |
| 1285 |
|
!!!parse-error (type => 'unclosed DOCTYPE'); |
| 1286 |
|
|
| 1287 |
|
$self->{state} = 'data'; |
| 1288 |
|
## reconsume |
| 1289 |
|
|
| 1290 |
|
delete $self->{current_token}->{correct}; |
| 1291 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1292 |
|
undef $self->{current_token}; |
| 1293 |
|
|
| 1294 |
|
redo A; |
| 1295 |
|
} else { |
| 1296 |
|
!!!parse-error (type => 'string after PUBLIC'); |
| 1297 |
|
$self->{state} = 'bogus DOCTYPE'; |
| 1298 |
|
!!!next-input-character; |
| 1299 |
|
redo A; |
| 1300 |
|
} |
| 1301 |
|
} elsif ($self->{state} eq 'DOCTYPE public identifier (double-quoted)') { |
| 1302 |
|
if ($self->{next_input_character} == 0x0022) { # " |
| 1303 |
|
$self->{state} = 'after DOCTYPE public identifier'; |
| 1304 |
|
!!!next-input-character; |
| 1305 |
|
redo A; |
| 1306 |
|
} elsif ($self->{next_input_character} == -1) { |
| 1307 |
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
| 1308 |
|
|
| 1309 |
|
$self->{state} = 'data'; |
| 1310 |
|
## reconsume |
| 1311 |
|
|
| 1312 |
|
delete $self->{current_token}->{correct}; |
| 1313 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1314 |
|
undef $self->{current_token}; |
| 1315 |
|
|
| 1316 |
|
redo A; |
| 1317 |
|
} else { |
| 1318 |
|
$self->{current_token}->{public_identifier} # DOCTYPE |
| 1319 |
|
.= chr $self->{next_input_character}; |
| 1320 |
|
## Stay in the state |
| 1321 |
|
!!!next-input-character; |
| 1322 |
|
redo A; |
| 1323 |
|
} |
| 1324 |
|
} elsif ($self->{state} eq 'DOCTYPE public identifier (single-quoted)') { |
| 1325 |
|
if ($self->{next_input_character} == 0x0027) { # ' |
| 1326 |
|
$self->{state} = 'after DOCTYPE public identifier'; |
| 1327 |
|
!!!next-input-character; |
| 1328 |
|
redo A; |
| 1329 |
|
} elsif ($self->{next_input_character} == -1) { |
| 1330 |
|
!!!parse-error (type => 'unclosed PUBLIC literal'); |
| 1331 |
|
|
| 1332 |
|
$self->{state} = 'data'; |
| 1333 |
|
## reconsume |
| 1334 |
|
|
| 1335 |
|
delete $self->{current_token}->{correct}; |
| 1336 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1337 |
|
undef $self->{current_token}; |
| 1338 |
|
|
| 1339 |
|
redo A; |
| 1340 |
|
} else { |
| 1341 |
|
$self->{current_token}->{public_identifier} # DOCTYPE |
| 1342 |
|
.= chr $self->{next_input_character}; |
| 1343 |
|
## Stay in the state |
| 1344 |
|
!!!next-input-character; |
| 1345 |
|
redo A; |
| 1346 |
|
} |
| 1347 |
|
} elsif ($self->{state} eq 'after DOCTYPE public identifier') { |
| 1348 |
|
if ({ |
| 1349 |
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
| 1350 |
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
| 1351 |
|
}->{$self->{next_input_character}}) { |
| 1352 |
|
## Stay in the state |
| 1353 |
|
!!!next-input-character; |
| 1354 |
|
redo A; |
| 1355 |
|
} elsif ($self->{next_input_character} == 0x0022) { # " |
| 1356 |
|
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
| 1357 |
|
$self->{state} = 'DOCTYPE system identifier (double-quoted)'; |
| 1358 |
|
!!!next-input-character; |
| 1359 |
|
redo A; |
| 1360 |
|
} elsif ($self->{next_input_character} == 0x0027) { # ' |
| 1361 |
|
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
| 1362 |
|
$self->{state} = 'DOCTYPE system identifier (single-quoted)'; |
| 1363 |
|
!!!next-input-character; |
| 1364 |
|
redo A; |
| 1365 |
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
| 1366 |
|
$self->{state} = 'data'; |
| 1367 |
|
!!!next-input-character; |
| 1368 |
|
|
| 1369 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1370 |
|
undef $self->{current_token}; |
| 1371 |
|
|
| 1372 |
|
redo A; |
| 1373 |
|
} elsif ($self->{next_input_character} == -1) { |
| 1374 |
|
!!!parse-error (type => 'unclosed DOCTYPE'); |
| 1375 |
|
|
| 1376 |
|
$self->{state} = 'data'; |
| 1377 |
|
## recomsume |
| 1378 |
|
|
| 1379 |
|
delete $self->{current_token}->{correct}; |
| 1380 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1381 |
|
undef $self->{current_token}; |
| 1382 |
|
|
| 1383 |
|
redo A; |
| 1384 |
|
} else { |
| 1385 |
|
!!!parse-error (type => 'string after PUBLIC literal'); |
| 1386 |
|
$self->{state} = 'bogus DOCTYPE'; |
| 1387 |
|
!!!next-input-character; |
| 1388 |
|
redo A; |
| 1389 |
|
} |
| 1390 |
|
} elsif ($self->{state} eq 'before DOCTYPE system identifier') { |
| 1391 |
|
if ({ |
| 1392 |
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
| 1393 |
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
| 1394 |
|
}->{$self->{next_input_character}}) { |
| 1395 |
|
## Stay in the state |
| 1396 |
|
!!!next-input-character; |
| 1397 |
|
redo A; |
| 1398 |
|
} elsif ($self->{next_input_character} == 0x0022) { # " |
| 1399 |
|
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
| 1400 |
|
$self->{state} = 'DOCTYPE system identifier (double-quoted)'; |
| 1401 |
|
!!!next-input-character; |
| 1402 |
|
redo A; |
| 1403 |
|
} elsif ($self->{next_input_character} == 0x0027) { # ' |
| 1404 |
|
$self->{current_token}->{system_identifier} = ''; # DOCTYPE |
| 1405 |
|
$self->{state} = 'DOCTYPE system identifier (single-quoted)'; |
| 1406 |
|
!!!next-input-character; |
| 1407 |
|
redo A; |
| 1408 |
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
| 1409 |
|
!!!parse-error (type => 'no SYSTEM literal'); |
| 1410 |
|
$self->{state} = 'data'; |
| 1411 |
|
!!!next-input-character; |
| 1412 |
|
|
| 1413 |
|
delete $self->{current_token}->{correct}; |
| 1414 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1415 |
|
undef $self->{current_token}; |
| 1416 |
|
|
| 1417 |
|
redo A; |
| 1418 |
|
} elsif ($self->{next_input_character} == -1) { |
| 1419 |
|
!!!parse-error (type => 'unclosed DOCTYPE'); |
| 1420 |
|
|
| 1421 |
|
$self->{state} = 'data'; |
| 1422 |
|
## recomsume |
| 1423 |
|
|
| 1424 |
|
delete $self->{current_token}->{correct}; |
| 1425 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1426 |
|
undef $self->{current_token}; |
| 1427 |
|
|
| 1428 |
|
redo A; |
| 1429 |
|
} else { |
| 1430 |
|
!!!parse-error (type => 'string after PUBLIC literal'); |
| 1431 |
|
$self->{state} = 'bogus DOCTYPE'; |
| 1432 |
|
!!!next-input-character; |
| 1433 |
|
redo A; |
| 1434 |
|
} |
| 1435 |
|
} elsif ($self->{state} eq 'DOCTYPE system identifier (double-quoted)') { |
| 1436 |
|
if ($self->{next_input_character} == 0x0022) { # " |
| 1437 |
|
$self->{state} = 'after DOCTYPE system identifier'; |
| 1438 |
|
!!!next-input-character; |
| 1439 |
|
redo A; |
| 1440 |
|
} elsif ($self->{next_input_character} == -1) { |
| 1441 |
|
!!!parse-error (type => 'unclosed SYSTEM literal'); |
| 1442 |
|
|
| 1443 |
|
$self->{state} = 'data'; |
| 1444 |
|
## reconsume |
| 1445 |
|
|
| 1446 |
|
delete $self->{current_token}->{correct}; |
| 1447 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1448 |
|
undef $self->{current_token}; |
| 1449 |
|
|
| 1450 |
|
redo A; |
| 1451 |
|
} else { |
| 1452 |
|
$self->{current_token}->{system_identifier} # DOCTYPE |
| 1453 |
|
.= chr $self->{next_input_character}; |
| 1454 |
|
## Stay in the state |
| 1455 |
|
!!!next-input-character; |
| 1456 |
|
redo A; |
| 1457 |
|
} |
| 1458 |
|
} elsif ($self->{state} eq 'DOCTYPE system identifier (single-quoted)') { |
| 1459 |
|
if ($self->{next_input_character} == 0x0027) { # ' |
| 1460 |
|
$self->{state} = 'after DOCTYPE system identifier'; |
| 1461 |
|
!!!next-input-character; |
| 1462 |
|
redo A; |
| 1463 |
|
} elsif ($self->{next_input_character} == -1) { |
| 1464 |
|
!!!parse-error (type => 'unclosed SYSTEM literal'); |
| 1465 |
|
|
| 1466 |
|
$self->{state} = 'data'; |
| 1467 |
|
## reconsume |
| 1468 |
|
|
| 1469 |
|
delete $self->{current_token}->{correct}; |
| 1470 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1471 |
|
undef $self->{current_token}; |
| 1472 |
|
|
| 1473 |
|
redo A; |
| 1474 |
|
} else { |
| 1475 |
|
$self->{current_token}->{system_identifier} # DOCTYPE |
| 1476 |
|
.= chr $self->{next_input_character}; |
| 1477 |
|
## Stay in the state |
| 1478 |
|
!!!next-input-character; |
| 1479 |
|
redo A; |
| 1480 |
|
} |
| 1481 |
|
} elsif ($self->{state} eq 'after DOCTYPE system identifier') { |
| 1482 |
|
if ({ |
| 1483 |
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
| 1484 |
|
#0x000D => 1, # HT, LF, VT, FF, SP, CR |
| 1485 |
|
}->{$self->{next_input_character}}) { |
| 1486 |
|
## Stay in the state |
| 1487 |
|
!!!next-input-character; |
| 1488 |
|
redo A; |
| 1489 |
|
} elsif ($self->{next_input_character} == 0x003E) { # > |
| 1490 |
|
$self->{state} = 'data'; |
| 1491 |
|
!!!next-input-character; |
| 1492 |
|
|
| 1493 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1494 |
|
undef $self->{current_token}; |
| 1495 |
|
|
| 1496 |
|
redo A; |
| 1497 |
|
} elsif ($self->{next_input_character} == -1) { |
| 1498 |
|
!!!parse-error (type => 'unclosed DOCTYPE'); |
| 1499 |
|
|
| 1500 |
|
$self->{state} = 'data'; |
| 1501 |
|
## recomsume |
| 1502 |
|
|
| 1503 |
|
delete $self->{current_token}->{correct}; |
| 1504 |
|
!!!emit ($self->{current_token}); # DOCTYPE |
| 1505 |
|
undef $self->{current_token}; |
| 1506 |
|
|
| 1507 |
|
redo A; |
| 1508 |
|
} else { |
| 1509 |
|
!!!parse-error (type => 'string after SYSTEM literal'); |
| 1510 |
$self->{state} = 'bogus DOCTYPE'; |
$self->{state} = 'bogus DOCTYPE'; |
| 1511 |
!!!next-input-character; |
!!!next-input-character; |
| 1512 |
redo A; |
redo A; |
| 1516 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1517 |
!!!next-input-character; |
!!!next-input-character; |
| 1518 |
|
|
| 1519 |
|
delete $self->{current_token}->{correct}; |
| 1520 |
!!!emit ($self->{current_token}); # DOCTYPE |
!!!emit ($self->{current_token}); # DOCTYPE |
| 1521 |
undef $self->{current_token}; |
undef $self->{current_token}; |
| 1522 |
|
|
| 1526 |
$self->{state} = 'data'; |
$self->{state} = 'data'; |
| 1527 |
## reconsume |
## reconsume |
| 1528 |
|
|
| 1529 |
|
delete $self->{current_token}->{correct}; |
| 1530 |
!!!emit ($self->{current_token}); # DOCTYPE |
!!!emit ($self->{current_token}); # DOCTYPE |
| 1531 |
undef $self->{current_token}; |
undef $self->{current_token}; |
| 1532 |
|
|
| 1546 |
|
|
| 1547 |
sub _tokenize_attempt_to_consume_an_entity ($) { |
sub _tokenize_attempt_to_consume_an_entity ($) { |
| 1548 |
my $self = shift; |
my $self = shift; |
| 1549 |
|
|
| 1550 |
if ($self->{next_input_character} == 0x0023) { # # |
if ({ |
| 1551 |
|
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF, |
| 1552 |
|
0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR |
| 1553 |
|
}->{$self->{next_input_character}}) { |
| 1554 |
|
## Don't consume |
| 1555 |
|
## No error |
| 1556 |
|
return undef; |
| 1557 |
|
} elsif ($self->{next_input_character} == 0x0023) { # # |
| 1558 |
!!!next-input-character; |
!!!next-input-character; |
| 1559 |
if ($self->{next_input_character} == 0x0078 or # x |
if ($self->{next_input_character} == 0x0078 or # x |
| 1560 |
$self->{next_input_character} == 0x0058) { # X |
$self->{next_input_character} == 0x0058) { # X |
| 1649 |
|
|
| 1650 |
my $value = $entity_name; |
my $value = $entity_name; |
| 1651 |
my $match; |
my $match; |
| 1652 |
|
require Whatpm::_NamedEntityList; |
| 1653 |
|
our $EntityChar; |
| 1654 |
|
|
| 1655 |
while (length $entity_name < 10 and |
while (length $entity_name < 10 and |
| 1656 |
## NOTE: Some number greater than the maximum length of entity name |
## NOTE: Some number greater than the maximum length of entity name |
| 1657 |
((0x0041 <= $self->{next_input_character} and |
((0x0041 <= $self->{next_input_character} and # a |
| 1658 |
$self->{next_input_character} <= 0x005A) or |
$self->{next_input_character} <= 0x005A) or # x |
| 1659 |
(0x0061 <= $self->{next_input_character} and |
(0x0061 <= $self->{next_input_character} and # a |
| 1660 |
$self->{next_input_character} <= 0x007A) or |
$self->{next_input_character} <= 0x007A) or # z |
| 1661 |
(0x0030 <= $self->{next_input_character} and |
(0x0030 <= $self->{next_input_character} and # 0 |
| 1662 |
$self->{next_input_character} <= 0x0039))) { |
$self->{next_input_character} <= 0x0039) or # 9 |
| 1663 |
|
$self->{next_input_character} == 0x003B)) { # ; |
| 1664 |
$entity_name .= chr $self->{next_input_character}; |
$entity_name .= chr $self->{next_input_character}; |
| 1665 |
if (defined $entity_char->{$entity_name}) { |
if (defined $EntityChar->{$entity_name}) { |
| 1666 |
$value = $entity_char->{$entity_name}; |
$value = $EntityChar->{$entity_name}; |
| 1667 |
$match = 1; |
if ($self->{next_input_character} == 0x003B) { # ; |
| 1668 |
|
$match = 1; |
| 1669 |
|
!!!next-input-character; |
| 1670 |
|
last; |
| 1671 |
|
} else { |
| 1672 |
|
$match = -1; |
| 1673 |
|
} |
| 1674 |
} else { |
} else { |
| 1675 |
$value .= chr $self->{next_input_character}; |
$value .= chr $self->{next_input_character}; |
| 1676 |
} |
} |
| 1677 |
!!!next-input-character; |
!!!next-input-character; |
| 1678 |
} |
} |
| 1679 |
|
|
| 1680 |
if ($match) { |
if ($match > 0) { |
| 1681 |
if ($self->{next_input_character} == 0x003B) { # ; |
return {type => 'character', data => $value}; |
| 1682 |
!!!next-input-character; |
} elsif ($match < 0) { |
| 1683 |
} else { |
!!!parse-error (type => 'refc'); |
|
!!!parse-error (type => 'refc'); |
|
|
} |
|
|
|
|
| 1684 |
return {type => 'character', data => $value}; |
return {type => 'character', data => $value}; |
| 1685 |
} else { |
} else { |
| 1686 |
!!!parse-error (type => 'bare ero'); |
!!!parse-error (type => 'bare ero'); |
| 1701 |
$self->{document}->strict_error_checking (0); |
$self->{document}->strict_error_checking (0); |
| 1702 |
## TODO: Turn mutation events off # MUST |
## TODO: Turn mutation events off # MUST |
| 1703 |
## TODO: Turn loose Document option (manakai extension) on |
## TODO: Turn loose Document option (manakai extension) on |
| 1704 |
## TODO: Mark the Document as an HTML document # MUST |
$self->{document}->manakai_is_html (1); # MUST |
| 1705 |
} # _initialize_tree_constructor |
} # _initialize_tree_constructor |
| 1706 |
|
|
| 1707 |
sub _terminate_tree_constructor ($) { |
sub _terminate_tree_constructor ($) { |
| 1741 |
|
|
| 1742 |
sub _tree_construction_initial ($) { |
sub _tree_construction_initial ($) { |
| 1743 |
my $self = shift; |
my $self = shift; |
| 1744 |
B: { |
INITIAL: { |
| 1745 |
if ($token->{type} eq 'DOCTYPE') { |
if ($token->{type} eq 'DOCTYPE') { |
| 1746 |
if ($token->{error}) { |
## NOTE: Conformance checkers MAY, instead of reporting "not HTML5" |
| 1747 |
## ISSUE: Spec currently left this case undefined. |
## error, switch to a conformance checking mode for another |
| 1748 |
!!!parse-error (type => 'bogus DOCTYPE'); |
## language. |
| 1749 |
} |
my $doctype_name = $token->{name}; |
| 1750 |
my $doctype = $self->{document}->create_document_type_definition |
$doctype_name = '' unless defined $doctype_name; |
| 1751 |
($token->{name}); |
$doctype_name =~ tr/a-z/A-Z/; |
| 1752 |
$self->{document}->append_child ($doctype); |
if (not defined $token->{name} or # <!DOCTYPE> |
| 1753 |
#$phase = 'root element'; |
defined $token->{public_identifier} or |
| 1754 |
!!!next-token; |
defined $token->{system_identifier}) { |
| 1755 |
#redo B; |
!!!parse-error (type => 'not HTML5'); |
| 1756 |
return; |
} elsif ($doctype_name ne 'HTML') { |
| 1757 |
} elsif ({ |
## ISSUE: ASCII case-insensitive? (in fact it does not matter) |
| 1758 |
comment => 1, |
!!!parse-error (type => 'not HTML5'); |
| 1759 |
'start tag' => 1, |
} |
| 1760 |
'end tag' => 1, |
|
| 1761 |
'end-of-file' => 1, |
my $doctype = $self->{document}->create_document_type_definition |
| 1762 |
}->{$token->{type}}) { |
($token->{name}); ## ISSUE: If name is missing (e.g. <!DOCTYPE>)? |
| 1763 |
## ISSUE: Spec currently left this case undefined. |
$doctype->public_id ($token->{public_identifier}) |
| 1764 |
!!!parse-error (type => 'missing DOCTYPE'); |
if defined $token->{public_identifier}; |
| 1765 |
#$phase = 'root element'; |
$doctype->system_id ($token->{system_identifier}) |
| 1766 |
## reprocess |
if defined $token->{system_identifier}; |
| 1767 |
#redo B; |
## NOTE: Other DocumentType attributes are null or empty lists. |
| 1768 |
return; |
## ISSUE: internalSubset = null?? |
| 1769 |
} elsif ($token->{type} eq 'character') { |
$self->{document}->append_child ($doctype); |
| 1770 |
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { |
|
| 1771 |
$self->{document}->manakai_append_text ($1); |
if (not $token->{correct} or $doctype_name ne 'HTML') { |
| 1772 |
## ISSUE: DOM3 Core does not allow Document > Text |
$self->{document}->manakai_compat_mode ('quirks'); |
| 1773 |
unless (length $token->{data}) { |
} elsif (defined $token->{public_identifier}) { |
| 1774 |
## Stay in the phase |
my $pubid = $token->{public_identifier}; |
| 1775 |
!!!next-token; |
$pubid =~ tr/a-z/A-z/; |
| 1776 |
redo B; |
if ({ |
| 1777 |
|
"+//SILMARIL//DTD HTML PRO V0R11 19970101//EN" => 1, |
| 1778 |
|
"-//ADVASOFT LTD//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1, |
| 1779 |
|
"-//AS//DTD HTML 3.0 ASWEDIT + EXTENSIONS//EN" => 1, |
| 1780 |
|
"-//IETF//DTD HTML 2.0 LEVEL 1//EN" => 1, |
| 1781 |
|
"-//IETF//DTD HTML 2.0 LEVEL 2//EN" => 1, |
| 1782 |
|
"-//IETF//DTD HTML 2.0 STRICT LEVEL 1//EN" => 1, |
| 1783 |
|
"-//IETF//DTD HTML 2.0 STRICT LEVEL 2//EN" => 1, |
| 1784 |
|
"-//IETF//DTD HTML 2.0 STRICT//EN" => 1, |
| 1785 |
|
"-//IETF//DTD HTML 2.0//EN" => 1, |
| 1786 |
|
"-//IETF//DTD HTML 2.1E//EN" => 1, |
| 1787 |
|
"-//IETF//DTD HTML 3.0//EN" => 1, |
| 1788 |
|
"-//IETF//DTD HTML 3.0//EN//" => 1, |
| 1789 |
|
"-//IETF//DTD HTML 3.2 FINAL//EN" => 1, |
| 1790 |
|
"-//IETF//DTD HTML 3.2//EN" => 1, |
| 1791 |
|
"-//IETF//DTD HTML 3//EN" => 1, |
| 1792 |
|
"-//IETF//DTD HTML LEVEL 0//EN" => 1, |
| 1793 |
|
"-//IETF//DTD HTML LEVEL 0//EN//2.0" => 1, |
| 1794 |
|
"-//IETF//DTD HTML LEVEL 1//EN" => 1, |
| 1795 |
|
"-//IETF//DTD HTML LEVEL 1//EN//2.0" => 1, |
| 1796 |
|
"-//IETF//DTD HTML LEVEL 2//EN" => 1, |
| 1797 |
|
"-//IETF//DTD HTML LEVEL 2//EN//2.0" => 1, |
| 1798 |
|
"-//IETF//DTD HTML LEVEL 3//EN" => 1, |
| 1799 |
|
"-//IETF//DTD HTML LEVEL 3//EN//3.0" => 1, |
| 1800 |
|
"-//IETF//DTD HTML STRICT LEVEL 0//EN" => 1, |
| 1801 |
|
"-//IETF//DTD HTML STRICT LEVEL 0//EN//2.0" => 1, |
| 1802 |
|
"-//IETF//DTD HTML STRICT LEVEL 1//EN" => 1, |
| 1803 |
|
"-//IETF//DTD HTML STRICT LEVEL 1//EN//2.0" => 1, |
| 1804 |
|
"-//IETF//DTD HTML STRICT LEVEL 2//EN" => 1, |
| 1805 |
|
"-//IETF//DTD HTML STRICT LEVEL 2//EN//2.0" => 1, |
| 1806 |
|
"-//IETF//DTD HTML STRICT LEVEL 3//EN" => 1, |
| 1807 |
|
"-//IETF//DTD HTML STRICT LEVEL 3//EN//3.0" => 1, |
| 1808 |
|
"-//IETF//DTD HTML STRICT//EN" => 1, |
| 1809 |
|
"-//IETF//DTD HTML STRICT//EN//2.0" => 1, |
| 1810 |
|
"-//IETF//DTD HTML STRICT//EN//3.0" => 1, |
| 1811 |
|
"-//IETF//DTD HTML//EN" => 1, |
| 1812 |
|
"-//IETF//DTD HTML//EN//2.0" => 1, |
| 1813 |
|
"-//IETF//DTD HTML//EN//3.0" => 1, |
| 1814 |
|
"-//METRIUS//DTD METRIUS PRESENTATIONAL//EN" => 1, |
| 1815 |
|
"-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML STRICT//EN" => 1, |
| 1816 |
|
"-//MICROSOFT//DTD INTERNET EXPLORER 2.0 HTML//EN" => 1, |
| 1817 |
|
"-//MICROSOFT//DTD INTERNET EXPLORER 2.0 TABLES//EN" => 1, |
| 1818 |
|
"-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML STRICT//EN" => 1, |
| 1819 |
|
"-//MICROSOFT//DTD INTERNET EXPLORER 3.0 HTML//EN" => 1, |
| 1820 |
|
"-//MICROSOFT//DTD INTERNET EXPLORER 3.0 TABLES//EN" => 1, |
| 1821 |
|
"-//NETSCAPE COMM. CORP.//DTD HTML//EN" => 1, |
| 1822 |
|
"-//NETSCAPE COMM. CORP.//DTD STRICT HTML//EN" => 1, |
| 1823 |
|
"-//O'REILLY AND ASSOCIATES//DTD HTML 2.0//EN" => 1, |
| 1824 |
|
"-//O'REILLY AND ASSOCIATES//DTD HTML EXTENDED 1.0//EN" => 1, |
| 1825 |
|
"-//SPYGLASS//DTD HTML 2.0 EXTENDED//EN" => 1, |
| 1826 |
|
"-//SQ//DTD HTML 2.0 HOTMETAL + EXTENSIONS//EN" => 1, |
| 1827 |
|
"-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA HTML//EN" => 1, |
| 1828 |
|
"-//SUN MICROSYSTEMS CORP.//DTD HOTJAVA STRICT HTML//EN" => 1, |
| 1829 |
|
"-//W3C//DTD HTML 3 1995-03-24//EN" => 1, |
| 1830 |
|
"-//W3C//DTD HTML 3.2 DRAFT//EN" => 1, |
| 1831 |
|
"-//W3C//DTD HTML 3.2 FINAL//EN" => 1, |
| 1832 |
|
"-//W3C//DTD HTML 3.2//EN" => 1, |
| 1833 |
|
"-//W3C//DTD HTML 3.2S DRAFT//EN" => 1, |
| 1834 |
|
"-//W3C//DTD HTML 4.0 FRAMESET//EN" => 1, |
| 1835 |
|
"-//W3C//DTD HTML 4.0 TRANSITIONAL//EN" => 1, |
| 1836 |
|
"-//W3C//DTD HTML EXPERIMETNAL 19960712//EN" => 1, |
| 1837 |
|
"-//W3C//DTD HTML EXPERIMENTAL 970421//EN" => 1, |
| 1838 |
|
"-//W3C//DTD W3 HTML//EN" => 1, |
| 1839 |
|
"-//W3O//DTD W3 HTML 3.0//EN" => 1, |
| 1840 |
|
"-//W3O//DTD W3 HTML 3.0//EN//" => 1, |
| 1841 |
|
"-//W3O//DTD W3 HTML STRICT 3.0//EN//" => 1, |
| 1842 |
|
"-//WEBTECHS//DTD MOZILLA HTML 2.0//EN" => 1, |
| 1843 |
|
"-//WEBTECHS//DTD MOZILLA HTML//EN" => 1, |
| 1844 |
|
"-/W3C/DTD HTML 4.0 TRANSITIONAL/EN" => 1, |
| 1845 |
|
"HTML" => 1, |
| 1846 |
|
}->{$pubid}) { |
| 1847 |
|
$self->{document}->manakai_compat_mode ('quirks'); |
| 1848 |
|
} elsif ($pubid eq "-//W3C//DTD HTML 4.01 FRAMESET//EN" or |
| 1849 |
|
$pubid eq "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN") { |
| 1850 |
|
if (defined $token->{system_identifier}) { |
| 1851 |
|
$self->{document}->manakai_compat_mode ('quirks'); |
| 1852 |
|
} else { |
| 1853 |
|
$self->{document}->manakai_compat_mode ('limited quirks'); |
| 1854 |
} |
} |
| 1855 |
|
} elsif ($pubid eq "-//W3C//DTD XHTML 1.0 Frameset//EN" or |
| 1856 |
|
$pubid eq "-//W3C//DTD XHTML 1.0 Transitional//EN") { |
| 1857 |
|
$self->{document}->manakai_compat_mode ('limited quirks'); |
| 1858 |
|
} |
| 1859 |
|
} |
| 1860 |
|
if (defined $token->{system_identifier}) { |
| 1861 |
|
my $sysid = $token->{system_identifier}; |
| 1862 |
|
$sysid =~ tr/A-Z/a-z/; |
| 1863 |
|
if ($sysid eq "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") { |
| 1864 |
|
$self->{document}->manakai_compat_mode ('quirks'); |
| 1865 |
} |
} |
|
## ISSUE: Spec currently left this case undefined. |
|
|
!!!parse-error (type => 'missing DOCTYPE'); |
|
|
#$phase = 'root element'; |
|
|
## reprocess |
|
|
#redo B; |
|
|
return; |
|
|
} else { |
|
|
die "$0: $token->{type}: Unknown token"; |
|
| 1866 |
} |
} |
| 1867 |
} # B |
|
| 1868 |
|
## Go to the root element phase. |
| 1869 |
|
!!!next-token; |
| 1870 |
|
return; |
| 1871 |
|
} elsif ({ |
| 1872 |
|
'start tag' => 1, |
| 1873 |
|
'end tag' => 1, |
| 1874 |
|
'end-of-file' => 1, |
| 1875 |
|
}->{$token->{type}}) { |
| 1876 |
|
!!!parse-error (type => 'no DOCTYPE'); |
| 1877 |
|
$self->{document}->manakai_compat_mode ('quirks'); |
| 1878 |
|
## Go to the root element phase |
| 1879 |
|
## reprocess |
| 1880 |
|
return; |
| 1881 |
|
} elsif ($token->{type} eq 'character') { |
| 1882 |
|
if ($token->{data} =~ s/^([\x09\x0A\x0B\x0C\x20]+)//) { # \x0D |
| 1883 |
|
## Ignore the token |
| 1884 |
|
unless (length $token->{data}) { |
| 1885 |
|
## Stay in the phase |
| 1886 |
|
!!!next-token; |
| 1887 |
|
redo INITIAL; |
| 1888 |
|
} |
| 1889 |
|
} |
| 1890 |
|
|
| 1891 |
|
!!!parse-error (type => 'no DOCTYPE'); |
| 1892 |
|
$self->{document}->manakai_compat_mode ('quirks'); |
| 1893 |
|
## Go to the root element phase |
| 1894 |
|
## reprocess |
| 1895 |
|
return; |
| 1896 |
|
} elsif ($token->{type} eq 'comment') { |
| 1897 |
|
my $comment = $self->{document}->create_comment ($token->{data}); |
| 1898 |
|
$self->{document}->append_child ($comment); |
| 1899 |
|
|
| 1900 |
|
## Stay in the phase. |
| 1901 |
|
!!!next-token; |
| 1902 |
|
redo INITIAL; |
| 1903 |
|
} else { |
| 1904 |
|
die "$0: $token->{type}: Unknown token"; |
| 1905 |
|
} |
| 1906 |
|
} # INITIAL |
| 1907 |
} # _tree_construction_initial |
} # _tree_construction_initial |
| 1908 |
|
|
| 1909 |
sub _tree_construction_root_element ($) { |
sub _tree_construction_root_element ($) { |
| 2726 |
return; |
return; |
| 2727 |
} elsif ({ |
} elsif ({ |
| 2728 |
b => 1, big => 1, em => 1, font => 1, i => 1, |
b => 1, big => 1, em => 1, font => 1, i => 1, |
| 2729 |
nobr => 1, s => 1, small => 1, strile => 1, |
s => 1, small => 1, strile => 1, |
| 2730 |
strong => 1, tt => 1, u => 1, |
strong => 1, tt => 1, u => 1, |
| 2731 |
}->{$token->{tag_name}}) { |
}->{$token->{tag_name}}) { |
| 2732 |
$reconstruct_active_formatting_elements->($insert_to_current); |
$reconstruct_active_formatting_elements->($insert_to_current); |
| 2736 |
|
|
| 2737 |
!!!next-token; |
!!!next-token; |
| 2738 |
return; |
return; |
| 2739 |
|
} elsif ($token->{tag_name} eq 'nobr') { |
| 2740 |
|
$reconstruct_active_formatting_elements->($insert_to_current); |
| 2741 |
|
|
| 2742 |
|
## has a |nobr| element in scope |
| 2743 |
|
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
| 2744 |
|
my $node = $self->{open_elements}->[$_]; |
| 2745 |
|
if ($node->[1] eq 'nobr') { |
| 2746 |
|
!!!back-token; |
| 2747 |
|
$token = {type => 'end tag', tag_name => 'nobr'}; |
| 2748 |
|
return; |
| 2749 |
|
} elsif ({ |
| 2750 |
|
table => 1, caption => 1, td => 1, th => 1, |
| 2751 |
|
button => 1, marquee => 1, object => 1, html => 1, |
| 2752 |
|
}->{$node->[1]}) { |
| 2753 |
|
last INSCOPE; |
| 2754 |
|
} |
| 2755 |
|
} # INSCOPE |
| 2756 |
|
|
| 2757 |
|
!!!insert-element-t ($token->{tag_name}, $token->{attributes}); |
| 2758 |
|
push @$active_formatting_elements, $self->{open_elements}->[-1]; |
| 2759 |
|
|
| 2760 |
|
!!!next-token; |
| 2761 |
|
return; |
| 2762 |
} elsif ($token->{tag_name} eq 'button') { |
} elsif ($token->{tag_name} eq 'button') { |
| 2763 |
## has a button element in scope |
## has a button element in scope |
| 2764 |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
INSCOPE: for (reverse 0..$#{$self->{open_elements}}) { |
| 2878 |
return; |
return; |
| 2879 |
} else { |
} else { |
| 2880 |
my $at = $token->{attributes}; |
my $at = $token->{attributes}; |
| 2881 |
|
my $form_attrs; |
| 2882 |
|
$form_attrs->{action} = $at->{action} if $at->{action}; |
| 2883 |
|
my $prompt_attr = $at->{prompt}; |
| 2884 |
$at->{name} = {name => 'name', value => 'isindex'}; |
$at->{name} = {name => 'name', value => 'isindex'}; |
| 2885 |
|
delete $at->{action}; |
| 2886 |
|
delete $at->{prompt}; |
| 2887 |
my @tokens = ( |
my @tokens = ( |
| 2888 |
{type => 'start tag', tag_name => 'form'}, |
{type => 'start tag', tag_name => 'form', |
| 2889 |
|
attributes => $form_attrs}, |
| 2890 |
{type => 'start tag', tag_name => 'hr'}, |
{type => 'start tag', tag_name => 'hr'}, |
| 2891 |
{type => 'start tag', tag_name => 'p'}, |
{type => 'start tag', tag_name => 'p'}, |
| 2892 |
{type => 'start tag', tag_name => 'label'}, |
{type => 'start tag', tag_name => 'label'}, |
| 2893 |
{type => 'character', |
); |
| 2894 |
data => 'This is a searchable index. Insert your search keywords here: '}, # SHOULD |
if ($prompt_attr) { |
| 2895 |
## TODO: make this configurable |
push @tokens, {type => 'character', data => $prompt_attr->{value}}; |
| 2896 |
|
} else { |
| 2897 |
|
push @tokens, {type => 'character', |
| 2898 |
|
data => 'This is a searchable index. Insert your search keywords here: '}; # SHOULD |
| 2899 |
|
## TODO: make this configurable |
| 2900 |
|
} |
| 2901 |
|
push @tokens, |
| 2902 |
{type => 'start tag', tag_name => 'input', attributes => $at}, |
{type => 'start tag', tag_name => 'input', attributes => $at}, |
| 2903 |
#{type => 'character', data => ''}, # SHOULD |
#{type => 'character', data => ''}, # SHOULD |
| 2904 |
{type => 'end tag', tag_name => 'label'}, |
{type => 'end tag', tag_name => 'label'}, |
| 2905 |
{type => 'end tag', tag_name => 'p'}, |
{type => 'end tag', tag_name => 'p'}, |
| 2906 |
{type => 'start tag', tag_name => 'hr'}, |
{type => 'start tag', tag_name => 'hr'}, |
| 2907 |
{type => 'end tag', tag_name => 'form'}, |
{type => 'end tag', tag_name => 'form'}; |
|
); |
|
| 2908 |
$token = shift @tokens; |
$token = shift @tokens; |
| 2909 |
!!!back-token (@tokens); |
!!!back-token (@tokens); |
| 2910 |
return; |
return; |
| 2995 |
} |
} |
| 2996 |
} elsif ($token->{type} eq 'end tag') { |
} elsif ($token->{type} eq 'end tag') { |
| 2997 |
if ($token->{tag_name} eq 'body') { |
if ($token->{tag_name} eq 'body') { |
| 2998 |
if (@{$self->{open_elements}} > 1 and $self->{open_elements}->[1]->[1] eq 'body') { |
if (@{$self->{open_elements}} > 1 and |
| 2999 |
## ISSUE: There is an issue in the spec. |
$self->{open_elements}->[1]->[1] eq 'body') { |
| 3000 |
if ($self->{open_elements}->[-1]->[1] ne 'body') { |
for (@{$self->{open_elements}}) { |
| 3001 |
!!!parse-error (type => 'not closed:'.$self->{open_elements}->[-1]->[1]); |
unless ({ |
| 3002 |
|
dd => 1, dt => 1, li => 1, p => 1, td => 1, |
| 3003 |
|
th => 1, tr => 1, body => 1, html => 1, |
| 3004 |
|
}->{$_->[1]}) { |
| 3005 |
|
!!!parse-error (type => 'not closed:'.$_->[1]); |
| 3006 |
|
} |
| 3007 |
} |
} |
| 3008 |
|
|
| 3009 |
$self->{insertion_mode} = 'after body'; |
$self->{insertion_mode} = 'after body'; |
| 3010 |
!!!next-token; |
!!!next-token; |
| 3011 |
return; |
return; |
| 3314 |
} |
} |
| 3315 |
redo B; |
redo B; |
| 3316 |
} elsif ($token->{type} eq 'end tag') { |
} elsif ($token->{type} eq 'end tag') { |
| 3317 |
if ($token->{tag_name} eq 'html') { |
if ({head => 1, body => 1, html => 1}->{$token->{tag_name}}) { |
| 3318 |
## As if <head> |
## As if <head> |
| 3319 |
!!!create-element ($self->{head_element}, 'head'); |
!!!create-element ($self->{head_element}, 'head'); |
| 3320 |
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
$self->{open_elements}->[-1]->[0]->append_child ($self->{head_element}); |
| 3324 |
redo B; |
redo B; |
| 3325 |
} else { |
} else { |
| 3326 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
| 3327 |
## Ignore the token |
## Ignore the token ## ISSUE: An issue in the spec. |
| 3328 |
!!!next-token; |
!!!next-token; |
| 3329 |
redo B; |
redo B; |
| 3330 |
} |
} |
| 3411 |
$self->{insertion_mode} = 'after head'; |
$self->{insertion_mode} = 'after head'; |
| 3412 |
!!!next-token; |
!!!next-token; |
| 3413 |
redo B; |
redo B; |
| 3414 |
} elsif ($token->{tag_name} eq 'html') { |
} elsif ($token->{tag_name} eq 'body' or |
| 3415 |
|
$token->{tag_name} eq 'html') { |
| 3416 |
# |
# |
| 3417 |
} else { |
} else { |
| 3418 |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
!!!parse-error (type => 'unmatched end tag:'.$token->{tag_name}); |
| 5128 |
## NOTE: Most of this code is copied from |parse_string| |
## NOTE: Most of this code is copied from |parse_string| |
| 5129 |
|
|
| 5130 |
## Step 1 # MUST |
## Step 1 # MUST |
| 5131 |
my $doc = $node->owner_document->implementation->create_document; |
my $this_doc = $node->owner_document; |
| 5132 |
## TODO: Mark as HTML document |
my $doc = $this_doc->implementation->create_document; |
| 5133 |
|
$doc->manakai_is_html (1); |
| 5134 |
my $p = $class->new; |
my $p = $class->new; |
| 5135 |
$p->{document} = $doc; |
$p->{document} = $doc; |
| 5136 |
|
|
| 5140 |
my $column = 0; |
my $column = 0; |
| 5141 |
$p->{set_next_input_character} = sub { |
$p->{set_next_input_character} = sub { |
| 5142 |
my $self = shift; |
my $self = shift; |
| 5143 |
|
|
| 5144 |
|
pop @{$self->{prev_input_character}}; |
| 5145 |
|
unshift @{$self->{prev_input_character}}, $self->{next_input_character}; |
| 5146 |
|
|
| 5147 |
$self->{next_input_character} = -1 and return if $i >= length $$s; |
$self->{next_input_character} = -1 and return if $i >= length $$s; |
| 5148 |
$self->{next_input_character} = ord substr $$s, $i++, 1; |
$self->{next_input_character} = ord substr $$s, $i++, 1; |
| 5149 |
$column++; |
$column++; |
| 5152 |
$line++; |
$line++; |
| 5153 |
$column = 0; |
$column = 0; |
| 5154 |
} elsif ($self->{next_input_character} == 0x000D) { # CR |
} elsif ($self->{next_input_character} == 0x000D) { # CR |
| 5155 |
if ($i >= length $$s) { |
$i++ if substr ($$s, $i, 1) eq "\x0A"; |
|
# |
|
|
} else { |
|
|
my $next_char = ord substr $$s, $i++, 1; |
|
|
if ($next_char == 0x000A) { # LF |
|
|
# |
|
|
} else { |
|
|
push @{$self->{char}}, $next_char; |
|
|
} |
|
|
} |
|
| 5156 |
$self->{next_input_character} = 0x000A; # LF # MUST |
$self->{next_input_character} = 0x000A; # LF # MUST |
| 5157 |
$line++; |
$line++; |
| 5158 |
$column = 0; |
$column = 0; |
| 5159 |
} elsif ($self->{next_input_character} > 0x10FFFF) { |
} elsif ($self->{next_input_character} > 0x10FFFF) { |
| 5160 |
$self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
$self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
| 5161 |
} elsif ($self->{next_input_character} == 0x0000) { # NULL |
} elsif ($self->{next_input_character} == 0x0000) { # NULL |
| 5162 |
|
!!!parse-error (type => 'NULL'); |
| 5163 |
$self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
$self->{next_input_character} = 0xFFFD; # REPLACEMENT CHARACTER # MUST |
| 5164 |
} |
} |
| 5165 |
}; |
}; |
| 5166 |
|
$p->{prev_input_character} = [-1, -1, -1]; |
| 5167 |
|
$p->{next_input_character} = -1; |
| 5168 |
|
|
| 5169 |
my $ponerror = $onerror || sub { |
my $ponerror = $onerror || sub { |
| 5170 |
my (%opt) = @_; |
my (%opt) = @_; |
| 5243 |
## Step 12 # MUST |
## Step 12 # MUST |
| 5244 |
@cn = @{$root->child_nodes}; |
@cn = @{$root->child_nodes}; |
| 5245 |
for (@cn) { |
for (@cn) { |
| 5246 |
|
$this_doc->adopt_node ($_); |
| 5247 |
$node->append_child ($_); |
$node->append_child ($_); |
| 5248 |
} |
} |
| 5249 |
## ISSUE: adopt_node? mutation events? |
## ISSUE: mutation events? |
| 5250 |
|
|
| 5251 |
$p->_terminate_tree_constructor; |
$p->_terminate_tree_constructor; |
| 5252 |
} else { |
} else { |