| 618 |
sub parse_char_string ($$$;$$) { |
sub parse_char_string ($$$;$$) { |
| 619 |
#my ($self, $s, $doc, $onerror, $get_wrapper) = @_; |
#my ($self, $s, $doc, $onerror, $get_wrapper) = @_; |
| 620 |
my $self = shift; |
my $self = shift; |
|
require utf8; |
|
| 621 |
my $s = ref $_[0] ? $_[0] : \($_[0]); |
my $s = ref $_[0] ? $_[0] : \($_[0]); |
| 622 |
open my $input, '<' . (utf8::is_utf8 ($$s) ? ':utf8' : ''), $s; |
require Whatpm::Charset::DecodeHandle; |
| 623 |
|
my $input = Whatpm::Charset::DecodeHandle::CharString->new ($s); |
| 624 |
if ($_[3]) { |
if ($_[3]) { |
| 625 |
$input = $_[3]->($input); |
$input = $_[3]->($input); |
| 626 |
} |
} |
| 669 |
$self->{column} = 0; |
$self->{column} = 0; |
| 670 |
} elsif ($self->{next_char} == 0x000D) { # CR |
} elsif ($self->{next_char} == 0x000D) { # CR |
| 671 |
!!!cp ('j2'); |
!!!cp ('j2'); |
| 672 |
|
## TODO: support for abort/streaming |
| 673 |
my $next = $input->getc; |
my $next = $input->getc; |
| 674 |
if (defined $next and $next ne "\x0A") { |
if (defined $next and $next ne "\x0A") { |
| 675 |
$self->{next_next_char} = $next; |
$self->{next_next_char} = $next; |
| 689 |
(0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or |
(0x007F <= $self->{next_char} and $self->{next_char} <= 0x009F) or |
| 690 |
(0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or |
(0xD800 <= $self->{next_char} and $self->{next_char} <= 0xDFFF) or |
| 691 |
(0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or |
(0xFDD0 <= $self->{next_char} and $self->{next_char} <= 0xFDDF) or |
| 692 |
|
## ISSUE: U+FDE0-U+FDEF are not excluded |
| 693 |
{ |
{ |
| 694 |
0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1, |
0xFFFE => 1, 0xFFFF => 1, 0x1FFFE => 1, 0x1FFFF => 1, |
| 695 |
0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1, |
0x2FFFE => 1, 0x2FFFF => 1, 0x3FFFE => 1, 0x3FFFF => 1, |
| 714 |
$self->{prev_char} = [-1, -1, -1]; |
$self->{prev_char} = [-1, -1, -1]; |
| 715 |
$self->{next_char} = -1; |
$self->{next_char} = -1; |
| 716 |
|
|
| 717 |
|
$self->{read_until} = sub { |
| 718 |
|
#my ($scalar, $specials_range, $offset) = @_; |
| 719 |
|
my $specials_range = $_[1]; |
| 720 |
|
return 0 if defined $self->{next_next_char}; |
| 721 |
|
my $count = $input->manakai_read_until |
| 722 |
|
($_[0], |
| 723 |
|
qr/(?![$specials_range\x{FDD0}-\x{FDDF}\x{FFFE}\x{FFFF}\x{1FFFE}\x{1FFFF}\x{2FFFE}\x{2FFFF}\x{3FFFE}\x{3FFFF}\x{4FFFE}\x{4FFFF}\x{5FFFE}\x{5FFFF}\x{6FFFE}\x{6FFFF}\x{7FFFE}\x{7FFFF}\x{8FFFE}\x{8FFFF}\x{9FFFE}\x{9FFFF}\x{AFFFE}\x{AFFFF}\x{BFFFE}\x{BFFFF}\x{CFFFE}\x{CFFFF}\x{DFFFE}\x{DFFFF}\x{EFFFE}\x{EFFFF}\x{FFFFE}\x{FFFFF}])[\x20-\x7E\xA0-\x{D7FF}\x{E000}-\x{10FFFD}]/, |
| 724 |
|
$_[2]); |
| 725 |
|
if ($count) { |
| 726 |
|
$self->{column} += $count; |
| 727 |
|
$self->{column_prev} += $count; |
| 728 |
|
$self->{prev_char} = [-1, -1, -1]; |
| 729 |
|
$self->{next_char} = -1; |
| 730 |
|
} |
| 731 |
|
return $count; |
| 732 |
|
}; # $self->{read_until} |
| 733 |
|
|
| 734 |
my $onerror = $_[2] || sub { |
my $onerror = $_[2] || sub { |
| 735 |
my (%opt) = @_; |
my (%opt) = @_; |
| 736 |
my $line = $opt{token} ? $opt{token}->{line} : $opt{line}; |
my $line = $opt{token} ? $opt{token}->{line} : $opt{line}; |
| 788 |
sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP } |
sub PCDATA_CONTENT_MODEL () { CM_ENTITY | CM_FULL_MARKUP } |
| 789 |
|
|
| 790 |
sub DATA_STATE () { 0 } |
sub DATA_STATE () { 0 } |
| 791 |
sub ENTITY_DATA_STATE () { 1 } |
#sub ENTITY_DATA_STATE () { 1 } |
| 792 |
sub TAG_OPEN_STATE () { 2 } |
sub TAG_OPEN_STATE () { 2 } |
| 793 |
sub CLOSE_TAG_OPEN_STATE () { 3 } |
sub CLOSE_TAG_OPEN_STATE () { 3 } |
| 794 |
sub TAG_NAME_STATE () { 4 } |
sub TAG_NAME_STATE () { 4 } |
| 799 |
sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 } |
sub ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE () { 9 } |
| 800 |
sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 } |
sub ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE () { 10 } |
| 801 |
sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 } |
sub ATTRIBUTE_VALUE_UNQUOTED_STATE () { 11 } |
| 802 |
sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 } |
#sub ENTITY_IN_ATTRIBUTE_VALUE_STATE () { 12 } |
| 803 |
sub MARKUP_DECLARATION_OPEN_STATE () { 13 } |
sub MARKUP_DECLARATION_OPEN_STATE () { 13 } |
| 804 |
sub COMMENT_START_STATE () { 14 } |
sub COMMENT_START_STATE () { 14 } |
| 805 |
sub COMMENT_START_DASH_STATE () { 15 } |
sub COMMENT_START_DASH_STATE () { 15 } |
| 829 |
sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec |
sub CDATA_PCDATA_CLOSE_TAG_STATE () { 39 } # "close tag open state" in the spec |
| 830 |
sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec |
sub CDATA_SECTION_MSE1_STATE () { 40 } # "CDATA section state" in the spec |
| 831 |
sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec |
sub CDATA_SECTION_MSE2_STATE () { 41 } # "CDATA section state" in the spec |
| 832 |
|
sub PUBLIC_STATE () { 42 } # "after DOCTYPE name state" in the spec |
| 833 |
|
sub SYSTEM_STATE () { 43 } # "after DOCTYPE name state" in the spec |
| 834 |
|
## NOTE: "Entity data state", "entity in attribute value state", and |
| 835 |
|
## "consume a character reference" algorithm are jointly implemented |
| 836 |
|
## using the following six states: |
| 837 |
|
sub ENTITY_STATE () { 44 } |
| 838 |
|
sub ENTITY_HASH_STATE () { 45 } |
| 839 |
|
sub NCR_NUM_STATE () { 46 } |
| 840 |
|
sub HEXREF_X_STATE () { 47 } |
| 841 |
|
sub HEXREF_HEX_STATE () { 48 } |
| 842 |
|
sub ENTITY_NAME_STATE () { 49 } |
| 843 |
|
|
| 844 |
sub DOCTYPE_TOKEN () { 1 } |
sub DOCTYPE_TOKEN () { 1 } |
| 845 |
sub COMMENT_TOKEN () { 2 } |
sub COMMENT_TOKEN () { 2 } |
| 893 |
my $self = shift; |
my $self = shift; |
| 894 |
$self->{state} = DATA_STATE; # MUST |
$self->{state} = DATA_STATE; # MUST |
| 895 |
#$self->{state_keyword}; # initialized when used |
#$self->{state_keyword}; # initialized when used |
| 896 |
|
#$self->{entity__value}; # initialized when used |
| 897 |
|
#$self->{entity__match}; # initialized when used |
| 898 |
$self->{content_model} = PCDATA_CONTENT_MODEL; # be |
$self->{content_model} = PCDATA_CONTENT_MODEL; # be |
| 899 |
undef $self->{current_token}; |
undef $self->{current_token}; |
| 900 |
undef $self->{current_attribute}; |
undef $self->{current_attribute}; |
| 901 |
undef $self->{last_emitted_start_tag_name}; |
undef $self->{last_emitted_start_tag_name}; |
| 902 |
undef $self->{last_attribute_value_state}; |
#$self->{prev_state}; # initialized when used |
| 903 |
delete $self->{self_closing}; |
delete $self->{self_closing}; |
|
$self->{char} = []; |
|
| 904 |
# $self->{next_char} |
# $self->{next_char} |
| 905 |
!!!next-input-character; |
!!!next-input-character; |
| 906 |
$self->{token} = []; |
$self->{token} = []; |
| 932 |
## has completed loading. If one has, then it MUST be executed |
## has completed loading. If one has, then it MUST be executed |
| 933 |
## and removed from the list. |
## and removed from the list. |
| 934 |
|
|
| 935 |
## NOTE: HTML5 "Writing HTML documents" section, applied to |
## TODO: Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) |
| 936 |
## documents and not to user agents and conformance checkers, |
## (This requirement was dropped from HTML5 spec, unfortunately.) |
|
## contains some requirements that are not detected by the |
|
|
## parsing algorithm: |
|
|
## - Some requirements on character encoding declarations. ## TODO |
|
|
## - "Elements MUST NOT contain content that their content model disallows." |
|
|
## ... Some are parse error, some are not (will be reported by c.c.). |
|
|
## - Polytheistic slash SHOULD NOT be used. (Applied only to atheists.) ## TODO |
|
|
## - Text (in elements, attributes, and comments) SHOULD NOT contain |
|
|
## control characters other than space characters. ## TODO: (what is control character? C0, C1 and DEL? Unicode control character?) |
|
|
|
|
|
## TODO: HTML5 poses authors two SHOULD-level requirements that cannot |
|
|
## be detected by the HTML5 parsing algorithm: |
|
|
## - Text, |
|
| 937 |
|
|
| 938 |
sub _get_next_token ($) { |
sub _get_next_token ($) { |
| 939 |
my $self = shift; |
my $self = shift; |
| 957 |
if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA |
if ($self->{content_model} & CM_ENTITY and # PCDATA | RCDATA |
| 958 |
not $self->{escape}) { |
not $self->{escape}) { |
| 959 |
!!!cp (1); |
!!!cp (1); |
| 960 |
$self->{state} = ENTITY_DATA_STATE; |
## NOTE: In the spec, the tokenizer is switched to the |
| 961 |
|
## "entity data state". In this implementation, the tokenizer |
| 962 |
|
## is switched to the |ENTITY_STATE|, which is an implementation |
| 963 |
|
## of the "consume a character reference" algorithm. |
| 964 |
|
$self->{entity_additional} = -1; |
| 965 |
|
$self->{prev_state} = DATA_STATE; |
| 966 |
|
$self->{state} = ENTITY_STATE; |
| 967 |
!!!next-input-character; |
!!!next-input-character; |
| 968 |
redo A; |
redo A; |
| 969 |
} else { |
} else { |
| 1027 |
data => chr $self->{next_char}, |
data => chr $self->{next_char}, |
| 1028 |
line => $self->{line}, column => $self->{column}, |
line => $self->{line}, column => $self->{column}, |
| 1029 |
}; |
}; |
| 1030 |
|
$self->{read_until}->($token->{data}, q[-!<>&], length $token->{data}); |
| 1031 |
|
|
| 1032 |
## Stay in the data state |
## Stay in the data state |
| 1033 |
!!!next-input-character; |
!!!next-input-character; |
| 1034 |
|
|
| 1035 |
!!!emit ($token); |
!!!emit ($token); |
| 1036 |
|
|
| 1037 |
redo A; |
redo A; |
|
} elsif ($self->{state} == ENTITY_DATA_STATE) { |
|
|
## (cannot happen in CDATA state) |
|
|
|
|
|
my ($l, $c) = ($self->{line_prev}, $self->{column_prev}); |
|
|
|
|
|
my $token = $self->_tokenize_attempt_to_consume_an_entity (0, -1); |
|
|
|
|
|
$self->{state} = DATA_STATE; |
|
|
# next-input-character is already done |
|
|
|
|
|
unless (defined $token) { |
|
|
!!!cp (13); |
|
|
!!!emit ({type => CHARACTER_TOKEN, data => '&', |
|
|
line => $l, column => $c, |
|
|
}); |
|
|
} else { |
|
|
!!!cp (14); |
|
|
!!!emit ($token); |
|
|
} |
|
|
|
|
|
redo A; |
|
| 1038 |
} elsif ($self->{state} == TAG_OPEN_STATE) { |
} elsif ($self->{state} == TAG_OPEN_STATE) { |
| 1039 |
if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
if ($self->{content_model} & CM_LIMITED_MARKUP) { # RCDATA | CDATA |
| 1040 |
if ($self->{next_char} == 0x002F) { # / |
if ($self->{next_char} == 0x002F) { # / |
| 1708 |
redo A; |
redo A; |
| 1709 |
} elsif ($self->{next_char} == 0x0026) { # & |
} elsif ($self->{next_char} == 0x0026) { # & |
| 1710 |
!!!cp (96); |
!!!cp (96); |
| 1711 |
$self->{last_attribute_value_state} = $self->{state}; |
## NOTE: In the spec, the tokenizer is switched to the |
| 1712 |
$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
## "entity in attribute value state". In this implementation, the |
| 1713 |
|
## tokenizer is switched to the |ENTITY_STATE|, which is an |
| 1714 |
|
## implementation of the "consume a character reference" algorithm. |
| 1715 |
|
$self->{prev_state} = $self->{state}; |
| 1716 |
|
$self->{entity_additional} = 0x0022; # " |
| 1717 |
|
$self->{state} = ENTITY_STATE; |
| 1718 |
!!!next-input-character; |
!!!next-input-character; |
| 1719 |
redo A; |
redo A; |
| 1720 |
} elsif ($self->{next_char} == -1) { |
} elsif ($self->{next_char} == -1) { |
| 1755 |
redo A; |
redo A; |
| 1756 |
} elsif ($self->{next_char} == 0x0026) { # & |
} elsif ($self->{next_char} == 0x0026) { # & |
| 1757 |
!!!cp (102); |
!!!cp (102); |
| 1758 |
$self->{last_attribute_value_state} = $self->{state}; |
## NOTE: In the spec, the tokenizer is switched to the |
| 1759 |
$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
## "entity in attribute value state". In this implementation, the |
| 1760 |
|
## tokenizer is switched to the |ENTITY_STATE|, which is an |
| 1761 |
|
## implementation of the "consume a character reference" algorithm. |
| 1762 |
|
$self->{entity_additional} = 0x0027; # ' |
| 1763 |
|
$self->{prev_state} = $self->{state}; |
| 1764 |
|
$self->{state} = ENTITY_STATE; |
| 1765 |
!!!next-input-character; |
!!!next-input-character; |
| 1766 |
redo A; |
redo A; |
| 1767 |
} elsif ($self->{next_char} == -1) { |
} elsif ($self->{next_char} == -1) { |
| 1806 |
redo A; |
redo A; |
| 1807 |
} elsif ($self->{next_char} == 0x0026) { # & |
} elsif ($self->{next_char} == 0x0026) { # & |
| 1808 |
!!!cp (108); |
!!!cp (108); |
| 1809 |
$self->{last_attribute_value_state} = $self->{state}; |
## NOTE: In the spec, the tokenizer is switched to the |
| 1810 |
$self->{state} = ENTITY_IN_ATTRIBUTE_VALUE_STATE; |
## "entity in attribute value state". In this implementation, the |
| 1811 |
|
## tokenizer is switched to the |ENTITY_STATE|, which is an |
| 1812 |
|
## implementation of the "consume a character reference" algorithm. |
| 1813 |
|
$self->{entity_additional} = -1; |
| 1814 |
|
$self->{prev_state} = $self->{state}; |
| 1815 |
|
$self->{state} = ENTITY_STATE; |
| 1816 |
!!!next-input-character; |
!!!next-input-character; |
| 1817 |
redo A; |
redo A; |
| 1818 |
} elsif ($self->{next_char} == 0x003E) { # > |
} elsif ($self->{next_char} == 0x003E) { # > |
| 1876 |
!!!next-input-character; |
!!!next-input-character; |
| 1877 |
redo A; |
redo A; |
| 1878 |
} |
} |
|
} elsif ($self->{state} == ENTITY_IN_ATTRIBUTE_VALUE_STATE) { |
|
|
my $token = $self->_tokenize_attempt_to_consume_an_entity |
|
|
(1, |
|
|
$self->{last_attribute_value_state} |
|
|
== ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE ? 0x0022 : # " |
|
|
$self->{last_attribute_value_state} |
|
|
== ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE ? 0x0027 : # ' |
|
|
-1); |
|
|
|
|
|
unless (defined $token) { |
|
|
!!!cp (117); |
|
|
$self->{current_attribute}->{value} .= '&'; |
|
|
} else { |
|
|
!!!cp (118); |
|
|
$self->{current_attribute}->{value} .= $token->{data}; |
|
|
$self->{current_attribute}->{has_reference} = $token->{has_reference}; |
|
|
## ISSUE: spec says "append the returned character token to the current attribute's value" |
|
|
} |
|
|
|
|
|
$self->{state} = $self->{last_attribute_value_state}; |
|
|
# next-input-character is already done |
|
|
redo A; |
|
| 1879 |
} elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) { |
} elsif ($self->{state} == AFTER_ATTRIBUTE_VALUE_QUOTED_STATE) { |
| 1880 |
if ($self->{next_char} == 0x0009 or # HT |
if ($self->{next_char} == 0x0009 or # HT |
| 1881 |
$self->{next_char} == 0x000A or # LF |
$self->{next_char} == 0x000A or # LF |
| 1995 |
} |
} |
| 1996 |
} elsif ($self->{state} == BOGUS_COMMENT_STATE) { |
} elsif ($self->{state} == BOGUS_COMMENT_STATE) { |
| 1997 |
## (only happen if PCDATA state) |
## (only happen if PCDATA state) |
|
|
|
|
## NOTE: Set by the previous state |
|
|
#my $token = {type => COMMENT_TOKEN, data => ''}; |
|
|
|
|
|
BC: { |
|
|
if ($self->{next_char} == 0x003E) { # > |
|
|
!!!cp (124); |
|
|
$self->{state} = DATA_STATE; |
|
|
!!!next-input-character; |
|
|
|
|
|
!!!emit ($self->{current_token}); # comment |
|
|
|
|
|
redo A; |
|
|
} elsif ($self->{next_char} == -1) { |
|
|
!!!cp (125); |
|
|
$self->{state} = DATA_STATE; |
|
|
## reconsume |
|
| 1998 |
|
|
| 1999 |
!!!emit ($self->{current_token}); # comment |
## NOTE: Unlike spec's "bogus comment state", this implementation |
| 2000 |
|
## consumes characters one-by-one basis. |
| 2001 |
|
|
| 2002 |
|
if ($self->{next_char} == 0x003E) { # > |
| 2003 |
|
!!!cp (124); |
| 2004 |
|
$self->{state} = DATA_STATE; |
| 2005 |
|
!!!next-input-character; |
| 2006 |
|
|
| 2007 |
redo A; |
!!!emit ($self->{current_token}); # comment |
| 2008 |
} else { |
redo A; |
| 2009 |
!!!cp (126); |
} elsif ($self->{next_char} == -1) { |
| 2010 |
$self->{current_token}->{data} .= chr ($self->{next_char}); # comment |
!!!cp (125); |
| 2011 |
!!!next-input-character; |
$self->{state} = DATA_STATE; |
| 2012 |
redo BC; |
## reconsume |
|
} |
|
|
} # BC |
|
| 2013 |
|
|
| 2014 |
die "$0: _get_next_token: unexpected case [BC]"; |
!!!emit ($self->{current_token}); # comment |
| 2015 |
|
redo A; |
| 2016 |
|
} else { |
| 2017 |
|
!!!cp (126); |
| 2018 |
|
$self->{current_token}->{data} .= chr ($self->{next_char}); # comment |
| 2019 |
|
## Stay in the state. |
| 2020 |
|
!!!next-input-character; |
| 2021 |
|
redo A; |
| 2022 |
|
} |
| 2023 |
} elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) { |
} elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) { |
| 2024 |
## (only happen if PCDATA state) |
## (only happen if PCDATA state) |
| 2025 |
|
|
| 2434 |
redo A; |
redo A; |
| 2435 |
} elsif ($self->{next_char} == 0x0050 or # P |
} elsif ($self->{next_char} == 0x0050 or # P |
| 2436 |
$self->{next_char} == 0x0070) { # p |
$self->{next_char} == 0x0070) { # p |
| 2437 |
|
$self->{state} = PUBLIC_STATE; |
| 2438 |
|
$self->{state_keyword} = chr $self->{next_char}; |
| 2439 |
!!!next-input-character; |
!!!next-input-character; |
| 2440 |
if ($self->{next_char} == 0x0055 or # U |
redo A; |
|
$self->{next_char} == 0x0075) { # u |
|
|
!!!next-input-character; |
|
|
if ($self->{next_char} == 0x0042 or # B |
|
|
$self->{next_char} == 0x0062) { # b |
|
|
!!!next-input-character; |
|
|
if ($self->{next_char} == 0x004C or # L |
|
|
$self->{next_char} == 0x006C) { # l |
|
|
!!!next-input-character; |
|
|
if ($self->{next_char} == 0x0049 or # I |
|
|
$self->{next_char} == 0x0069) { # i |
|
|
!!!next-input-character; |
|
|
if ($self->{next_char} == 0x0043 or # C |
|
|
$self->{next_char} == 0x0063) { # c |
|
|
!!!cp (168); |
|
|
$self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE; |
|
|
!!!next-input-character; |
|
|
redo A; |
|
|
} else { |
|
|
!!!cp (169); |
|
|
} |
|
|
} else { |
|
|
!!!cp (170); |
|
|
} |
|
|
} else { |
|
|
!!!cp (171); |
|
|
} |
|
|
} else { |
|
|
!!!cp (172); |
|
|
} |
|
|
} else { |
|
|
!!!cp (173); |
|
|
} |
|
|
|
|
|
# |
|
| 2441 |
} elsif ($self->{next_char} == 0x0053 or # S |
} elsif ($self->{next_char} == 0x0053 or # S |
| 2442 |
$self->{next_char} == 0x0073) { # s |
$self->{next_char} == 0x0073) { # s |
| 2443 |
|
$self->{state} = SYSTEM_STATE; |
| 2444 |
|
$self->{state_keyword} = chr $self->{next_char}; |
| 2445 |
!!!next-input-character; |
!!!next-input-character; |
| 2446 |
if ($self->{next_char} == 0x0059 or # Y |
redo A; |
|
$self->{next_char} == 0x0079) { # y |
|
|
!!!next-input-character; |
|
|
if ($self->{next_char} == 0x0053 or # S |
|
|
$self->{next_char} == 0x0073) { # s |
|
|
!!!next-input-character; |
|
|
if ($self->{next_char} == 0x0054 or # T |
|
|
$self->{next_char} == 0x0074) { # t |
|
|
!!!next-input-character; |
|
|
if ($self->{next_char} == 0x0045 or # E |
|
|
$self->{next_char} == 0x0065) { # e |
|
|
!!!next-input-character; |
|
|
if ($self->{next_char} == 0x004D or # M |
|
|
$self->{next_char} == 0x006D) { # m |
|
|
!!!cp (174); |
|
|
$self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE; |
|
|
!!!next-input-character; |
|
|
redo A; |
|
|
} else { |
|
|
!!!cp (175); |
|
|
} |
|
|
} else { |
|
|
!!!cp (176); |
|
|
} |
|
|
} else { |
|
|
!!!cp (177); |
|
|
} |
|
|
} else { |
|
|
!!!cp (178); |
|
|
} |
|
|
} else { |
|
|
!!!cp (179); |
|
|
} |
|
|
|
|
|
# |
|
| 2447 |
} else { |
} else { |
| 2448 |
!!!cp (180); |
!!!cp (180); |
| 2449 |
|
!!!parse-error (type => 'string after DOCTYPE name'); |
| 2450 |
|
$self->{current_token}->{quirks} = 1; |
| 2451 |
|
|
| 2452 |
|
$self->{state} = BOGUS_DOCTYPE_STATE; |
| 2453 |
!!!next-input-character; |
!!!next-input-character; |
| 2454 |
# |
redo A; |
| 2455 |
} |
} |
| 2456 |
|
} elsif ($self->{state} == PUBLIC_STATE) { |
| 2457 |
|
## ASCII case-insensitive |
| 2458 |
|
if ($self->{next_char} == [ |
| 2459 |
|
undef, |
| 2460 |
|
0x0055, # U |
| 2461 |
|
0x0042, # B |
| 2462 |
|
0x004C, # L |
| 2463 |
|
0x0049, # I |
| 2464 |
|
]->[length $self->{state_keyword}] or |
| 2465 |
|
$self->{next_char} == [ |
| 2466 |
|
undef, |
| 2467 |
|
0x0075, # u |
| 2468 |
|
0x0062, # b |
| 2469 |
|
0x006C, # l |
| 2470 |
|
0x0069, # i |
| 2471 |
|
]->[length $self->{state_keyword}]) { |
| 2472 |
|
!!!cp (175); |
| 2473 |
|
## Stay in the state. |
| 2474 |
|
$self->{state_keyword} .= chr $self->{next_char}; |
| 2475 |
|
!!!next-input-character; |
| 2476 |
|
redo A; |
| 2477 |
|
} elsif ((length $self->{state_keyword}) == 5 and |
| 2478 |
|
($self->{next_char} == 0x0043 or # C |
| 2479 |
|
$self->{next_char} == 0x0063)) { # c |
| 2480 |
|
!!!cp (168); |
| 2481 |
|
$self->{state} = BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE; |
| 2482 |
|
!!!next-input-character; |
| 2483 |
|
redo A; |
| 2484 |
|
} else { |
| 2485 |
|
!!!cp (169); |
| 2486 |
|
!!!parse-error (type => 'string after DOCTYPE name', |
| 2487 |
|
line => $self->{line_prev}, |
| 2488 |
|
column => $self->{column_prev} + 1 - length $self->{state_keyword}); |
| 2489 |
|
$self->{current_token}->{quirks} = 1; |
| 2490 |
|
|
| 2491 |
!!!parse-error (type => 'string after DOCTYPE name'); |
$self->{state} = BOGUS_DOCTYPE_STATE; |
| 2492 |
$self->{current_token}->{quirks} = 1; |
## Reconsume. |
| 2493 |
|
redo A; |
| 2494 |
|
} |
| 2495 |
|
} elsif ($self->{state} == SYSTEM_STATE) { |
| 2496 |
|
## ASCII case-insensitive |
| 2497 |
|
if ($self->{next_char} == [ |
| 2498 |
|
undef, |
| 2499 |
|
0x0059, # Y |
| 2500 |
|
0x0053, # S |
| 2501 |
|
0x0054, # T |
| 2502 |
|
0x0045, # E |
| 2503 |
|
]->[length $self->{state_keyword}] or |
| 2504 |
|
$self->{next_char} == [ |
| 2505 |
|
undef, |
| 2506 |
|
0x0079, # y |
| 2507 |
|
0x0073, # s |
| 2508 |
|
0x0074, # t |
| 2509 |
|
0x0065, # e |
| 2510 |
|
]->[length $self->{state_keyword}]) { |
| 2511 |
|
!!!cp (170); |
| 2512 |
|
## Stay in the state. |
| 2513 |
|
$self->{state_keyword} .= chr $self->{next_char}; |
| 2514 |
|
!!!next-input-character; |
| 2515 |
|
redo A; |
| 2516 |
|
} elsif ((length $self->{state_keyword}) == 5 and |
| 2517 |
|
($self->{next_char} == 0x004D or # M |
| 2518 |
|
$self->{next_char} == 0x006D)) { # m |
| 2519 |
|
!!!cp (171); |
| 2520 |
|
$self->{state} = BEFORE_DOCTYPE_SYSTEM_IDENTIFIER_STATE; |
| 2521 |
|
!!!next-input-character; |
| 2522 |
|
redo A; |
| 2523 |
|
} else { |
| 2524 |
|
!!!cp (172); |
| 2525 |
|
!!!parse-error (type => 'string after DOCTYPE name', |
| 2526 |
|
line => $self->{line_prev}, |
| 2527 |
|
column => $self->{column_prev} + 1 - length $self->{state_keyword}); |
| 2528 |
|
$self->{current_token}->{quirks} = 1; |
| 2529 |
|
|
| 2530 |
$self->{state} = BOGUS_DOCTYPE_STATE; |
$self->{state} = BOGUS_DOCTYPE_STATE; |
| 2531 |
# next-input-character is already done |
## Reconsume. |
| 2532 |
redo A; |
redo A; |
| 2533 |
|
} |
| 2534 |
} elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) { |
} elsif ($self->{state} == BEFORE_DOCTYPE_PUBLIC_IDENTIFIER_STATE) { |
| 2535 |
if ({ |
if ({ |
| 2536 |
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, 0x0020 => 1, |
| 2955 |
## Reconsume. |
## Reconsume. |
| 2956 |
redo A; |
redo A; |
| 2957 |
} |
} |
| 2958 |
} else { |
} elsif ($self->{state} == ENTITY_STATE) { |
| 2959 |
die "$0: $self->{state}: Unknown state"; |
if ({ |
| 2960 |
} |
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF, |
| 2961 |
} # A |
0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & |
| 2962 |
|
$self->{entity_additional} => 1, |
| 2963 |
die "$0: _get_next_token: unexpected case"; |
}->{$self->{next_char}}) { |
| 2964 |
} # _get_next_token |
!!!cp (1001); |
| 2965 |
|
## Don't consume |
| 2966 |
sub _tokenize_attempt_to_consume_an_entity ($$$) { |
## No error |
| 2967 |
my ($self, $in_attr, $additional) = @_; |
## Return nothing. |
| 2968 |
|
# |
| 2969 |
|
} elsif ($self->{next_char} == 0x0023) { # # |
| 2970 |
|
!!!cp (999); |
| 2971 |
|
$self->{state} = ENTITY_HASH_STATE; |
| 2972 |
|
$self->{state_keyword} = '#'; |
| 2973 |
|
!!!next-input-character; |
| 2974 |
|
redo A; |
| 2975 |
|
} elsif ((0x0041 <= $self->{next_char} and |
| 2976 |
|
$self->{next_char} <= 0x005A) or # A..Z |
| 2977 |
|
(0x0061 <= $self->{next_char} and |
| 2978 |
|
$self->{next_char} <= 0x007A)) { # a..z |
| 2979 |
|
!!!cp (998); |
| 2980 |
|
require Whatpm::_NamedEntityList; |
| 2981 |
|
$self->{state} = ENTITY_NAME_STATE; |
| 2982 |
|
$self->{state_keyword} = chr $self->{next_char}; |
| 2983 |
|
$self->{entity__value} = $self->{state_keyword}; |
| 2984 |
|
$self->{entity__match} = 0; |
| 2985 |
|
!!!next-input-character; |
| 2986 |
|
redo A; |
| 2987 |
|
} else { |
| 2988 |
|
!!!cp (1027); |
| 2989 |
|
!!!parse-error (type => 'bare ero'); |
| 2990 |
|
## Return nothing. |
| 2991 |
|
# |
| 2992 |
|
} |
| 2993 |
|
|
| 2994 |
my ($l, $c) = ($self->{line_prev}, $self->{column_prev}); |
## NOTE: No character is consumed by the "consume a character |
| 2995 |
|
## reference" algorithm. In other word, there is an "&" character |
| 2996 |
|
## that does not introduce a character reference, which would be |
| 2997 |
|
## appended to the parent element or the attribute value in later |
| 2998 |
|
## process of the tokenizer. |
| 2999 |
|
|
| 3000 |
|
if ($self->{prev_state} == DATA_STATE) { |
| 3001 |
|
!!!cp (997); |
| 3002 |
|
$self->{state} = $self->{prev_state}; |
| 3003 |
|
## Reconsume. |
| 3004 |
|
!!!emit ({type => CHARACTER_TOKEN, data => '&', |
| 3005 |
|
line => $self->{line_prev}, |
| 3006 |
|
column => $self->{column_prev}, |
| 3007 |
|
}); |
| 3008 |
|
redo A; |
| 3009 |
|
} else { |
| 3010 |
|
!!!cp (996); |
| 3011 |
|
$self->{current_attribute}->{value} .= '&'; |
| 3012 |
|
$self->{state} = $self->{prev_state}; |
| 3013 |
|
## Reconsume. |
| 3014 |
|
redo A; |
| 3015 |
|
} |
| 3016 |
|
} elsif ($self->{state} == ENTITY_HASH_STATE) { |
| 3017 |
|
if ($self->{next_char} == 0x0078 or # x |
| 3018 |
|
$self->{next_char} == 0x0058) { # X |
| 3019 |
|
!!!cp (995); |
| 3020 |
|
$self->{state} = HEXREF_X_STATE; |
| 3021 |
|
$self->{state_keyword} .= chr $self->{next_char}; |
| 3022 |
|
!!!next-input-character; |
| 3023 |
|
redo A; |
| 3024 |
|
} elsif (0x0030 <= $self->{next_char} and |
| 3025 |
|
$self->{next_char} <= 0x0039) { # 0..9 |
| 3026 |
|
!!!cp (994); |
| 3027 |
|
$self->{state} = NCR_NUM_STATE; |
| 3028 |
|
$self->{state_keyword} = $self->{next_char} - 0x0030; |
| 3029 |
|
!!!next-input-character; |
| 3030 |
|
redo A; |
| 3031 |
|
} else { |
| 3032 |
|
!!!parse-error (type => 'bare nero', |
| 3033 |
|
line => $self->{line_prev}, |
| 3034 |
|
column => $self->{column_prev} - 1); |
| 3035 |
|
|
| 3036 |
if ({ |
## NOTE: According to the spec algorithm, nothing is returned, |
| 3037 |
0x0009 => 1, 0x000A => 1, 0x000B => 1, 0x000C => 1, # HT, LF, VT, FF, |
## and then "&#" is appended to the parent element or the attribute |
| 3038 |
0x0020 => 1, 0x003C => 1, 0x0026 => 1, -1 => 1, # SP, <, & # 0x000D # CR |
## value in the later processing. |
| 3039 |
$additional => 1, |
|
| 3040 |
}->{$self->{next_char}}) { |
if ($self->{prev_state} == DATA_STATE) { |
| 3041 |
!!!cp (1001); |
!!!cp (1019); |
| 3042 |
## Don't consume |
$self->{state} = $self->{prev_state}; |
| 3043 |
## No error |
## Reconsume. |
| 3044 |
return undef; |
!!!emit ({type => CHARACTER_TOKEN, |
| 3045 |
} elsif ($self->{next_char} == 0x0023) { # # |
data => '&#', |
| 3046 |
!!!next-input-character; |
line => $self->{line_prev}, |
| 3047 |
if ($self->{next_char} == 0x0078 or # x |
column => $self->{column_prev} - 1, |
| 3048 |
$self->{next_char} == 0x0058) { # X |
}); |
| 3049 |
my $code; |
redo A; |
|
X: { |
|
|
my $x_char = $self->{next_char}; |
|
|
!!!next-input-character; |
|
|
if (0x0030 <= $self->{next_char} and |
|
|
$self->{next_char} <= 0x0039) { # 0..9 |
|
|
!!!cp (1002); |
|
|
$code ||= 0; |
|
|
$code *= 0x10; |
|
|
$code += $self->{next_char} - 0x0030; |
|
|
redo X; |
|
|
} elsif (0x0061 <= $self->{next_char} and |
|
|
$self->{next_char} <= 0x0066) { # a..f |
|
|
!!!cp (1003); |
|
|
$code ||= 0; |
|
|
$code *= 0x10; |
|
|
$code += $self->{next_char} - 0x0060 + 9; |
|
|
redo X; |
|
|
} elsif (0x0041 <= $self->{next_char} and |
|
|
$self->{next_char} <= 0x0046) { # A..F |
|
|
!!!cp (1004); |
|
|
$code ||= 0; |
|
|
$code *= 0x10; |
|
|
$code += $self->{next_char} - 0x0040 + 9; |
|
|
redo X; |
|
|
} elsif (not defined $code) { # no hexadecimal digit |
|
|
!!!cp (1005); |
|
|
!!!parse-error (type => 'bare hcro', line => $l, column => $c); |
|
|
!!!back-next-input-character ($x_char, $self->{next_char}); |
|
|
$self->{next_char} = 0x0023; # # |
|
|
return undef; |
|
|
} elsif ($self->{next_char} == 0x003B) { # ; |
|
|
!!!cp (1006); |
|
|
!!!next-input-character; |
|
| 3050 |
} else { |
} else { |
| 3051 |
!!!cp (1007); |
!!!cp (993); |
| 3052 |
!!!parse-error (type => 'no refc', line => $l, column => $c); |
$self->{current_attribute}->{value} .= '&#'; |
| 3053 |
|
$self->{state} = $self->{prev_state}; |
| 3054 |
|
## Reconsume. |
| 3055 |
|
redo A; |
| 3056 |
} |
} |
| 3057 |
|
} |
| 3058 |
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
} elsif ($self->{state} == NCR_NUM_STATE) { |
| 3059 |
!!!cp (1008); |
if (0x0030 <= $self->{next_char} and |
| 3060 |
!!!parse-error (type => 'invalid character reference', |
$self->{next_char} <= 0x0039) { # 0..9 |
|
text => (sprintf 'U+%04X', $code), |
|
|
line => $l, column => $c); |
|
|
$code = 0xFFFD; |
|
|
} elsif ($code > 0x10FFFF) { |
|
|
!!!cp (1009); |
|
|
!!!parse-error (type => 'invalid character reference', |
|
|
text => (sprintf 'U-%08X', $code), |
|
|
line => $l, column => $c); |
|
|
$code = 0xFFFD; |
|
|
} elsif ($code == 0x000D) { |
|
|
!!!cp (1010); |
|
|
!!!parse-error (type => 'CR character reference', line => $l, column => $c); |
|
|
$code = 0x000A; |
|
|
} elsif (0x80 <= $code and $code <= 0x9F) { |
|
|
!!!cp (1011); |
|
|
!!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c); |
|
|
$code = $c1_entity_char->{$code}; |
|
|
} |
|
|
|
|
|
return {type => CHARACTER_TOKEN, data => chr $code, |
|
|
has_reference => 1, |
|
|
line => $l, column => $c, |
|
|
}; |
|
|
} # X |
|
|
} elsif (0x0030 <= $self->{next_char} and |
|
|
$self->{next_char} <= 0x0039) { # 0..9 |
|
|
my $code = $self->{next_char} - 0x0030; |
|
|
!!!next-input-character; |
|
|
|
|
|
while (0x0030 <= $self->{next_char} and |
|
|
$self->{next_char} <= 0x0039) { # 0..9 |
|
| 3061 |
!!!cp (1012); |
!!!cp (1012); |
| 3062 |
$code *= 10; |
$self->{state_keyword} *= 10; |
| 3063 |
$code += $self->{next_char} - 0x0030; |
$self->{state_keyword} += $self->{next_char} - 0x0030; |
| 3064 |
|
|
| 3065 |
|
## Stay in the state. |
| 3066 |
!!!next-input-character; |
!!!next-input-character; |
| 3067 |
} |
redo A; |
| 3068 |
|
} elsif ($self->{next_char} == 0x003B) { # ; |
|
if ($self->{next_char} == 0x003B) { # ; |
|
| 3069 |
!!!cp (1013); |
!!!cp (1013); |
| 3070 |
!!!next-input-character; |
!!!next-input-character; |
| 3071 |
|
# |
| 3072 |
} else { |
} else { |
| 3073 |
!!!cp (1014); |
!!!cp (1014); |
| 3074 |
!!!parse-error (type => 'no refc', line => $l, column => $c); |
!!!parse-error (type => 'no refc'); |
| 3075 |
|
## Reconsume. |
| 3076 |
|
# |
| 3077 |
} |
} |
| 3078 |
|
|
| 3079 |
|
my $code = $self->{state_keyword}; |
| 3080 |
|
my $l = $self->{line_prev}; |
| 3081 |
|
my $c = $self->{column_prev}; |
| 3082 |
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
| 3083 |
!!!cp (1015); |
!!!cp (1015); |
| 3084 |
!!!parse-error (type => 'invalid character reference', |
!!!parse-error (type => 'invalid character reference', |
| 3103 |
line => $l, column => $c); |
line => $l, column => $c); |
| 3104 |
$code = $c1_entity_char->{$code}; |
$code = $c1_entity_char->{$code}; |
| 3105 |
} |
} |
| 3106 |
|
|
| 3107 |
return {type => CHARACTER_TOKEN, data => chr $code, has_reference => 1, |
if ($self->{prev_state} == DATA_STATE) { |
| 3108 |
line => $l, column => $c, |
!!!cp (992); |
| 3109 |
}; |
$self->{state} = $self->{prev_state}; |
| 3110 |
} else { |
## Reconsume. |
| 3111 |
!!!cp (1019); |
!!!emit ({type => CHARACTER_TOKEN, data => chr $code, |
| 3112 |
!!!parse-error (type => 'bare nero', line => $l, column => $c); |
line => $l, column => $c, |
| 3113 |
!!!back-next-input-character ($self->{next_char}); |
}); |
| 3114 |
$self->{next_char} = 0x0023; # # |
redo A; |
| 3115 |
return undef; |
} else { |
| 3116 |
} |
!!!cp (991); |
| 3117 |
} elsif ((0x0041 <= $self->{next_char} and |
$self->{current_attribute}->{value} .= chr $code; |
| 3118 |
$self->{next_char} <= 0x005A) or |
$self->{current_attribute}->{has_reference} = 1; |
| 3119 |
(0x0061 <= $self->{next_char} and |
$self->{state} = $self->{prev_state}; |
| 3120 |
$self->{next_char} <= 0x007A)) { |
## Reconsume. |
| 3121 |
my $entity_name = chr $self->{next_char}; |
redo A; |
| 3122 |
!!!next-input-character; |
} |
| 3123 |
|
} elsif ($self->{state} == HEXREF_X_STATE) { |
| 3124 |
my $value = $entity_name; |
if ((0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) or |
| 3125 |
my $match = 0; |
(0x0041 <= $self->{next_char} and $self->{next_char} <= 0x0046) or |
| 3126 |
require Whatpm::_NamedEntityList; |
(0x0061 <= $self->{next_char} and $self->{next_char} <= 0x0066)) { |
| 3127 |
our $EntityChar; |
# 0..9, A..F, a..f |
| 3128 |
|
!!!cp (990); |
| 3129 |
while (length $entity_name < 30 and |
$self->{state} = HEXREF_HEX_STATE; |
| 3130 |
## NOTE: Some number greater than the maximum length of entity name |
$self->{state_keyword} = 0; |
| 3131 |
((0x0041 <= $self->{next_char} and # a |
## Reconsume. |
| 3132 |
$self->{next_char} <= 0x005A) or # x |
redo A; |
| 3133 |
(0x0061 <= $self->{next_char} and # a |
} else { |
| 3134 |
$self->{next_char} <= 0x007A) or # z |
!!!parse-error (type => 'bare hcro', |
| 3135 |
(0x0030 <= $self->{next_char} and # 0 |
line => $self->{line_prev}, |
| 3136 |
$self->{next_char} <= 0x0039) or # 9 |
column => $self->{column_prev} - 2); |
| 3137 |
$self->{next_char} == 0x003B)) { # ; |
|
| 3138 |
$entity_name .= chr $self->{next_char}; |
## NOTE: According to the spec algorithm, nothing is returned, |
| 3139 |
if (defined $EntityChar->{$entity_name}) { |
## and then "&#" followed by "X" or "x" is appended to the parent |
| 3140 |
if ($self->{next_char} == 0x003B) { # ; |
## element or the attribute value in the later processing. |
| 3141 |
!!!cp (1020); |
|
| 3142 |
$value = $EntityChar->{$entity_name}; |
if ($self->{prev_state} == DATA_STATE) { |
| 3143 |
$match = 1; |
!!!cp (1005); |
| 3144 |
!!!next-input-character; |
$self->{state} = $self->{prev_state}; |
| 3145 |
last; |
## Reconsume. |
| 3146 |
|
!!!emit ({type => CHARACTER_TOKEN, |
| 3147 |
|
data => '&' . $self->{state_keyword}, |
| 3148 |
|
line => $self->{line_prev}, |
| 3149 |
|
column => $self->{column_prev} - length $self->{state_keyword}, |
| 3150 |
|
}); |
| 3151 |
|
redo A; |
| 3152 |
} else { |
} else { |
| 3153 |
!!!cp (1021); |
!!!cp (989); |
| 3154 |
$value = $EntityChar->{$entity_name}; |
$self->{current_attribute}->{value} .= '&' . $self->{state_keyword}; |
| 3155 |
$match = -1; |
$self->{state} = $self->{prev_state}; |
| 3156 |
|
## Reconsume. |
| 3157 |
|
redo A; |
| 3158 |
|
} |
| 3159 |
|
} |
| 3160 |
|
} elsif ($self->{state} == HEXREF_HEX_STATE) { |
| 3161 |
|
if (0x0030 <= $self->{next_char} and $self->{next_char} <= 0x0039) { |
| 3162 |
|
# 0..9 |
| 3163 |
|
!!!cp (1002); |
| 3164 |
|
$self->{state_keyword} *= 0x10; |
| 3165 |
|
$self->{state_keyword} += $self->{next_char} - 0x0030; |
| 3166 |
|
## Stay in the state. |
| 3167 |
|
!!!next-input-character; |
| 3168 |
|
redo A; |
| 3169 |
|
} elsif (0x0061 <= $self->{next_char} and |
| 3170 |
|
$self->{next_char} <= 0x0066) { # a..f |
| 3171 |
|
!!!cp (1003); |
| 3172 |
|
$self->{state_keyword} *= 0x10; |
| 3173 |
|
$self->{state_keyword} += $self->{next_char} - 0x0060 + 9; |
| 3174 |
|
## Stay in the state. |
| 3175 |
|
!!!next-input-character; |
| 3176 |
|
redo A; |
| 3177 |
|
} elsif (0x0041 <= $self->{next_char} and |
| 3178 |
|
$self->{next_char} <= 0x0046) { # A..F |
| 3179 |
|
!!!cp (1004); |
| 3180 |
|
$self->{state_keyword} *= 0x10; |
| 3181 |
|
$self->{state_keyword} += $self->{next_char} - 0x0040 + 9; |
| 3182 |
|
## Stay in the state. |
| 3183 |
|
!!!next-input-character; |
| 3184 |
|
redo A; |
| 3185 |
|
} elsif ($self->{next_char} == 0x003B) { # ; |
| 3186 |
|
!!!cp (1006); |
| 3187 |
|
!!!next-input-character; |
| 3188 |
|
# |
| 3189 |
|
} else { |
| 3190 |
|
!!!cp (1007); |
| 3191 |
|
!!!parse-error (type => 'no refc', |
| 3192 |
|
line => $self->{line}, |
| 3193 |
|
column => $self->{column}); |
| 3194 |
|
## Reconsume. |
| 3195 |
|
# |
| 3196 |
|
} |
| 3197 |
|
|
| 3198 |
|
my $code = $self->{state_keyword}; |
| 3199 |
|
my $l = $self->{line_prev}; |
| 3200 |
|
my $c = $self->{column_prev}; |
| 3201 |
|
if ($code == 0 or (0xD800 <= $code and $code <= 0xDFFF)) { |
| 3202 |
|
!!!cp (1008); |
| 3203 |
|
!!!parse-error (type => 'invalid character reference', |
| 3204 |
|
text => (sprintf 'U+%04X', $code), |
| 3205 |
|
line => $l, column => $c); |
| 3206 |
|
$code = 0xFFFD; |
| 3207 |
|
} elsif ($code > 0x10FFFF) { |
| 3208 |
|
!!!cp (1009); |
| 3209 |
|
!!!parse-error (type => 'invalid character reference', |
| 3210 |
|
text => (sprintf 'U-%08X', $code), |
| 3211 |
|
line => $l, column => $c); |
| 3212 |
|
$code = 0xFFFD; |
| 3213 |
|
} elsif ($code == 0x000D) { |
| 3214 |
|
!!!cp (1010); |
| 3215 |
|
!!!parse-error (type => 'CR character reference', line => $l, column => $c); |
| 3216 |
|
$code = 0x000A; |
| 3217 |
|
} elsif (0x80 <= $code and $code <= 0x9F) { |
| 3218 |
|
!!!cp (1011); |
| 3219 |
|
!!!parse-error (type => 'C1 character reference', text => (sprintf 'U+%04X', $code), line => $l, column => $c); |
| 3220 |
|
$code = $c1_entity_char->{$code}; |
| 3221 |
|
} |
| 3222 |
|
|
| 3223 |
|
if ($self->{prev_state} == DATA_STATE) { |
| 3224 |
|
!!!cp (988); |
| 3225 |
|
$self->{state} = $self->{prev_state}; |
| 3226 |
|
## Reconsume. |
| 3227 |
|
!!!emit ({type => CHARACTER_TOKEN, data => chr $code, |
| 3228 |
|
line => $l, column => $c, |
| 3229 |
|
}); |
| 3230 |
|
redo A; |
| 3231 |
|
} else { |
| 3232 |
|
!!!cp (987); |
| 3233 |
|
$self->{current_attribute}->{value} .= chr $code; |
| 3234 |
|
$self->{current_attribute}->{has_reference} = 1; |
| 3235 |
|
$self->{state} = $self->{prev_state}; |
| 3236 |
|
## Reconsume. |
| 3237 |
|
redo A; |
| 3238 |
|
} |
| 3239 |
|
} elsif ($self->{state} == ENTITY_NAME_STATE) { |
| 3240 |
|
if (length $self->{state_keyword} < 30 and |
| 3241 |
|
## NOTE: Some number greater than the maximum length of entity name |
| 3242 |
|
((0x0041 <= $self->{next_char} and # a |
| 3243 |
|
$self->{next_char} <= 0x005A) or # x |
| 3244 |
|
(0x0061 <= $self->{next_char} and # a |
| 3245 |
|
$self->{next_char} <= 0x007A) or # z |
| 3246 |
|
(0x0030 <= $self->{next_char} and # 0 |
| 3247 |
|
$self->{next_char} <= 0x0039) or # 9 |
| 3248 |
|
$self->{next_char} == 0x003B)) { # ; |
| 3249 |
|
our $EntityChar; |
| 3250 |
|
$self->{state_keyword} .= chr $self->{next_char}; |
| 3251 |
|
if (defined $EntityChar->{$self->{state_keyword}}) { |
| 3252 |
|
if ($self->{next_char} == 0x003B) { # ; |
| 3253 |
|
!!!cp (1020); |
| 3254 |
|
$self->{entity__value} = $EntityChar->{$self->{state_keyword}}; |
| 3255 |
|
$self->{entity__match} = 1; |
| 3256 |
|
!!!next-input-character; |
| 3257 |
|
# |
| 3258 |
|
} else { |
| 3259 |
|
!!!cp (1021); |
| 3260 |
|
$self->{entity__value} = $EntityChar->{$self->{state_keyword}}; |
| 3261 |
|
$self->{entity__match} = -1; |
| 3262 |
|
## Stay in the state. |
| 3263 |
|
!!!next-input-character; |
| 3264 |
|
redo A; |
| 3265 |
|
} |
| 3266 |
|
} else { |
| 3267 |
|
!!!cp (1022); |
| 3268 |
|
$self->{entity__value} .= chr $self->{next_char}; |
| 3269 |
|
$self->{entity__match} *= 2; |
| 3270 |
|
## Stay in the state. |
| 3271 |
!!!next-input-character; |
!!!next-input-character; |
| 3272 |
|
redo A; |
| 3273 |
|
} |
| 3274 |
|
} |
| 3275 |
|
|
| 3276 |
|
my $data; |
| 3277 |
|
my $has_ref; |
| 3278 |
|
if ($self->{entity__match} > 0) { |
| 3279 |
|
!!!cp (1023); |
| 3280 |
|
$data = $self->{entity__value}; |
| 3281 |
|
$has_ref = 1; |
| 3282 |
|
# |
| 3283 |
|
} elsif ($self->{entity__match} < 0) { |
| 3284 |
|
!!!parse-error (type => 'no refc'); |
| 3285 |
|
if ($self->{prev_state} != DATA_STATE and # in attribute |
| 3286 |
|
$self->{entity__match} < -1) { |
| 3287 |
|
!!!cp (1024); |
| 3288 |
|
$data = '&' . $self->{state_keyword}; |
| 3289 |
|
# |
| 3290 |
|
} else { |
| 3291 |
|
!!!cp (1025); |
| 3292 |
|
$data = $self->{entity__value}; |
| 3293 |
|
$has_ref = 1; |
| 3294 |
|
# |
| 3295 |
} |
} |
| 3296 |
} else { |
} else { |
| 3297 |
!!!cp (1022); |
!!!cp (1026); |
| 3298 |
$value .= chr $self->{next_char}; |
!!!parse-error (type => 'bare ero', |
| 3299 |
$match *= 2; |
line => $self->{line_prev}, |
| 3300 |
!!!next-input-character; |
column => $self->{column_prev}); |
| 3301 |
|
$data = '&' . $self->{state_keyword}; |
| 3302 |
|
# |
| 3303 |
} |
} |
| 3304 |
} |
|
| 3305 |
|
## NOTE: In these cases, when a character reference is found, |
| 3306 |
if ($match > 0) { |
## it is consumed and a character token is returned, or, otherwise, |
| 3307 |
!!!cp (1023); |
## nothing is consumed and returned, according to the spec algorithm. |
| 3308 |
return {type => CHARACTER_TOKEN, data => $value, has_reference => 1, |
## In this implementation, anything that has been examined by the |
| 3309 |
line => $l, column => $c, |
## tokenizer is appended to the parent element or the attribute value |
| 3310 |
}; |
## as string, either literal string when no character reference or |
| 3311 |
} elsif ($match < 0) { |
## entity-replaced string otherwise, in this stage, since any characters |
| 3312 |
!!!parse-error (type => 'no refc', line => $l, column => $c); |
## that would not be consumed are appended in the data state or in an |
| 3313 |
if ($in_attr and $match < -1) { |
## appropriate attribute value state anyway. |
| 3314 |
!!!cp (1024); |
|
| 3315 |
return {type => CHARACTER_TOKEN, data => '&'.$entity_name, |
if ($self->{prev_state} == DATA_STATE) { |
| 3316 |
line => $l, column => $c, |
!!!cp (986); |
| 3317 |
}; |
$self->{state} = $self->{prev_state}; |
| 3318 |
} else { |
## Reconsume. |
| 3319 |
!!!cp (1025); |
!!!emit ({type => CHARACTER_TOKEN, |
| 3320 |
return {type => CHARACTER_TOKEN, data => $value, has_reference => 1, |
data => $data, |
| 3321 |
line => $l, column => $c, |
line => $self->{line_prev}, |
| 3322 |
}; |
column => $self->{column_prev} + 1 - length $self->{state_keyword}, |
| 3323 |
|
}); |
| 3324 |
|
redo A; |
| 3325 |
|
} else { |
| 3326 |
|
!!!cp (985); |
| 3327 |
|
$self->{current_attribute}->{value} .= $data; |
| 3328 |
|
$self->{current_attribute}->{has_reference} = 1 if $has_ref; |
| 3329 |
|
$self->{state} = $self->{prev_state}; |
| 3330 |
|
## Reconsume. |
| 3331 |
|
redo A; |
| 3332 |
} |
} |
| 3333 |
} else { |
} else { |
| 3334 |
!!!cp (1026); |
die "$0: $self->{state}: Unknown state"; |
|
!!!parse-error (type => 'bare ero', line => $l, column => $c); |
|
|
## NOTE: "No characters are consumed" in the spec. |
|
|
return {type => CHARACTER_TOKEN, data => '&'.$value, |
|
|
line => $l, column => $c, |
|
|
}; |
|
| 3335 |
} |
} |
| 3336 |
} else { |
} # A |
| 3337 |
!!!cp (1027); |
|
| 3338 |
## no characters are consumed |
die "$0: _get_next_token: unexpected case"; |
| 3339 |
!!!parse-error (type => 'bare ero', line => $l, column => $c); |
} # _get_next_token |
|
return undef; |
|
|
} |
|
|
} # _tokenize_attempt_to_consume_an_entity |
|
| 3340 |
|
|
| 3341 |
sub _initialize_tree_constructor ($) { |
sub _initialize_tree_constructor ($) { |
| 3342 |
my $self = shift; |
my $self = shift; |
| 7794 |
}; |
}; |
| 7795 |
$p->{prev_char} = [-1, -1, -1]; |
$p->{prev_char} = [-1, -1, -1]; |
| 7796 |
$p->{next_char} = -1; |
$p->{next_char} = -1; |
| 7797 |
|
|
| 7798 |
|
$p->{read_until} = sub { |
| 7799 |
|
## TODO: ... |
| 7800 |
|
return 0; |
| 7801 |
|
}; # $p->{read_until}; |
| 7802 |
|
|
| 7803 |
my $ponerror = $onerror || sub { |
my $ponerror = $onerror || sub { |
| 7804 |
my (%opt) = @_; |
my (%opt) = @_; |
| 7805 |
my $line = $opt{line}; |
my $line = $opt{line}; |