/[suikacvs]/markup/html/whatpm/Whatpm/HTML/Tokenizer.pm.src
Suika

Diff of /markup/html/whatpm/Whatpm/HTML/Tokenizer.pm.src

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by wakaba, Wed Oct 15 12:49:49 2008 UTC revision 1.17 by wakaba, Sun Oct 19 04:39:25 2008 UTC
# Line 15  BEGIN { Line 15  BEGIN {
15      CHARACTER_TOKEN      CHARACTER_TOKEN
16      PI_TOKEN      PI_TOKEN
17      ABORT_TOKEN      ABORT_TOKEN
18        END_OF_DOCTYPE_TOKEN
19        ATTLIST_TOKEN
20        ELEMENT_TOKEN
21        GENERAL_ENTITY_TOKEN
22        PARAMETER_ENTITY_TOKEN
23        NOTATION_TOKEN
24    );    );
25        
26    our %EXPORT_TAGS = (    our %EXPORT_TAGS = (
# Line 27  BEGIN { Line 33  BEGIN {
33        CHARACTER_TOKEN        CHARACTER_TOKEN
34        PI_TOKEN        PI_TOKEN
35        ABORT_TOKEN        ABORT_TOKEN
36          END_OF_DOCTYPE_TOKEN
37          ATTLIST_TOKEN
38          ELEMENT_TOKEN
39          GENERAL_ENTITY_TOKEN
40          PARAMETER_ENTITY_TOKEN
41          NOTATION_TOKEN
42      )],      )],
43    );    );
44  }  }
# Line 43  sub END_OF_FILE_TOKEN () { 5 } Line 55  sub END_OF_FILE_TOKEN () { 5 }
55  sub CHARACTER_TOKEN () { 6 }  sub CHARACTER_TOKEN () { 6 }
56  sub PI_TOKEN () { 7 } ## NOTE: XML only.  sub PI_TOKEN () { 7 } ## NOTE: XML only.
57  sub ABORT_TOKEN () { 8 } ## NOTE: For internal processing.  sub ABORT_TOKEN () { 8 } ## NOTE: For internal processing.
58    sub END_OF_DOCTYPE_TOKEN () { 9 } ## NOTE: XML only.
59    sub ATTLIST_TOKEN () { 10 } ## NOTE: XML only.
60    sub ELEMENT_TOKEN () { 11 } ## NOTE: XML only.
61    sub GENERAL_ENTITY_TOKEN () { 12 } ## NOTE: XML only.
62    sub PARAMETER_ENTITY_TOKEN () { 13 } ## NOTE: XML only.
63    sub NOTATION_TOKEN () { 14 } ## NOTE: XML only.
64    
65  ## XML5: XML5 has "empty tag token".  In this implementation, it is  ## XML5: XML5 has "empty tag token".  In this implementation, it is
66  ## represented as a start tag token with $self->{self_closing} flag  ## represented as a start tag token with $self->{self_closing} flag
# Line 133  sub PI_AFTER_STATE () { 55 } Line 151  sub PI_AFTER_STATE () { 55 }
151  sub PI_DATA_AFTER_STATE () { 56 }  sub PI_DATA_AFTER_STATE () { 56 }
152  sub DOCTYPE_INTERNAL_SUBSET_STATE () { 57 }  sub DOCTYPE_INTERNAL_SUBSET_STATE () { 57 }
153  sub DOCTYPE_INTERNAL_SUBSET_AFTER_STATE () { 58 }  sub DOCTYPE_INTERNAL_SUBSET_AFTER_STATE () { 58 }
154    sub BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE () { 59 }
155    sub DOCTYPE_TAG_STATE () { 60 }
156    sub DOCTYPE_MARKUP_DECLARATION_OPEN_STATE () { 61 }
157    sub MD_ATTLIST_STATE () { 62 }
158    sub MD_E_STATE () { 63 }
159    sub MD_ELEMENT_STATE () { 64 }
160    sub MD_ENTITY_STATE () { 65 }
161    sub MD_NOTATION_STATE () { 66 }
162    sub DOCTYPE_MD_STATE () { 67 }
163    sub BEFORE_MD_NAME_STATE () { 68 }
164    sub MD_NAME_STATE () { 69 }
165    sub DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE () { 70 }
166    sub DOCTYPE_ATTLIST_NAME_AFTER_STATE () { 71 }
167    sub DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE () { 72 }
168    sub DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE () { 73 }
169    sub DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE () { 74 }
170    sub DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE () { 75 }
171    sub BEFORE_ALLOWED_TOKEN_STATE () { 76 }
172    sub ALLOWED_TOKEN_STATE () { 77 }
173    sub AFTER_ALLOWED_TOKEN_STATE () { 78 }
174    sub AFTER_ALLOWED_TOKENS_STATE () { 79 }
175    sub BEFORE_ATTR_DEFAULT_STATE () { 80 }
176    sub DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE () { 81 }
177    sub DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE () { 82 }
178    sub DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE () { 83 }
179    sub AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE () { 84 }
180    sub BOGUS_MD_STATE () { 85 }
181    
182  ## Tree constructor state constants (see Whatpm::HTML for the full  ## Tree constructor state constants (see Whatpm::HTML for the full
183  ## list and descriptions)  ## list and descriptions)
# Line 1226  sub _get_next_token ($) { Line 1271  sub _get_next_token ($) {
1271          redo A;          redo A;
1272        }        }
1273      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE) {
1274        ## XML5: "Tag attribute value double quoted state".        ## XML5: "Tag attribute value double quoted state" and "DOCTYPE
1275          ## ATTLIST attribute value double quoted state".
1276                
1277        if ($self->{nc} == 0x0022) { # "        if ($self->{nc} == 0x0022) { # "
1278          !!!cp (95);          if ($self->{ct}->{type} == ATTLIST_TOKEN) {
1279          ## XML5: "Tag attribute name before state".            !!!cp (95.1);
1280          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;            ## XML5: "DOCTYPE ATTLIST name after state".
1281              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1282              $self->{state} = AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE;
1283            } else {
1284              !!!cp (95);
1285              ## XML5: "Tag attribute name before state".
1286              $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1287            }
1288          !!!next-input-character;          !!!next-input-character;
1289          redo A;          redo A;
1290        } elsif ($self->{nc} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
# Line 1252  sub _get_next_token ($) { Line 1305  sub _get_next_token ($) {
1305          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1306            !!!cp (97);            !!!cp (97);
1307            $self->{last_stag_name} = $self->{ct}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1308    
1309              $self->{state} = DATA_STATE;
1310              $self->{s_kwd} = '';
1311              ## reconsume
1312              !!!emit ($self->{ct}); # start tag
1313              redo A;
1314          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1315            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1316            if ($self->{ct}->{attributes}) {            if ($self->{ct}->{attributes}) {
# Line 1261  sub _get_next_token ($) { Line 1320  sub _get_next_token ($) {
1320              ## NOTE: This state should never be reached.              ## NOTE: This state should never be reached.
1321              !!!cp (99);              !!!cp (99);
1322            }            }
1323    
1324              $self->{state} = DATA_STATE;
1325              $self->{s_kwd} = '';
1326              ## reconsume
1327              !!!emit ($self->{ct}); # end tag
1328              redo A;
1329            } elsif ($self->{ct}->{type} == ATTLIST_TOKEN) {
1330              ## XML5: No parse error above; not defined yet.
1331              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1332              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1333              ## Reconsume.
1334              !!!emit ($self->{ct}); # ATTLIST
1335              redo A;
1336          } else {          } else {
1337            die "$0: $self->{ct}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1338          }          }
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
         ## reconsume  
   
         !!!emit ($self->{ct}); # start tag or end tag  
   
         redo A;  
1339        } else {        } else {
1340            ## XML5 [ATTLIST]: Not defined yet.
1341          if ($self->{is_xml} and $self->{nc} == 0x003C) { # <          if ($self->{is_xml} and $self->{nc} == 0x003C) { # <
1342            !!!cp (100);            !!!cp (100);
1343            ## XML5: Not a parse error.            ## XML5: Not a parse error.
# Line 1289  sub _get_next_token ($) { Line 1355  sub _get_next_token ($) {
1355          redo A;          redo A;
1356        }        }
1357      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {      } elsif ($self->{state} == ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE) {
1358        ## XML5: "Tag attribute value single quoted state".        ## XML5: "Tag attribute value single quoted state" and "DOCTYPE
1359          ## ATTLIST attribute value single quoted state".
1360    
1361        if ($self->{nc} == 0x0027) { # '        if ($self->{nc} == 0x0027) { # '
1362          !!!cp (101);          if ($self->{ct}->{type} == ATTLIST_TOKEN) {
1363          ## XML5: "Before attribute name state" (sic).            !!!cp (101.1);
1364          $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;            ## XML5: "DOCTYPE ATTLIST name after state".
1365              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1366              $self->{state} = AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE;
1367            } else {
1368              !!!cp (101);
1369              ## XML5: "Before attribute name state" (sic).
1370              $self->{state} = AFTER_ATTRIBUTE_VALUE_QUOTED_STATE;
1371            }
1372          !!!next-input-character;          !!!next-input-character;
1373          redo A;          redo A;
1374        } elsif ($self->{nc} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
# Line 1315  sub _get_next_token ($) { Line 1389  sub _get_next_token ($) {
1389          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1390            !!!cp (103);            !!!cp (103);
1391            $self->{last_stag_name} = $self->{ct}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1392    
1393              $self->{state} = DATA_STATE;
1394              $self->{s_kwd} = '';
1395              ## reconsume
1396              !!!emit ($self->{ct}); # start tag
1397              redo A;
1398          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1399            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1400            if ($self->{ct}->{attributes}) {            if ($self->{ct}->{attributes}) {
# Line 1324  sub _get_next_token ($) { Line 1404  sub _get_next_token ($) {
1404              ## NOTE: This state should never be reached.              ## NOTE: This state should never be reached.
1405              !!!cp (105);              !!!cp (105);
1406            }            }
1407    
1408              $self->{state} = DATA_STATE;
1409              $self->{s_kwd} = '';
1410              ## reconsume
1411              !!!emit ($self->{ct}); # end tag
1412              redo A;
1413            } elsif ($self->{ct}->{type} == ATTLIST_TOKEN) {
1414              ## XML5: No parse error above; not defined yet.
1415              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1416              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1417              ## Reconsume.
1418              !!!emit ($self->{ct}); # ATTLIST
1419              redo A;
1420          } else {          } else {
1421            die "$0: $self->{ct}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1422          }          }
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
         ## reconsume  
   
         !!!emit ($self->{ct}); # start tag or end tag  
   
         redo A;  
1423        } else {        } else {
1424            ## XML5 [ATTLIST]: Not defined yet.
1425          if ($self->{is_xml} and $self->{nc} == 0x003C) { # <          if ($self->{is_xml} and $self->{nc} == 0x003C) { # <
1426            !!!cp (106);            !!!cp (106);
1427            ## XML5: Not a parse error.            ## XML5: Not a parse error.
# Line 1355  sub _get_next_token ($) { Line 1442  sub _get_next_token ($) {
1442        ## XML5: "Tag attribute value unquoted state".        ## XML5: "Tag attribute value unquoted state".
1443    
1444        if ($is_space->{$self->{nc}}) {        if ($is_space->{$self->{nc}}) {
1445          !!!cp (107);          if ($self->{ct}->{type} == ATTLIST_TOKEN) {
1446          ## XML5: "Tag attribute name before state".            !!!cp (107.1);
1447          $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;            push @{$self->{ct}->{attrdefs}}, $self->{ca};
1448              $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
1449            } else {
1450              !!!cp (107);
1451              ## XML5: "Tag attribute name before state".
1452              $self->{state} = BEFORE_ATTRIBUTE_NAME_STATE;
1453            }
1454          !!!next-input-character;          !!!next-input-character;
1455          redo A;          redo A;
1456        } elsif ($self->{nc} == 0x0026) { # &        } elsif ($self->{nc} == 0x0026) { # &
# Line 1378  sub _get_next_token ($) { Line 1471  sub _get_next_token ($) {
1471          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1472            !!!cp (109);            !!!cp (109);
1473            $self->{last_stag_name} = $self->{ct}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1474    
1475              $self->{state} = DATA_STATE;
1476              $self->{s_kwd} = '';
1477              !!!next-input-character;
1478              !!!emit ($self->{ct}); # start tag
1479              redo A;
1480          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1481            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1482            if ($self->{ct}->{attributes}) {            if ($self->{ct}->{attributes}) {
# Line 1387  sub _get_next_token ($) { Line 1486  sub _get_next_token ($) {
1486              ## NOTE: This state should never be reached.              ## NOTE: This state should never be reached.
1487              !!!cp (111);              !!!cp (111);
1488            }            }
1489    
1490              $self->{state} = DATA_STATE;
1491              $self->{s_kwd} = '';
1492              !!!next-input-character;
1493              !!!emit ($self->{ct}); # end tag
1494              redo A;
1495            } elsif ($self->{ct}->{type} == ATTLIST_TOKEN) {
1496              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1497              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1498              !!!next-input-character;
1499              !!!emit ($self->{ct}); # ATTLIST
1500              redo A;
1501          } else {          } else {
1502            die "$0: $self->{ct}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1503          }          }
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
         !!!next-input-character;  
   
         !!!emit ($self->{ct}); # start tag or end tag  
   
         redo A;  
1504        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!parse-error (type => 'unclosed tag');  
1505          if ($self->{ct}->{type} == START_TAG_TOKEN) {          if ($self->{ct}->{type} == START_TAG_TOKEN) {
1506            !!!cp (112);            !!!cp (112);
1507              !!!parse-error (type => 'unclosed tag');
1508            $self->{last_stag_name} = $self->{ct}->{tag_name};            $self->{last_stag_name} = $self->{ct}->{tag_name};
1509    
1510              $self->{state} = DATA_STATE;
1511              $self->{s_kwd} = '';
1512              ## reconsume
1513              !!!emit ($self->{ct}); # start tag
1514              redo A;
1515          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {          } elsif ($self->{ct}->{type} == END_TAG_TOKEN) {
1516              !!!parse-error (type => 'unclosed tag');
1517            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST            $self->{content_model} = PCDATA_CONTENT_MODEL; # MUST
1518            if ($self->{ct}->{attributes}) {            if ($self->{ct}->{attributes}) {
1519              !!!cp (113);              !!!cp (113);
# Line 1411  sub _get_next_token ($) { Line 1522  sub _get_next_token ($) {
1522              ## NOTE: This state should never be reached.              ## NOTE: This state should never be reached.
1523              !!!cp (114);              !!!cp (114);
1524            }            }
1525    
1526              $self->{state} = DATA_STATE;
1527              $self->{s_kwd} = '';
1528              ## reconsume
1529              !!!emit ($self->{ct}); # end tag
1530              redo A;
1531            } elsif ($self->{ct}->{type} == ATTLIST_TOKEN) {
1532              !!!parse-error (type => 'unclosed md'); ## TODO: type
1533              push @{$self->{ct}->{attrdefs}}, $self->{ca};
1534              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1535              ## Reconsume.
1536              !!!emit ($self->{ct}); # ATTLIST
1537              redo A;
1538          } else {          } else {
1539            die "$0: $self->{ct}->{type}: Unknown token type";            die "$0: $self->{ct}->{type}: Unknown token type";
1540          }          }
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
         ## reconsume  
   
         !!!emit ($self->{ct}); # start tag or end tag  
   
         redo A;  
1541        } else {        } else {
1542          if ({          if ({
1543               0x0022 => 1, # "               0x0022 => 1, # "
# Line 1563  sub _get_next_token ($) { Line 1680  sub _get_next_token ($) {
1680          redo A;          redo A;
1681        }        }
1682      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {      } elsif ($self->{state} == BOGUS_COMMENT_STATE) {
1683        ## (only happen if PCDATA state)        ## XML5: "Bogus comment state" and "DOCTYPE bogus comment state".
1684    
1685        ## NOTE: Unlike spec's "bogus comment state", this implementation        ## NOTE: Unlike spec's "bogus comment state", this implementation
1686        ## consumes characters one-by-one basis.        ## consumes characters one-by-one basis.
1687                
1688        if ($self->{nc} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
1689          !!!cp (124);          if ($self->{in_subset}) {
1690          $self->{state} = DATA_STATE;            !!!cp (123);
1691          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1692            } else {
1693              !!!cp (124);
1694              $self->{state} = DATA_STATE;
1695              $self->{s_kwd} = '';
1696            }
1697          !!!next-input-character;          !!!next-input-character;
1698    
1699          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
1700          redo A;          redo A;
1701        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
1702          !!!cp (125);          if ($self->{in_subset}) {
1703          $self->{state} = DATA_STATE;            !!!cp (125.1);
1704          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1705            } else {
1706              !!!cp (125);
1707              $self->{state} = DATA_STATE;
1708              $self->{s_kwd} = '';
1709            }
1710          ## reconsume          ## reconsume
1711    
1712          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1596  sub _get_next_token ($) { Line 1723  sub _get_next_token ($) {
1723          redo A;          redo A;
1724        }        }
1725      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {      } elsif ($self->{state} == MARKUP_DECLARATION_OPEN_STATE) {
1726        ## (only happen if PCDATA state)        ## XML5: "Markup declaration state".
1727                
1728        if ($self->{nc} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
1729          !!!cp (133);          !!!cp (133);
# Line 1772  sub _get_next_token ($) { Line 1899  sub _get_next_token ($) {
1899          !!!next-input-character;          !!!next-input-character;
1900          redo A;          redo A;
1901        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (138);  
1902          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1903          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
1904          $self->{s_kwd} = '';            !!!cp (138.1);
1905              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1906            } else {
1907              !!!cp (138);
1908              $self->{state} = DATA_STATE;
1909              $self->{s_kwd} = '';
1910            }
1911          !!!next-input-character;          !!!next-input-character;
1912    
1913          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
1914    
1915          redo A;          redo A;
1916        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (139);  
1917          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1918          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
1919          $self->{s_kwd} = '';            !!!cp (139.1);
1920              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1921            } else {
1922              !!!cp (139);
1923              $self->{state} = DATA_STATE;
1924              $self->{s_kwd} = '';
1925            }
1926          ## reconsume          ## reconsume
1927    
1928          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1806  sub _get_next_token ($) { Line 1943  sub _get_next_token ($) {
1943          !!!next-input-character;          !!!next-input-character;
1944          redo A;          redo A;
1945        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (142);  
1946          !!!parse-error (type => 'bogus comment');          !!!parse-error (type => 'bogus comment');
1947          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
1948          $self->{s_kwd} = '';            !!!cp (142.1);
1949              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1950            } else {
1951              !!!cp (142);
1952              $self->{state} = DATA_STATE;
1953              $self->{s_kwd} = '';
1954            }
1955          !!!next-input-character;          !!!next-input-character;
1956    
1957          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
1958    
1959          redo A;          redo A;
1960        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (143);  
1961          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1962          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
1963          $self->{s_kwd} = '';            !!!cp (143.1);
1964              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1965            } else {
1966              !!!cp (143);
1967              $self->{state} = DATA_STATE;
1968              $self->{s_kwd} = '';
1969            }
1970          ## reconsume          ## reconsume
1971    
1972          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1834  sub _get_next_token ($) { Line 1981  sub _get_next_token ($) {
1981          redo A;          redo A;
1982        }        }
1983      } elsif ($self->{state} == COMMENT_STATE) {      } elsif ($self->{state} == COMMENT_STATE) {
1984          ## XML5: "Comment state" and "DOCTYPE comment state".
1985    
1986        if ($self->{nc} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
1987          !!!cp (145);          !!!cp (145);
1988          $self->{state} = COMMENT_END_DASH_STATE;          $self->{state} = COMMENT_END_DASH_STATE;
1989          !!!next-input-character;          !!!next-input-character;
1990          redo A;          redo A;
1991        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (146);  
1992          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
1993          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
1994          $self->{s_kwd} = '';            !!!cp (146.1);
1995              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
1996            } else {
1997              !!!cp (146);
1998              $self->{state} = DATA_STATE;
1999              $self->{s_kwd} = '';
2000            }
2001          ## reconsume          ## reconsume
2002    
2003          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1861  sub _get_next_token ($) { Line 2015  sub _get_next_token ($) {
2015          redo A;          redo A;
2016        }        }
2017      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {      } elsif ($self->{state} == COMMENT_END_DASH_STATE) {
2018        ## XML5: "comment dash state".        ## XML5: "Comment dash state" and "DOCTYPE comment dash state".
2019    
2020        if ($self->{nc} == 0x002D) { # -        if ($self->{nc} == 0x002D) { # -
2021          !!!cp (148);          !!!cp (148);
# Line 1869  sub _get_next_token ($) { Line 2023  sub _get_next_token ($) {
2023          !!!next-input-character;          !!!next-input-character;
2024          redo A;          redo A;
2025        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (149);  
2026          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2027          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
2028          $self->{s_kwd} = '';            !!!cp (149.1);
2029              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2030            } else {
2031              !!!cp (149);
2032              $self->{state} = DATA_STATE;
2033              $self->{s_kwd} = '';
2034            }
2035          ## reconsume          ## reconsume
2036    
2037          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1886  sub _get_next_token ($) { Line 2045  sub _get_next_token ($) {
2045          redo A;          redo A;
2046        }        }
2047      } elsif ($self->{state} == COMMENT_END_STATE) {      } elsif ($self->{state} == COMMENT_END_STATE) {
2048          ## XML5: "Comment end state" and "DOCTYPE comment end state".
2049    
2050        if ($self->{nc} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
2051          !!!cp (151);          if ($self->{in_subset}) {
2052          $self->{state} = DATA_STATE;            !!!cp (151.1);
2053          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2054            } else {
2055              !!!cp (151);
2056              $self->{state} = DATA_STATE;
2057              $self->{s_kwd} = '';
2058            }
2059          !!!next-input-character;          !!!next-input-character;
2060    
2061          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1906  sub _get_next_token ($) { Line 2072  sub _get_next_token ($) {
2072          !!!next-input-character;          !!!next-input-character;
2073          redo A;          redo A;
2074        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (153);  
2075          !!!parse-error (type => 'unclosed comment');          !!!parse-error (type => 'unclosed comment');
2076          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
2077          $self->{s_kwd} = '';            !!!cp (153.1);
2078              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2079            } else {
2080              !!!cp (153);
2081              $self->{state} = DATA_STATE;
2082              $self->{s_kwd} = '';
2083            }
2084          ## reconsume          ## reconsume
2085    
2086          !!!emit ($self->{ct}); # comment          !!!emit ($self->{ct}); # comment
# Line 1973  sub _get_next_token ($) { Line 2144  sub _get_next_token ($) {
2144          !!!cp (159.1);          !!!cp (159.1);
2145          !!!parse-error (type => 'no DOCTYPE name');          !!!parse-error (type => 'no DOCTYPE name');
2146          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2147            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2148            $self->{in_subset} = 1;
2149          !!!next-input-character;          !!!next-input-character;
2150            !!!emit ($self->{ct}); # DOCTYPE
2151          redo A;          redo A;
2152        } else {        } else {
2153          !!!cp (160);          !!!cp (160);
# Line 2016  sub _get_next_token ($) { Line 2190  sub _get_next_token ($) {
2190        } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [        } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [
2191          !!!cp (163.1);          !!!cp (163.1);
2192          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2193            $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2194            $self->{in_subset} = 1;
2195          !!!next-input-character;          !!!next-input-character;
2196            !!!emit ($self->{ct}); # DOCTYPE
2197          redo A;          redo A;
2198        } else {        } else {
2199          !!!cp (164);          !!!cp (164);
# Line 2036  sub _get_next_token ($) { Line 2213  sub _get_next_token ($) {
2213          !!!next-input-character;          !!!next-input-character;
2214          redo A;          redo A;
2215        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2216          !!!cp (166);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2217          $self->{state} = DATA_STATE;            !!!cp (166);
2218          $self->{s_kwd} = '';            $self->{state} = DATA_STATE;
2219              $self->{s_kwd} = '';
2220            } else {
2221              !!!cp (166.1);
2222              !!!parse-error (type => 'no md def'); ## TODO: type
2223              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2224            }
2225            
2226          !!!next-input-character;          !!!next-input-character;
2227            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         !!!emit ($self->{ct}); # DOCTYPE  
   
2228          redo A;          redo A;
2229        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2230          !!!cp (167);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2231          !!!parse-error (type => 'unclosed DOCTYPE');            !!!cp (167);
2232          $self->{state} = DATA_STATE;            !!!parse-error (type => 'unclosed DOCTYPE');
2233          $self->{s_kwd} = '';            $self->{state} = DATA_STATE;
2234          ## reconsume            $self->{s_kwd} = '';
2235              $self->{ct}->{quirks} = 1;
2236          $self->{ct}->{quirks} = 1;          } else {
2237          !!!emit ($self->{ct}); # DOCTYPE            !!!cp (167.12);
2238              !!!parse-error (type => 'unclosed md'); ## TODO: type
2239              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2240            }
2241            
2242            ## Reconsume.
2243            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2244          redo A;          redo A;
2245        } elsif ($self->{nc} == 0x0050 or # P        } elsif ($self->{nc} == 0x0050 or # P
2246                 $self->{nc} == 0x0070) { # p                 $self->{nc} == 0x0070) { # p
# Line 2069  sub _get_next_token ($) { Line 2256  sub _get_next_token ($) {
2256          $self->{kwd} = chr $self->{nc};          $self->{kwd} = chr $self->{nc};
2257          !!!next-input-character;          !!!next-input-character;
2258          redo A;          redo A;
2259        } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [  ## TODO: " and ' for ENTITY
2260          } elsif ($self->{is_xml} and
2261                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2262                   $self->{nc} == 0x005B) { # [
2263          !!!cp (167.3);          !!!cp (167.3);
2264          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2265          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2266            $self->{in_subset} = 1;
2267          !!!next-input-character;          !!!next-input-character;
2268            !!!emit ($self->{ct}); # DOCTYPE
2269          redo A;          redo A;
2270        } else {        } else {
2271          !!!cp (180);          !!!parse-error (type => 'string after DOCTYPE name'); ## TODO: type
2272          !!!parse-error (type => 'string after DOCTYPE name');  
2273          $self->{ct}->{quirks} = 1;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2274              !!!cp (180);
2275              $self->{ct}->{quirks} = 1;
2276              $self->{state} = BOGUS_DOCTYPE_STATE;
2277            } else {
2278              !!!cp (180.1);
2279              $self->{state} = BOGUS_MD_STATE;
2280            }
2281    
         $self->{state} = BOGUS_DOCTYPE_STATE;  
2282          !!!next-input-character;          !!!next-input-character;
2283          redo A;          redo A;
2284        }        }
# Line 2122  sub _get_next_token ($) { Line 2320  sub _get_next_token ($) {
2320          !!!next-input-character;          !!!next-input-character;
2321          redo A;          redo A;
2322        } else {        } else {
2323          !!!cp (169);          !!!parse-error (type => 'string after DOCTYPE name', ## TODO: type
         !!!parse-error (type => 'string after DOCTYPE name',  
2324                          line => $self->{line_prev},                          line => $self->{line_prev},
2325                          column => $self->{column_prev} + 1 - length $self->{kwd});                          column => $self->{column_prev} + 1 - length $self->{kwd});
2326          $self->{ct}->{quirks} = 1;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2327              !!!cp (169);
2328          $self->{state} = BOGUS_DOCTYPE_STATE;            $self->{ct}->{quirks} = 1;
2329              $self->{state} = BOGUS_DOCTYPE_STATE;
2330            } else {
2331              !!!cp (169.1);
2332              $self->{state} = BOGUS_MD_STATE;
2333            }
2334          ## Reconsume.          ## Reconsume.
2335          redo A;          redo A;
2336        }        }
# Line 2170  sub _get_next_token ($) { Line 2372  sub _get_next_token ($) {
2372          !!!next-input-character;          !!!next-input-character;
2373          redo A;          redo A;
2374        } else {        } else {
2375          !!!cp (172);          !!!parse-error (type => 'string after DOCTYPE name', ## TODO: type
         !!!parse-error (type => 'string after DOCTYPE name',  
2376                          line => $self->{line_prev},                          line => $self->{line_prev},
2377                          column => $self->{column_prev} + 1 - length $self->{kwd});                          column => $self->{column_prev} + 1 - length $self->{kwd});
2378          $self->{ct}->{quirks} = 1;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2379              !!!cp (172);
2380          $self->{state} = BOGUS_DOCTYPE_STATE;            $self->{ct}->{quirks} = 1;
2381              $self->{state} = BOGUS_DOCTYPE_STATE;
2382            } else {
2383              !!!cp (172.1);
2384              $self->{state} = BOGUS_MD_STATE;
2385            }
2386          ## Reconsume.          ## Reconsume.
2387          redo A;          redo A;
2388        }        }
# Line 2199  sub _get_next_token ($) { Line 2405  sub _get_next_token ($) {
2405          !!!next-input-character;          !!!next-input-character;
2406          redo A;          redo A;
2407        } elsif ($self->{nc} eq 0x003E) { # >        } elsif ($self->{nc} eq 0x003E) { # >
         !!!cp (184);  
2408          !!!parse-error (type => 'no PUBLIC literal');          !!!parse-error (type => 'no PUBLIC literal');
2409            
2410          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2411          $self->{s_kwd} = '';            !!!cp (184);
2412              $self->{state} = DATA_STATE;
2413              $self->{s_kwd} = '';
2414              $self->{ct}->{quirks} = 1;
2415            } else {
2416              !!!cp (184.1);
2417              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2418            }
2419            
2420          !!!next-input-character;          !!!next-input-character;
2421            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2422          redo A;          redo A;
2423        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2424          !!!cp (185);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2425          !!!parse-error (type => 'unclosed DOCTYPE');            !!!cp (185);
2426              !!!parse-error (type => 'unclosed DOCTYPE');
2427          $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
2428          $self->{s_kwd} = '';            $self->{s_kwd} = '';
2429              $self->{ct}->{quirks} = 1;
2430            } else {
2431              !!!cp (185.1);
2432              !!!parse-error (type => 'unclosed md'); ## TODO: type
2433              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2434            }
2435            
2436          ## reconsume          ## reconsume
   
         $self->{ct}->{quirks} = 1;  
2437          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
   
2438          redo A;          redo A;
2439        } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [        } elsif ($self->{is_xml} and
2440                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2441                   $self->{nc} == 0x005B) { # [
2442          !!!cp (186.1);          !!!cp (186.1);
2443          !!!parse-error (type => 'no PUBLIC literal');          !!!parse-error (type => 'no PUBLIC literal');
2444          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2445          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2446            $self->{in_subset} = 1;
2447          !!!next-input-character;          !!!next-input-character;
2448            !!!emit ($self->{ct}); # DOCTYPE
2449          redo A;          redo A;
2450        } else {        } else {
         !!!cp (186);  
2451          !!!parse-error (type => 'string after PUBLIC');          !!!parse-error (type => 'string after PUBLIC');
         $self->{ct}->{quirks} = 1;  
2452    
2453          $self->{state} = BOGUS_DOCTYPE_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2454              !!!cp (186);
2455              $self->{ct}->{quirks} = 1;
2456              $self->{state} = BOGUS_DOCTYPE_STATE;
2457            } else {
2458              !!!cp (186.2);
2459              $self->{state} = BOGUS_MD_STATE;
2460            }
2461    
2462          !!!next-input-character;          !!!next-input-character;
2463          redo A;          redo A;
2464        }        }
# Line 2245  sub _get_next_token ($) { Line 2469  sub _get_next_token ($) {
2469          !!!next-input-character;          !!!next-input-character;
2470          redo A;          redo A;
2471        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (188);  
2472          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2473    
2474          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2475          $self->{s_kwd} = '';            !!!cp (188);
2476          !!!next-input-character;            $self->{state} = DATA_STATE;
2477              $self->{s_kwd} = '';
2478          $self->{ct}->{quirks} = 1;            $self->{ct}->{quirks} = 1;
2479          !!!emit ($self->{ct}); # DOCTYPE          } else {
2480              !!!cp (188.1);
2481              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2482            }
2483    
2484            !!!next-input-character;
2485            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2486          redo A;          redo A;
2487        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (189);  
2488          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2489    
2490          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2491          $self->{s_kwd} = '';            !!!cp (189);
2492          ## reconsume            $self->{state} = DATA_STATE;
2493              $self->{s_kwd} = '';
2494          $self->{ct}->{quirks} = 1;            $self->{ct}->{quirks} = 1;
2495            } else {
2496              !!!cp (189.1);
2497              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2498            }
2499            
2500            ## Reconsume.
2501          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ($self->{ct}); # DOCTYPE
   
2502          redo A;          redo A;
2503        } else {        } else {
2504          !!!cp (190);          !!!cp (190);
2505          $self->{ct}->{pubid} # DOCTYPE          $self->{ct}->{pubid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
             .= chr $self->{nc};  
2506          $self->{read_until}->($self->{ct}->{pubid}, q[">],          $self->{read_until}->($self->{ct}->{pubid}, q[">],
2507                                length $self->{ct}->{pubid});                                length $self->{ct}->{pubid});
2508    
# Line 2286  sub _get_next_token ($) { Line 2517  sub _get_next_token ($) {
2517          !!!next-input-character;          !!!next-input-character;
2518          redo A;          redo A;
2519        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (192);  
2520          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2521    
2522          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2523          $self->{s_kwd} = '';            !!!cp (192);
2524          !!!next-input-character;            $self->{state} = DATA_STATE;
2525              $self->{s_kwd} = '';
2526          $self->{ct}->{quirks} = 1;            $self->{ct}->{quirks} = 1;
2527          !!!emit ($self->{ct}); # DOCTYPE          } else {
2528              !!!cp (192.1);
2529              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2530            }
2531    
2532            !!!next-input-character;
2533            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2534          redo A;          redo A;
2535        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (193);  
2536          !!!parse-error (type => 'unclosed PUBLIC literal');          !!!parse-error (type => 'unclosed PUBLIC literal');
2537    
2538          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2539          $self->{s_kwd} = '';            !!!cp (193);
2540              $self->{state} = DATA_STATE;
2541              $self->{s_kwd} = '';
2542              $self->{ct}->{quirks} = 1;
2543            } else {
2544              !!!cp (193.1);
2545              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2546            }
2547          
2548          ## reconsume          ## reconsume
2549            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2550          redo A;          redo A;
2551        } else {        } else {
2552          !!!cp (194);          !!!cp (194);
2553          $self->{ct}->{pubid} # DOCTYPE          $self->{ct}->{pubid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
             .= chr $self->{nc};  
2554          $self->{read_until}->($self->{ct}->{pubid}, q['>],          $self->{read_until}->($self->{ct}->{pubid}, q['>],
2555                                length $self->{ct}->{pubid});                                length $self->{ct}->{pubid});
2556    
# Line 2328  sub _get_next_token ($) { Line 2566  sub _get_next_token ($) {
2566          redo A;          redo A;
2567        } elsif ($self->{nc} == 0x0022) { # "        } elsif ($self->{nc} == 0x0022) { # "
2568          !!!cp (196);          !!!cp (196);
2569          $self->{ct}->{sysid} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE/ENTITY/NOTATION
2570          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED_STATE;
2571          !!!next-input-character;          !!!next-input-character;
2572          redo A;          redo A;
2573        } elsif ($self->{nc} == 0x0027) { # '        } elsif ($self->{nc} == 0x0027) { # '
2574          !!!cp (197);          !!!cp (197);
2575          $self->{ct}->{sysid} = ''; # DOCTYPE          $self->{ct}->{sysid} = ''; # DOCTYPE/ENTITY/NOTATION
2576          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;          $self->{state} = DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED_STATE;
2577          !!!next-input-character;          !!!next-input-character;
2578          redo A;          redo A;
2579        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2580          if ($self->{is_xml}) {          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2581            !!!cp (198.1);            if ($self->{is_xml}) {
2582            !!!parse-error (type => 'no SYSTEM literal');              !!!cp (198.1);
2583                !!!parse-error (type => 'no SYSTEM literal');
2584              } else {
2585                !!!cp (198);
2586              }
2587              $self->{state} = DATA_STATE;
2588              $self->{s_kwd} = '';
2589          } else {          } else {
2590            !!!cp (198);            if ($self->{ct}->{type} == NOTATION_TOKEN) {
2591                !!!cp (198.2);
2592              } else {
2593                !!!cp (198.3);
2594                !!!parse-error (type => 'no SYSTEM literal');            
2595              }
2596              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2597          }          }
2598          $self->{state} = DATA_STATE;          
         $self->{s_kwd} = '';  
2599          !!!next-input-character;          !!!next-input-character;
2600            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         !!!emit ($self->{ct}); # DOCTYPE  
   
2601          redo A;          redo A;
2602        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2603          !!!cp (199);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2604          !!!parse-error (type => 'unclosed DOCTYPE');            !!!cp (199);
2605              !!!parse-error (type => 'unclosed DOCTYPE');
2606          $self->{state} = DATA_STATE;            
2607          $self->{s_kwd} = '';            $self->{state} = DATA_STATE;
2608              $self->{s_kwd} = '';
2609              $self->{ct}->{quirks} = 1;
2610            } else {
2611              !!!parse-error (type => 'unclosed md'); ## TODO: type
2612              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2613            }
2614            
2615          ## reconsume          ## reconsume
2616            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2617          redo A;          redo A;
2618        } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [        } elsif ($self->{is_xml} and
2619                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2620                   $self->{nc} == 0x005B) { # [
2621          !!!cp (200.1);          !!!cp (200.1);
2622          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
2623          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2624          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2625            $self->{in_subset} = 1;
2626          !!!next-input-character;          !!!next-input-character;
2627            !!!emit ($self->{ct}); # DOCTYPE
2628          redo A;          redo A;
2629        } else {        } else {
         !!!cp (200);  
2630          !!!parse-error (type => 'string after PUBLIC literal');          !!!parse-error (type => 'string after PUBLIC literal');
         $self->{ct}->{quirks} = 1;  
2631    
2632          $self->{state} = BOGUS_DOCTYPE_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2633              !!!cp (200);
2634              $self->{ct}->{quirks} = 1;
2635              $self->{state} = BOGUS_DOCTYPE_STATE;
2636            } else {
2637              !!!cp (200.2);
2638              $self->{state} = BOGUS_MD_STATE;
2639            }
2640    
2641          !!!next-input-character;          !!!next-input-character;
2642          redo A;          redo A;
2643        }        }
# Line 2399  sub _get_next_token ($) { Line 2660  sub _get_next_token ($) {
2660          !!!next-input-character;          !!!next-input-character;
2661          redo A;          redo A;
2662        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
         !!!cp (204);  
2663          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
         $self->{state} = DATA_STATE;  
         $self->{s_kwd} = '';  
2664          !!!next-input-character;          !!!next-input-character;
2665    
2666          $self->{ct}->{quirks} = 1;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2667          !!!emit ($self->{ct}); # DOCTYPE            !!!cp (204);
2668              $self->{state} = DATA_STATE;
2669              $self->{s_kwd} = '';
2670              $self->{ct}->{quirks} = 1;
2671            } else {
2672              !!!cp (204.1);
2673              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2674            }
2675    
2676            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2677          redo A;          redo A;
2678        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2679          !!!cp (205);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2680          !!!parse-error (type => 'unclosed DOCTYPE');            !!!cp (205);
2681              !!!parse-error (type => 'unclosed DOCTYPE');
2682          $self->{state} = DATA_STATE;            $self->{state} = DATA_STATE;
2683          $self->{s_kwd} = '';            $self->{s_kwd} = '';
2684              $self->{ct}->{quirks} = 1;
2685            } else {
2686              !!!cp (205.1);
2687              !!!parse-error (type => 'unclosed md'); ## TODO: type
2688              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2689            }
2690            
2691          ## reconsume          ## reconsume
2692            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2693          redo A;          redo A;
2694        } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [        } elsif ($self->{is_xml} and
2695                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2696                   $self->{nc} == 0x005B) { # [
2697          !!!cp (206.1);          !!!cp (206.1);
2698          !!!parse-error (type => 'no SYSTEM literal');          !!!parse-error (type => 'no SYSTEM literal');
2699    
2700          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2701          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2702            $self->{in_subset} = 1;
2703          !!!next-input-character;          !!!next-input-character;
2704            !!!emit ($self->{ct}); # DOCTYPE
2705          redo A;          redo A;
2706        } else {        } else {
         !!!cp (206);  
2707          !!!parse-error (type => 'string after SYSTEM');          !!!parse-error (type => 'string after SYSTEM');
         $self->{ct}->{quirks} = 1;  
2708    
2709          $self->{state} = BOGUS_DOCTYPE_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2710              !!!cp (206);          
2711              $self->{ct}->{quirks} = 1;
2712              $self->{state} = BOGUS_DOCTYPE_STATE;
2713            } else {
2714              !!!cp (206.2);
2715              $self->{state} = BOGUS_MD_STATE;
2716            }
2717    
2718          !!!next-input-character;          !!!next-input-character;
2719          redo A;          redo A;
2720        }        }
# Line 2445  sub _get_next_token ($) { Line 2725  sub _get_next_token ($) {
2725          !!!next-input-character;          !!!next-input-character;
2726          redo A;          redo A;
2727        } elsif (not $self->{is_xml} and $self->{nc} == 0x003E) { # >        } elsif (not $self->{is_xml} and $self->{nc} == 0x003E) { # >
         !!!cp (208);  
2728          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2729    
2730          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2731          $self->{s_kwd} = '';            !!!cp (208);
2732              $self->{state} = DATA_STATE;
2733              $self->{s_kwd} = '';
2734              $self->{ct}->{quirks} = 1;
2735            } else {
2736              !!!cp (208.1);
2737              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2738            }
2739            
2740          !!!next-input-character;          !!!next-input-character;
2741            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2742          redo A;          redo A;
2743        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (209);  
2744          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2745    
2746          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2747          $self->{s_kwd} = '';            !!!cp (209);
2748              $self->{state} = DATA_STATE;
2749              $self->{s_kwd} = '';
2750              $self->{ct}->{quirks} = 1;
2751            } else {
2752              !!!cp (209.1);
2753              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2754            }
2755            
2756          ## reconsume          ## reconsume
2757            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
         $self->{ct}->{quirks} = 1;  
         !!!emit ($self->{ct}); # DOCTYPE  
   
2758          redo A;          redo A;
2759        } else {        } else {
2760          !!!cp (210);          !!!cp (210);
2761          $self->{ct}->{sysid} # DOCTYPE          $self->{ct}->{sysid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
             .= chr $self->{nc};  
2762          $self->{read_until}->($self->{ct}->{sysid}, q[">],          $self->{read_until}->($self->{ct}->{sysid}, q[">],
2763                                length $self->{ct}->{sysid});                                length $self->{ct}->{sysid});
2764    
# Line 2498  sub _get_next_token ($) { Line 2785  sub _get_next_token ($) {
2785    
2786          redo A;          redo A;
2787        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
         !!!cp (213);  
2788          !!!parse-error (type => 'unclosed SYSTEM literal');          !!!parse-error (type => 'unclosed SYSTEM literal');
2789    
2790          $self->{state} = DATA_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2791          $self->{s_kwd} = '';            !!!cp (213);
2792          ## reconsume            $self->{state} = DATA_STATE;
2793              $self->{s_kwd} = '';
2794          $self->{ct}->{quirks} = 1;            $self->{ct}->{quirks} = 1;
2795          !!!emit ($self->{ct}); # DOCTYPE          } else {
2796              !!!cp (213.1);
2797              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2798            }
2799    
2800            ## reconsume
2801            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2802          redo A;          redo A;
2803        } else {        } else {
2804          !!!cp (214);          !!!cp (214);
2805          $self->{ct}->{sysid} # DOCTYPE          $self->{ct}->{sysid} .= chr $self->{nc}; # DOCTYPE/ENTITY/NOTATION
             .= chr $self->{nc};  
2806          $self->{read_until}->($self->{ct}->{sysid}, q['>],          $self->{read_until}->($self->{ct}->{sysid}, q['>],
2807                                length $self->{ct}->{sysid});                                length $self->{ct}->{sysid});
2808    
# Line 2527  sub _get_next_token ($) { Line 2817  sub _get_next_token ($) {
2817          !!!next-input-character;          !!!next-input-character;
2818          redo A;          redo A;
2819        } elsif ($self->{nc} == 0x003E) { # >        } elsif ($self->{nc} == 0x003E) { # >
2820          !!!cp (216);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2821          $self->{state} = DATA_STATE;            !!!cp (216);
2822          $self->{s_kwd} = '';            $self->{state} = DATA_STATE;
2823          !!!next-input-character;            $self->{s_kwd} = '';
2824            } else {
2825          !!!emit ($self->{ct}); # DOCTYPE            !!!cp (216.1);
2826              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2827            }
2828    
2829            !!!next-input-character;
2830            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2831          redo A;          redo A;
2832    ## TODO: "NDATA"
2833        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2834          !!!cp (217);          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2835          !!!parse-error (type => 'unclosed DOCTYPE');            !!!cp (217);
2836          $self->{state} = DATA_STATE;            !!!parse-error (type => 'unclosed DOCTYPE');
2837          $self->{s_kwd} = '';            $self->{state} = DATA_STATE;
2838          ## reconsume            $self->{s_kwd} = '';
2839              $self->{ct}->{quirks} = 1;
2840          $self->{ct}->{quirks} = 1;          } else {
2841          !!!emit ($self->{ct}); # DOCTYPE            !!!cp (217.1);
2842              !!!parse-error (type => 'unclosed md'); ## TODO: type
2843              $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2844            }
2845    
2846            ## reconsume
2847            !!!emit ($self->{ct}); # DOCTYPE/ENTITY/NOTATION
2848          redo A;          redo A;
2849        } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [        } elsif ($self->{is_xml} and
2850                   $self->{ct}->{type} == DOCTYPE_TOKEN and
2851                   $self->{nc} == 0x005B) { # [
2852          !!!cp (218.1);          !!!cp (218.1);
2853          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2854          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2855            $self->{in_subset} = 1;
2856          !!!next-input-character;          !!!next-input-character;
2857            !!!emit ($self->{ct}); # DOCTYPE
2858          redo A;          redo A;
2859        } else {        } else {
         !!!cp (218);  
2860          !!!parse-error (type => 'string after SYSTEM literal');          !!!parse-error (type => 'string after SYSTEM literal');
         #$self->{ct}->{quirks} = 1;  
2861    
2862          $self->{state} = BOGUS_DOCTYPE_STATE;          if ($self->{ct}->{type} == DOCTYPE_TOKEN) {
2863              !!!cp (218);
2864              #$self->{ct}->{quirks} = 1;
2865              $self->{state} = BOGUS_DOCTYPE_STATE;
2866            } else {
2867              !!!cp (218.2);
2868              $self->{state} = BOGUS_MD_STATE;
2869            }
2870    
2871          !!!next-input-character;          !!!next-input-character;
2872          redo A;          redo A;
2873        }        }
# Line 2572  sub _get_next_token ($) { Line 2882  sub _get_next_token ($) {
2882    
2883          redo A;          redo A;
2884        } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [        } elsif ($self->{is_xml} and $self->{nc} == 0x005B) { # [
2885          if ($self->{ct}->{has_internal_subset}) { # DOCTYPE          !!!cp (220.1);
2886            !!!cp (220.2);          $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
2887            ## Stay in the state.          $self->{ct}->{has_internal_subset} = 1; # DOCTYPE
2888            !!!next-input-character;          $self->{in_subset} = 1;
2889            redo A;          !!!next-input-character;
2890          } else {          !!!emit ($self->{ct}); # DOCTYPE
2891            !!!cp (220.1);          redo A;
           $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;  
           $self->{ct}->{has_internal_subset} = 1; # DOCTYPE  
           !!!next-input-character;  
           redo A;  
         }  
2892        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
2893          !!!cp (220);          !!!cp (220);
2894          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
# Line 3065  sub _get_next_token ($) { Line 3370  sub _get_next_token ($) {
3370      ## XML-only states      ## XML-only states
3371    
3372      } elsif ($self->{state} == PI_STATE) {      } elsif ($self->{state} == PI_STATE) {
3373          ## XML5: "Pi state" and "DOCTYPE pi state".
3374    
3375        if ($is_space->{$self->{nc}} or        if ($is_space->{$self->{nc}} or
3376            $self->{nc} == 0x003F or # ? ## XML5: Same as "Anything else"            $self->{nc} == 0x003F or # ?
3377            $self->{nc} == -1) {            $self->{nc} == -1) {
3378            ## XML5: U+003F: "pi state": Same as "Anything else"; "DOCTYPE
3379            ## pi state": Switch to the "DOCTYPE pi after state".  EOF:
3380            ## "DOCTYPE pi state": Parse error, switch to the "data
3381            ## state".
3382          !!!parse-error (type => 'bare pio', ## TODO: type          !!!parse-error (type => 'bare pio', ## TODO: type
3383                          line => $self->{line_prev},                          line => $self->{line_prev},
3384                          column => $self->{column_prev}                          column => $self->{column_prev}
# Line 3082  sub _get_next_token ($) { Line 3393  sub _get_next_token ($) {
3393                        };                        };
3394          redo A;          redo A;
3395        } else {        } else {
3396            ## XML5: "DOCTYPE pi state": Stay in the state.
3397          $self->{ct} = {type => PI_TOKEN,          $self->{ct} = {type => PI_TOKEN,
3398                         target => chr $self->{nc},                         target => chr $self->{nc},
3399                         data => '',                         data => '',
# Line 3099  sub _get_next_token ($) { Line 3411  sub _get_next_token ($) {
3411          redo A;          redo A;
3412        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
3413          !!!parse-error (type => 'no pic'); ## TODO: type          !!!parse-error (type => 'no pic'); ## TODO: type
3414          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
3415          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3416            } else {
3417              $self->{state} = DATA_STATE;
3418              $self->{s_kwd} = '';
3419            }
3420          ## Reconsume.          ## Reconsume.
3421          !!!emit ($self->{ct}); # pi          !!!emit ($self->{ct}); # pi
3422          redo A;          redo A;
# Line 3131  sub _get_next_token ($) { Line 3447  sub _get_next_token ($) {
3447          redo A;          redo A;
3448        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
3449          !!!parse-error (type => 'no pic'); ## TODO: type          !!!parse-error (type => 'no pic'); ## TODO: type
3450          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
3451          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state"
3452            } else {
3453              $self->{state} = DATA_STATE;
3454              $self->{s_kwd} = '';
3455            }
3456          ## Reprocess.          ## Reprocess.
3457          !!!emit ($self->{ct}); # pi          !!!emit ($self->{ct}); # pi
3458          redo A;          redo A;
# Line 3146  sub _get_next_token ($) { Line 3466  sub _get_next_token ($) {
3466          redo A;          redo A;
3467        }        }
3468      } elsif ($self->{state} == PI_AFTER_STATE) {      } elsif ($self->{state} == PI_AFTER_STATE) {
3469          ## XML5: Part of "Pi after state".
3470    
3471        if ($self->{nc} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
3472          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
3473          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3474            } else {
3475              $self->{state} = DATA_STATE;
3476              $self->{s_kwd} = '';
3477            }
3478          !!!next-input-character;          !!!next-input-character;
3479          !!!emit ($self->{ct}); # pi          !!!emit ($self->{ct}); # pi
3480          redo A;          redo A;
# Line 3171  sub _get_next_token ($) { Line 3497  sub _get_next_token ($) {
3497          redo A;          redo A;
3498        }        }
3499      } elsif ($self->{state} == PI_DATA_AFTER_STATE) {      } elsif ($self->{state} == PI_DATA_AFTER_STATE) {
3500        ## XML5: Same as "pi after state" in XML5        ## XML5: Same as "pi after state" and "DOCTYPE pi after state".
3501    
3502        if ($self->{nc} == 0x003E) { # >        if ($self->{nc} == 0x003E) { # >
3503          $self->{state} = DATA_STATE;          if ($self->{in_subset}) {
3504          $self->{s_kwd} = '';            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3505            } else {
3506              $self->{state} = DATA_STATE;
3507              $self->{s_kwd} = '';
3508            }
3509          !!!next-input-character;          !!!next-input-character;
3510          !!!emit ($self->{ct}); # pi          !!!emit ($self->{ct}); # pi
3511          redo A;          redo A;
# Line 3192  sub _get_next_token ($) { Line 3523  sub _get_next_token ($) {
3523    
3524      } elsif ($self->{state} == DOCTYPE_INTERNAL_SUBSET_STATE) {      } elsif ($self->{state} == DOCTYPE_INTERNAL_SUBSET_STATE) {
3525        if ($self->{nc} == 0x003C) { # <        if ($self->{nc} == 0x003C) { # <
3526          ## TODO:          $self->{state} = DOCTYPE_TAG_STATE;
3527          !!!next-input-character;          !!!next-input-character;
3528          redo A;          redo A;
3529        } elsif ($self->{nc} == 0x0025) { # %        } elsif ($self->{nc} == 0x0025) { # %
# Line 3202  sub _get_next_token ($) { Line 3533  sub _get_next_token ($) {
3533          !!!next-input-character;          !!!next-input-character;
3534          redo A;          redo A;
3535        } elsif ($self->{nc} == 0x005D) { # ]        } elsif ($self->{nc} == 0x005D) { # ]
3536            delete $self->{in_subset};
3537          $self->{state} = DOCTYPE_INTERNAL_SUBSET_AFTER_STATE;          $self->{state} = DOCTYPE_INTERNAL_SUBSET_AFTER_STATE;
3538          !!!next-input-character;          !!!next-input-character;
3539          redo A;          redo A;
# Line 3211  sub _get_next_token ($) { Line 3543  sub _get_next_token ($) {
3543          redo A;          redo A;
3544        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
3545          !!!parse-error (type => 'unclosed internal subset'); ## TODO: type          !!!parse-error (type => 'unclosed internal subset'); ## TODO: type
3546            delete $self->{in_subset};
3547          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
3548          $self->{s_kwd} = '';          $self->{s_kwd} = '';
3549          ## Reconsume.          ## Reconsume.
3550          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3551          redo A;          redo A;
3552        } else {        } else {
3553          unless ($self->{internal_subset_tainted}) {          unless ($self->{internal_subset_tainted}) {
# Line 3231  sub _get_next_token ($) { Line 3564  sub _get_next_token ($) {
3564          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
3565          $self->{s_kwd} = '';          $self->{s_kwd} = '';
3566          !!!next-input-character;          !!!next-input-character;
3567          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3568          redo A;          redo A;
3569        } elsif ($self->{nc} == -1) {        } elsif ($self->{nc} == -1) {
3570          !!!parse-error (type => 'unclosed DOCTYPE');          !!!parse-error (type => 'unclosed DOCTYPE');
3571          $self->{state} = DATA_STATE;          $self->{state} = DATA_STATE;
3572          $self->{s_kwd} = '';          $self->{s_kwd} = '';
3573          ## Reconsume.          ## Reconsume.
3574          !!!emit ($self->{ct}); # DOCTYPE          !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3575          redo A;          redo A;
3576        } else {        } else {
3577          ## XML5: No parse error and stay in the state.          ## XML5: No parse error and stay in the state.
3578          !!!parse-error (type => 'string after internal subset'); ## TODO: type          !!!parse-error (type => 'string after internal subset'); ## TODO: type
3579    
3580          $self->{state} = BOGUS_DOCTYPE_STATE;          $self->{state} = BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE;
3581            !!!next-input-character;
3582            redo A;
3583          }
3584        } elsif ($self->{state} == BOGUS_DOCTYPE_INTERNAL_SUBSET_AFTER_STATE) {
3585          if ($self->{nc} == 0x003E) { # >
3586            $self->{state} = DATA_STATE;
3587            $self->{s_kwd} = '';
3588            !!!next-input-character;
3589            !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3590            redo A;
3591          } elsif ($self->{nc} == -1) {
3592            $self->{state} = DATA_STATE;
3593            $self->{s_kwd} = '';
3594            ## Reconsume.
3595            !!!emit ({type => END_OF_DOCTYPE_TOKEN});
3596            redo A;
3597          } else {
3598            ## Stay in the state.
3599            !!!next-input-character;
3600            redo A;
3601          }
3602        } elsif ($self->{state} == DOCTYPE_TAG_STATE) {
3603          if ($self->{nc} == 0x0021) { # !
3604            $self->{state} = DOCTYPE_MARKUP_DECLARATION_OPEN_STATE;
3605            !!!next-input-character;
3606            redo A;
3607          } elsif ($self->{nc} == 0x003F) { # ?
3608            $self->{state} = PI_STATE;
3609            !!!next-input-character;
3610            redo A;
3611          } elsif ($self->{nc} == -1) {
3612            !!!parse-error (type => 'bare stago');
3613            $self->{state} = DATA_STATE;
3614            $self->{s_kwd} = '';
3615            ## Reconsume.
3616            redo A;
3617          } else {
3618            !!!parse-error (type => 'bare stago', ## XML5: Not a parse error.
3619                            line => $self->{line_prev},
3620                            column => $self->{column_prev});
3621            $self->{state} = BOGUS_COMMENT_STATE;
3622            $self->{ct} = {type => COMMENT_TOKEN,
3623                           data => '',
3624                          }; ## NOTE: Will be discarded.
3625            !!!next-input-character;
3626            redo A;
3627          }
3628        } elsif ($self->{state} == DOCTYPE_MARKUP_DECLARATION_OPEN_STATE) {
3629          ## XML5: "DOCTYPE markup declaration state".
3630          
3631          if ($self->{nc} == 0x002D) { # -
3632            $self->{state} = MD_HYPHEN_STATE;
3633            !!!next-input-character;
3634            redo A;
3635          } elsif ($self->{nc} == 0x0045 or # E
3636                   $self->{nc} == 0x0065) { # e
3637            $self->{state} = MD_E_STATE;
3638            $self->{kwd} = chr $self->{nc};
3639            !!!next-input-character;
3640            redo A;
3641          } elsif ($self->{nc} == 0x0041 or # A
3642                   $self->{nc} == 0x0061) { # a
3643            $self->{state} = MD_ATTLIST_STATE;
3644            $self->{kwd} = chr $self->{nc};
3645            !!!next-input-character;
3646            redo A;
3647          } elsif ($self->{nc} == 0x004E or # N
3648                   $self->{nc} == 0x006E) { # n
3649            $self->{state} = MD_NOTATION_STATE;
3650            $self->{kwd} = chr $self->{nc};
3651            !!!next-input-character;
3652            redo A;
3653          } else {
3654            #
3655          }
3656          
3657          ## XML5: No parse error.
3658          !!!parse-error (type => 'bogus comment',
3659                          line => $self->{line_prev},
3660                          column => $self->{column_prev} - 1);
3661          ## Reconsume.
3662          $self->{state} = BOGUS_COMMENT_STATE;
3663          $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded.
3664          redo A;
3665        } elsif ($self->{state} == MD_E_STATE) {
3666          if ($self->{nc} == 0x004E or # N
3667              $self->{nc} == 0x006E) { # n
3668            $self->{state} = MD_ENTITY_STATE;
3669            $self->{kwd} .= chr $self->{nc};
3670            !!!next-input-character;
3671            redo A;
3672          } elsif ($self->{nc} == 0x004C or # L
3673                   $self->{nc} == 0x006C) { # l
3674            ## XML5: <!ELEMENT> not supported.
3675            $self->{state} = MD_ELEMENT_STATE;
3676            $self->{kwd} .= chr $self->{nc};
3677            !!!next-input-character;
3678            redo A;
3679          } else {
3680            ## XML5: No parse error.
3681            !!!parse-error (type => 'bogus comment',
3682                            line => $self->{line_prev},
3683                            column => $self->{column_prev} - 2
3684                                + 1 * ($self->{nc} == -1));
3685            ## Reconsume.
3686            $self->{state} = BOGUS_COMMENT_STATE;
3687            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3688            redo A;
3689          }
3690        } elsif ($self->{state} == MD_ENTITY_STATE) {
3691          if ($self->{nc} == [
3692                undef,
3693                undef,
3694                0x0054, # T
3695                0x0049, # I
3696                0x0054, # T
3697              ]->[length $self->{kwd}] or
3698              $self->{nc} == [
3699                undef,
3700                undef,
3701                0x0074, # t
3702                0x0069, # i
3703                0x0074, # t
3704              ]->[length $self->{kwd}]) {
3705            ## Stay in the state.
3706            $self->{kwd} .= chr $self->{nc};
3707            !!!next-input-character;
3708            redo A;
3709          } elsif ((length $self->{kwd}) == 5 and
3710                   ($self->{nc} == 0x0059 or # Y
3711                    $self->{nc} == 0x0079)) { # y
3712            if ($self->{kwd} ne 'ENTIT' or $self->{nc} == 0x0079) {
3713              !!!parse-error (type => 'lowercase keyword', ## TODO: type
3714                              text => 'ENTITY',
3715                              line => $self->{line_prev},
3716                              column => $self->{column_prev} - 4);
3717            }
3718            $self->{ct} = {type => GENERAL_ENTITY_TOKEN, name => '',
3719                           line => $self->{line_prev},
3720                           column => $self->{column_prev} - 6};
3721            $self->{state} = DOCTYPE_MD_STATE;
3722            !!!next-input-character;
3723            redo A;
3724          } else {
3725            !!!parse-error (type => 'bogus comment',
3726                            line => $self->{line_prev},
3727                            column => $self->{column_prev} - 1
3728                                - (length $self->{kwd})
3729                                + 1 * ($self->{nc} == -1));
3730            $self->{state} = BOGUS_COMMENT_STATE;
3731            ## Reconsume.
3732            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3733            redo A;
3734          }
3735        } elsif ($self->{state} == MD_ELEMENT_STATE) {
3736          if ($self->{nc} == [
3737               undef,
3738               undef,
3739               0x0045, # E
3740               0x004D, # M
3741               0x0045, # E
3742               0x004E, # N
3743              ]->[length $self->{kwd}] or
3744              $self->{nc} == [
3745               undef,
3746               undef,
3747               0x0065, # e
3748               0x006D, # m
3749               0x0065, # e
3750               0x006E, # n
3751              ]->[length $self->{kwd}]) {
3752            ## Stay in the state.
3753            $self->{kwd} .= chr $self->{nc};
3754            !!!next-input-character;
3755            redo A;
3756          } elsif ((length $self->{kwd}) == 6 and
3757                   ($self->{nc} == 0x0054 or # T
3758                    $self->{nc} == 0x0074)) { # t
3759            if ($self->{kwd} ne 'ELEMEN' or $self->{nc} == 0x0074) {
3760              !!!parse-error (type => 'lowercase keyword', ## TODO: type
3761                              text => 'ELEMENT',
3762                              line => $self->{line_prev},
3763                              column => $self->{column_prev} - 5);
3764            }
3765            $self->{ct} = {type => ELEMENT_TOKEN, name => '',
3766                           line => $self->{line_prev},
3767                           column => $self->{column_prev} - 6};
3768            $self->{state} = DOCTYPE_MD_STATE;
3769            !!!next-input-character;
3770            redo A;
3771          } else {
3772            !!!parse-error (type => 'bogus comment',
3773                            line => $self->{line_prev},
3774                            column => $self->{column_prev} - 1
3775                                - (length $self->{kwd})
3776                                + 1 * ($self->{nc} == -1));
3777            $self->{state} = BOGUS_COMMENT_STATE;
3778            ## Reconsume.
3779            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3780            redo A;
3781          }
3782        } elsif ($self->{state} == MD_ATTLIST_STATE) {
3783          if ($self->{nc} == [
3784               undef,
3785               0x0054, # T
3786               0x0054, # T
3787               0x004C, # L
3788               0x0049, # I
3789               0x0053, # S
3790              ]->[length $self->{kwd}] or
3791              $self->{nc} == [
3792               undef,
3793               0x0074, # t
3794               0x0074, # t
3795               0x006C, # l
3796               0x0069, # i
3797               0x0073, # s
3798              ]->[length $self->{kwd}]) {
3799            ## Stay in the state.
3800            $self->{kwd} .= chr $self->{nc};
3801            !!!next-input-character;
3802            redo A;
3803          } elsif ((length $self->{kwd}) == 6 and
3804                   ($self->{nc} == 0x0054 or # T
3805                    $self->{nc} == 0x0074)) { # t
3806            if ($self->{kwd} ne 'ATTLIS' or $self->{nc} == 0x0074) {
3807              !!!parse-error (type => 'lowercase keyword', ## TODO: type
3808                              text => 'ATTLIST',
3809                              line => $self->{line_prev},
3810                              column => $self->{column_prev} - 5);
3811            }
3812            $self->{ct} = {type => ATTLIST_TOKEN, name => '',
3813                           attrdefs => [],
3814                           line => $self->{line_prev},
3815                           column => $self->{column_prev} - 6};
3816            $self->{state} = DOCTYPE_MD_STATE;
3817            !!!next-input-character;
3818            redo A;
3819          } else {
3820            !!!parse-error (type => 'bogus comment',
3821                            line => $self->{line_prev},
3822                            column => $self->{column_prev} - 1
3823                                 - (length $self->{kwd})
3824                                 + 1 * ($self->{nc} == -1));
3825            $self->{state} = BOGUS_COMMENT_STATE;
3826            ## Reconsume.
3827            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3828            redo A;
3829          }
3830        } elsif ($self->{state} == MD_NOTATION_STATE) {
3831          if ($self->{nc} == [
3832               undef,
3833               0x004F, # O
3834               0x0054, # T
3835               0x0041, # A
3836               0x0054, # T
3837               0x0049, # I
3838               0x004F, # O
3839              ]->[length $self->{kwd}] or
3840              $self->{nc} == [
3841               undef,
3842               0x006F, # o
3843               0x0074, # t
3844               0x0061, # a
3845               0x0074, # t
3846               0x0069, # i
3847               0x006F, # o
3848              ]->[length $self->{kwd}]) {
3849            ## Stay in the state.
3850            $self->{kwd} .= chr $self->{nc};
3851            !!!next-input-character;
3852            redo A;
3853          } elsif ((length $self->{kwd}) == 7 and
3854                   ($self->{nc} == 0x004E or # N
3855                    $self->{nc} == 0x006E)) { # n
3856            if ($self->{kwd} ne 'NOTATIO' or $self->{nc} == 0x006E) {
3857              !!!parse-error (type => 'lowercase keyword', ## TODO: type
3858                              text => 'NOTATION',
3859                              line => $self->{line_prev},
3860                              column => $self->{column_prev} - 6);
3861            }
3862            $self->{ct} = {type => NOTATION_TOKEN, name => '',
3863                           line => $self->{line_prev},
3864                           column => $self->{column_prev} - 6};
3865            $self->{state} = DOCTYPE_MD_STATE;
3866            !!!next-input-character;
3867            redo A;
3868          } else {
3869            !!!parse-error (type => 'bogus comment',
3870                            line => $self->{line_prev},
3871                            column => $self->{column_prev} - 1
3872                                - (length $self->{kwd})
3873                                + 1 * ($self->{nc} == -1));
3874            $self->{state} = BOGUS_COMMENT_STATE;
3875            ## Reconsume.
3876            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3877            redo A;
3878          }
3879        } elsif ($self->{state} == DOCTYPE_MD_STATE) {
3880          ## XML5: "DOCTYPE ENTITY state", "DOCTYPE ATTLIST state", and
3881          ## "DOCTYPE NOTATION state".
3882    
3883          if ($is_space->{$self->{nc}}) {
3884            ## XML5: [NOTATION] Switch to the "DOCTYPE NOTATION identifier state".
3885            $self->{state} = BEFORE_MD_NAME_STATE;
3886            !!!next-input-character;
3887            redo A;
3888          } elsif ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN and
3889                   $self->{nc} == 0x0025) { # %
3890            ## XML5: Switch to the "DOCTYPE bogus comment state".
3891            !!!parse-error (type => 'no space before md name'); ## TODO: type
3892            $self->{state} = DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE;
3893            !!!next-input-character;
3894            redo A;
3895          } elsif ($self->{nc} == -1) {
3896            !!!parse-error (type => 'unclosed md'); ## TODO: type
3897            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
3898            ## Reconsume.
3899            redo A;
3900          } elsif ($self->{nc} == 0x003E) { # >
3901            ## XML5: Switch to the "DOCTYPE bogus comment state".
3902            !!!parse-error (type => 'no md name'); ## TODO: type
3903            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3904            !!!next-input-character;
3905            redo A;
3906          } else {
3907            ## XML5: Switch to the "DOCTYPE bogus comment state".
3908            !!!parse-error (type => 'no space before md name'); ## TODO: type
3909            $self->{state} = BEFORE_MD_NAME_STATE;
3910            redo A;
3911          }
3912        } elsif ($self->{state} == BEFORE_MD_NAME_STATE) {
3913          ## XML5: "DOCTYPE ENTITY parameter state", "DOCTYPE ENTITY type
3914          ## before state", "DOCTYPE ATTLIST name before state".
3915    
3916          if ($is_space->{$self->{nc}}) {
3917            ## Stay in the state.
3918            !!!next-input-character;
3919            redo A;
3920          } elsif ($self->{ct}->{type} == GENERAL_ENTITY_TOKEN and
3921                   $self->{nc} == 0x0025) { # %
3922            $self->{state} = DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE;
3923            !!!next-input-character;
3924            redo A;
3925          } elsif ($self->{nc} == 0x003E) { # >
3926            ## XML5: Same as "Anything else".
3927            !!!parse-error (type => 'no md name'); ## TODO: type
3928            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3929            !!!next-input-character;
3930            redo A;
3931          } elsif ($self->{nc} == -1) {
3932            !!!parse-error (type => 'unclosed md'); ## TODO: type
3933            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
3934            ## Reconsume.
3935            redo A;
3936          } else {
3937            ## XML5: [ATTLIST] Not defined yet.
3938            $self->{ct}->{name} .= chr $self->{nc};
3939            $self->{state} = MD_NAME_STATE;
3940            !!!next-input-character;
3941            redo A;
3942          }
3943        } elsif ($self->{state} == DOCTYPE_ENTITY_PARAMETER_BEFORE_STATE) {
3944          if ($is_space->{$self->{nc}}) {
3945            ## XML5: Switch to the "DOCTYPE ENTITY parameter state".
3946            $self->{ct}->{type} = PARAMETER_ENTITY_TOKEN;
3947            $self->{state} = BEFORE_MD_NAME_STATE;
3948            !!!next-input-character;
3949            redo A;
3950          } elsif ($self->{nc} == 0x003E) { # >
3951            ## XML5: Same as "Anything else".
3952            !!!parse-error (type => 'no md name'); ## TODO: type
3953            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3954            !!!next-input-character;
3955            redo A;
3956          } elsif ($self->{nc} == -1) {
3957            !!!parse-error (type => 'unclosed md');
3958            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
3959            ## Reconsume.
3960            redo A;
3961          } else {
3962            ## XML5: No parse error.
3963            !!!parse-error (type => 'no space after ENTITY percent'); ## TODO: type
3964            $self->{state} = BOGUS_COMMENT_STATE;
3965            $self->{ct} = {type => COMMENT_TOKEN, data => ''}; ## Will be discarded
3966            ## Reconsume.
3967            redo A;
3968          }
3969        } elsif ($self->{state} == MD_NAME_STATE) {
3970          ## XML5: "DOCTYPE ENTITY name state" and "DOCTYPE ATTLIST name state".
3971          
3972          if ($is_space->{$self->{nc}}) {
3973            if ($self->{ct}->{type} == ATTLIST_TOKEN) {
3974              $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
3975            } elsif ($self->{ct}->{type} == ELEMENT_TOKEN) {
3976              ## TODO: ...
3977              $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
3978            } else { # ENTITY/NOTATION
3979              $self->{state} = AFTER_DOCTYPE_NAME_STATE;
3980            }
3981            !!!next-input-character;
3982            redo A;
3983          } elsif ($self->{nc} == 0x003E) { # >
3984            if ($self->{ct}->{type} == ATTLIST_TOKEN) {
3985              #
3986            } else {
3987              !!!parse-error (type => 'no md def'); ## TODO: type
3988            }
3989            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
3990            !!!next-input-character;
3991            !!!emit ($self->{ct}); # ELEMENT/ENTITY/ATTLIST/NOTATION
3992            redo A;
3993          } elsif ($self->{nc} == -1) {
3994            ## XML5: [ATTLIST] No parse error.
3995            !!!parse-error (type => 'unclosed md');
3996            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
3997            ## Reconsume.
3998            !!!emit ($self->{ct}); # ELEMENT/ENTITY/ATTLIST/NOTATION
3999            redo A;
4000          } else {
4001            ## XML5: [ATTLIST] Not defined yet.
4002            $self->{ct}->{name} .= chr $self->{nc};
4003            ## Stay in the state.
4004            !!!next-input-character;
4005            redo A;
4006          }
4007        } elsif ($self->{state} == DOCTYPE_ATTLIST_NAME_AFTER_STATE) {
4008          if ($is_space->{$self->{nc}}) {
4009            ## Stay in the state.
4010            !!!next-input-character;
4011            redo A;
4012          } elsif ($self->{nc} == 0x003E) { # >
4013            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4014            !!!next-input-character;
4015            !!!emit ($self->{ct}); # ATTLIST
4016            redo A;
4017          } elsif ($self->{nc} == -1) {
4018            ## XML5: No parse error.
4019            !!!parse-error (type => 'unclosed md'); ## TODO: type
4020            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4021            !!!emit ($self->{ct});
4022            redo A;
4023          } else {
4024            ## XML5: Not defined yet.
4025            $self->{ca} = {name => chr ($self->{nc}), # attrdef
4026                           tokens => [],
4027                           line => $self->{line}, column => $self->{column}};
4028            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE;
4029            !!!next-input-character;
4030            redo A;
4031          }
4032        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_NAME_STATE) {
4033          if ($is_space->{$self->{nc}}) {
4034            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE;
4035            !!!next-input-character;
4036            redo A;
4037          } elsif ($self->{nc} == 0x003E) { # >
4038            ## XML5: Same as "anything else".
4039            !!!parse-error (type => 'no attr type'); ## TODO: type
4040            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4041            !!!next-input-character;
4042            !!!emit ($self->{ct}); # ATTLIST
4043            redo A;
4044          } elsif ($self->{nc} == 0x0028) { # (
4045            ## XML5: Same as "anything else".
4046            !!!parse-error (type => 'no space before paren'); ## TODO: type
4047            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4048            !!!next-input-character;
4049            redo A;
4050          } elsif ($self->{nc} == -1) {
4051            ## XML5: No parse error.
4052            !!!parse-error (type => 'unclosed md'); ## TODO: type
4053            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4054            !!!next-input-character;
4055            !!!emit ($self->{ct}); # ATTLIST
4056            redo A;
4057          } else {
4058            ## XML5: Not defined yet.
4059            $self->{ca}->{name} .= chr $self->{nc};
4060            ## Stay in the state.
4061            !!!next-input-character;
4062            redo A;
4063          }
4064        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_NAME_AFTER_STATE) {
4065          if ($is_space->{$self->{nc}}) {
4066            ## Stay in the state.
4067            !!!next-input-character;
4068            redo A;
4069          } elsif ($self->{nc} == 0x003E) { # >
4070            ## XML5: Same as "anything else".
4071            !!!parse-error (type => 'no attr type'); ## TODO: type
4072            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4073            !!!next-input-character;
4074            !!!emit ($self->{ct}); # ATTLIST
4075            redo A;
4076          } elsif ($self->{nc} == 0x0028) { # (
4077            ## XML5: Same as "anything else".
4078            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4079            !!!next-input-character;
4080            redo A;
4081          } elsif ($self->{nc} == -1) {
4082            ## XML5: No parse error.
4083            !!!parse-error (type => 'unclosed md'); ## TODO: type
4084            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4085            !!!next-input-character;
4086            !!!emit ($self->{ct});
4087            redo A;
4088          } else {
4089            ## XML5: Not defined yet.
4090            $self->{ca}->{type} = chr $self->{nc};
4091            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE;
4092            !!!next-input-character;
4093            redo A;
4094          }
4095        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_STATE) {
4096          if ($is_space->{$self->{nc}}) {
4097            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE;
4098            !!!next-input-character;
4099            redo A;
4100          } elsif ($self->{nc} == 0x0023) { # #
4101            ## XML5: Same as "anything else".
4102            !!!parse-error (type => 'no space before default value'); ## TODO: type
4103            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4104            !!!next-input-character;
4105            redo A;
4106          } elsif ($self->{nc} == 0x0022) { # "
4107            ## XML5: Same as "anything else".
4108            !!!parse-error (type => 'no space before default value'); ## TODO: type
4109            $self->{ca}->{value} = '';
4110            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4111            !!!next-input-character;
4112            redo A;
4113          } elsif ($self->{nc} == 0x0027) { # '
4114            ## XML5: Same as "anything else".
4115            !!!parse-error (type => 'no space before default value'); ## TODO: type
4116            $self->{ca}->{value} = '';
4117            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4118            !!!next-input-character;
4119            redo A;
4120          } elsif ($self->{nc} == 0x003E) { # >
4121            ## XML5: Same as "anything else".
4122            !!!parse-error (type => 'no attr default'); ## TODO: type
4123            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4124            !!!next-input-character;
4125            !!!emit ($self->{ct}); # ATTLIST
4126            redo A;
4127          } elsif ($self->{nc} == 0x0028) { # (
4128            ## XML5: Same as "anything else".
4129            !!!parse-error (type => 'no space before paren'); ## TODO: type
4130            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4131            !!!next-input-character;
4132            redo A;
4133          } elsif ($self->{nc} == -1) {
4134            ## XML5: No parse error.
4135            !!!parse-error (type => 'unclosed md'); ## TODO: type
4136            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4137            !!!next-input-character;
4138            !!!emit ($self->{ct});
4139            redo A;
4140          } else {
4141            ## XML5: Not defined yet.
4142            $self->{ca}->{type} .= chr $self->{nc};
4143            ## Stay in the state.
4144            !!!next-input-character;
4145            redo A;
4146          }
4147        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_TYPE_AFTER_STATE) {
4148          if ($is_space->{$self->{nc}}) {
4149            ## Stay in the state.
4150            !!!next-input-character;
4151            redo A;
4152          } elsif ($self->{nc} == 0x0028) { # (
4153            ## XML5: Same as "anything else".
4154            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4155            !!!next-input-character;
4156            redo A;
4157          } elsif ($self->{nc} == 0x0023) { # #
4158            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4159            !!!next-input-character;
4160            redo A;
4161          } elsif ($self->{nc} == 0x0022) { # "
4162            ## XML5: Same as "anything else".
4163            $self->{ca}->{value} = '';
4164            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4165            !!!next-input-character;
4166            redo A;
4167          } elsif ($self->{nc} == 0x0027) { # '
4168            ## XML5: Same as "anything else".
4169            $self->{ca}->{value} = '';
4170            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4171            !!!next-input-character;
4172            redo A;
4173          } elsif ($self->{nc} == 0x003E) { # >
4174            ## XML5: Same as "anything else".
4175            !!!parse-error (type => 'no attr default'); ## TODO: type
4176            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4177            !!!next-input-character;
4178            !!!emit ($self->{ct}); # ATTLIST
4179            redo A;
4180          } elsif ($self->{nc} == -1) {
4181            ## XML5: No parse error.
4182            !!!parse-error (type => 'unclosed md'); ## TODO: type
4183            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4184            !!!next-input-character;
4185            !!!emit ($self->{ct});
4186            redo A;
4187          } else {
4188            ## XML5: Switch to the "DOCTYPE bogus comment state".
4189            !!!parse-error (type => 'unquoted attr value'); ## TODO: type
4190            $self->{ca}->{value} = '';
4191            $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4192            ## Reconsume.
4193            redo A;
4194          }
4195        } elsif ($self->{state} == BEFORE_ALLOWED_TOKEN_STATE) {
4196          if ($is_space->{$self->{nc}}) {
4197            ## Stay in the state.
4198            !!!next-input-character;
4199            redo A;
4200          } elsif ($self->{nc} == 0x007C) { # |
4201            !!!parse-error (type => 'empty allowed token'); ## TODO: type
4202            ## Stay in the state.
4203            !!!next-input-character;
4204            redo A;
4205          } elsif ($self->{nc} == 0x0029) { # )
4206            !!!parse-error (type => 'empty allowed token'); ## TODO: type
4207            $self->{state} = AFTER_ALLOWED_TOKENS_STATE;
4208            !!!next-input-character;
4209            redo A;
4210          } elsif ($self->{nc} == 0x003E) { # >
4211            !!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type
4212            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4213            !!!next-input-character;
4214            !!!emit ($self->{ct}); # ATTLIST
4215            redo A;
4216          } elsif ($self->{nc} == -1) {
4217            ## XML5: No parse error.
4218            !!!parse-error (type => 'unclosed md'); ## TODO: type
4219            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4220            !!!next-input-character;
4221            !!!emit ($self->{ct});
4222            redo A;
4223          } else {
4224            push @{$self->{ca}->{tokens}}, chr $self->{nc};
4225            $self->{state} = ALLOWED_TOKEN_STATE;
4226            !!!next-input-character;
4227            redo A;
4228          }
4229        } elsif ($self->{state} == ALLOWED_TOKEN_STATE) {
4230          if ($is_space->{$self->{nc}}) {
4231            $self->{state} = AFTER_ALLOWED_TOKEN_STATE;
4232            !!!next-input-character;
4233            redo A;
4234          } elsif ($self->{nc} == 0x007C) { # |
4235            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4236            !!!next-input-character;
4237            redo A;
4238          } elsif ($self->{nc} == 0x0029) { # )
4239            $self->{state} = AFTER_ALLOWED_TOKENS_STATE;
4240            !!!next-input-character;
4241            redo A;
4242          } elsif ($self->{nc} == 0x003E) { # >
4243            !!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type
4244            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4245            !!!next-input-character;
4246            !!!emit ($self->{ct}); # ATTLIST
4247            redo A;
4248          } elsif ($self->{nc} == -1) {
4249            ## XML5: No parse error.
4250            !!!parse-error (type => 'unclosed md'); ## TODO: type
4251            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4252            !!!next-input-character;
4253            !!!emit ($self->{ct});
4254            redo A;
4255          } else {
4256            $self->{ca}->{tokens}->[-1] .= chr $self->{nc};
4257            ## Stay in the state.
4258            !!!next-input-character;
4259            redo A;
4260          }
4261        } elsif ($self->{state} == AFTER_ALLOWED_TOKEN_STATE) {
4262          if ($is_space->{$self->{nc}}) {
4263            ## Stay in the state.
4264            !!!next-input-character;
4265            redo A;
4266          } elsif ($self->{nc} == 0x007C) { # |
4267            $self->{state} = BEFORE_ALLOWED_TOKEN_STATE;
4268            !!!next-input-character;
4269            redo A;
4270          } elsif ($self->{nc} == 0x0029) { # )
4271            $self->{state} = AFTER_ALLOWED_TOKENS_STATE;
4272            !!!next-input-character;
4273            redo A;
4274          } elsif ($self->{nc} == 0x003E) { # >
4275            !!!parse-error (type => 'unclosed allowed tokens'); ## TODO: type
4276            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4277            !!!next-input-character;
4278            !!!emit ($self->{ct}); # ATTLIST
4279            redo A;
4280          } elsif ($self->{nc} == -1) {
4281            ## XML5: No parse error.
4282            !!!parse-error (type => 'unclosed md'); ## TODO: type
4283            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4284            !!!next-input-character;
4285            !!!emit ($self->{ct});
4286            redo A;
4287          } else {
4288            !!!parse-error (type => 'space in allowed token', ## TODO: type
4289                            line => $self->{line_prev},
4290                            column => $self->{column_prev});
4291            $self->{ca}->{tokens}->[-1] .= ' ' . chr $self->{nc};
4292            $self->{state} = ALLOWED_TOKEN_STATE;
4293            !!!next-input-character;
4294            redo A;
4295          }
4296        } elsif ($self->{state} == AFTER_ALLOWED_TOKENS_STATE) {
4297          if ($is_space->{$self->{nc}}) {
4298            $self->{state} = BEFORE_ATTR_DEFAULT_STATE;
4299            !!!next-input-character;
4300            redo A;
4301          } elsif ($self->{nc} == 0x0023) { # #
4302            !!!parse-error (type => 'no space before default value'); ## TODO: type
4303            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4304            !!!next-input-character;
4305            redo A;
4306          } elsif ($self->{nc} == 0x0022) { # "
4307            !!!parse-error (type => 'no space before default value'); ## TODO: type
4308            $self->{ca}->{value} = '';
4309            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4310            !!!next-input-character;
4311            redo A;
4312          } elsif ($self->{nc} == 0x0027) { # '
4313            !!!parse-error (type => 'no space before default value'); ## TODO: type
4314            $self->{ca}->{value} = '';
4315            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4316            !!!next-input-character;
4317            redo A;
4318          } elsif ($self->{nc} == 0x003E) { # >
4319            !!!parse-error (type => 'no attr default'); ## TODO: type
4320            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4321            !!!next-input-character;
4322            !!!emit ($self->{ct}); # ATTLIST
4323            redo A;
4324          } elsif ($self->{nc} == -1) {
4325            !!!parse-error (type => 'unclosed md'); ## TODO: type
4326            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4327            !!!next-input-character;
4328            !!!emit ($self->{ct});
4329            redo A;
4330          } else {
4331            !!!parse-error (type => 'unquoted attr value'); ## TODO: type
4332            $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4333            ## Reconsume.
4334            redo A;
4335          }
4336        } elsif ($self->{state} == BEFORE_ATTR_DEFAULT_STATE) {
4337          if ($is_space->{$self->{nc}}) {
4338            ## Stay in the state.
4339            !!!next-input-character;
4340            redo A;
4341          } elsif ($self->{nc} == 0x0023) { # #
4342            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE;
4343            !!!next-input-character;
4344            redo A;
4345          } elsif ($self->{nc} == 0x0022) { # "
4346            $self->{ca}->{value} = '';
4347            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4348            !!!next-input-character;
4349            redo A;
4350          } elsif ($self->{nc} == 0x0027) { # '
4351            $self->{ca}->{value} = '';
4352            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4353            !!!next-input-character;
4354            redo A;
4355          } elsif ($self->{nc} == 0x003E) { # >
4356            !!!parse-error (type => 'no attr default'); ## TODO: type
4357            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4358            !!!next-input-character;
4359            !!!emit ($self->{ct}); # ATTLIST
4360            redo A;
4361          } elsif ($self->{nc} == -1) {
4362            !!!parse-error (type => 'unclosed md'); ## TODO: type
4363            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4364            !!!next-input-character;
4365            !!!emit ($self->{ct});
4366            redo A;
4367          } else {
4368            !!!parse-error (type => 'unquoted attr value'); ## TODO: type
4369            $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4370            ## Reconsume.
4371            redo A;
4372          }
4373        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_BEFORE_STATE) {
4374          if ($is_space->{$self->{nc}}) {
4375            ## XML5: No parse error.
4376            !!!parse-error (type => 'no default type'); ## TODO: type
4377            $self->{state} = BOGUS_MD_STATE;
4378            ## Reconsume.
4379            redo A;
4380          } elsif ($self->{nc} == 0x0022) { # "
4381            ## XML5: Same as "anything else".
4382            $self->{ca}->{value} = '';
4383            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4384            !!!next-input-character;
4385            redo A;
4386          } elsif ($self->{nc} == 0x0027) { # '
4387            ## XML5: Same as "anything else".
4388            $self->{ca}->{value} = '';
4389            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4390            !!!next-input-character;
4391            redo A;
4392          } elsif ($self->{nc} == 0x003E) { # >
4393            ## XML5: Same as "anything else".
4394            !!!parse-error (type => 'no attr default'); ## TODO: type
4395            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4396            !!!next-input-character;
4397            !!!emit ($self->{ct}); # ATTLIST
4398            redo A;
4399          } elsif ($self->{nc} == -1) {
4400            ## XML5: No parse error.
4401            !!!parse-error (type => 'unclosed md'); ## TODO: type
4402            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4403            !!!next-input-character;
4404            !!!emit ($self->{ct});
4405            redo A;
4406          } else {
4407            $self->{ca}->{default} = chr $self->{nc};
4408            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE;
4409            !!!next-input-character;
4410            redo A;
4411          }
4412        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_STATE) {
4413          if ($is_space->{$self->{nc}}) {
4414            $self->{state} = DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE;
4415            !!!next-input-character;
4416            redo A;
4417          } elsif ($self->{nc} == 0x0022) { # "
4418            ## XML5: Same as "anything else".
4419            !!!parse-error (type => 'no space before default value'); ## TODO: type
4420            $self->{ca}->{value} = '';
4421            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4422            !!!next-input-character;
4423            redo A;
4424          } elsif ($self->{nc} == 0x0027) { # '
4425            ## XML5: Same as "anything else".
4426            !!!parse-error (type => 'no space before default value'); ## TODO: type
4427            $self->{ca}->{value} = '';
4428            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4429            !!!next-input-character;
4430            redo A;
4431          } elsif ($self->{nc} == 0x003E) { # >
4432            ## XML5: Same as "anything else".
4433            push @{$self->{ct}->{attrdefs}}, $self->{ca};
4434            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4435            !!!next-input-character;
4436            !!!emit ($self->{ct}); # ATTLIST
4437            redo A;
4438          } elsif ($self->{nc} == -1) {
4439            ## XML5: No parse error.
4440            !!!parse-error (type => 'unclosed md'); ## TODO: type
4441            push @{$self->{ct}->{attrdefs}}, $self->{ca};
4442            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4443            !!!next-input-character;
4444            !!!emit ($self->{ct});
4445            redo A;
4446          } else {
4447            $self->{ca}->{default} .= chr $self->{nc};
4448            ## Stay in the state.
4449            !!!next-input-character;
4450            redo A;
4451          }
4452        } elsif ($self->{state} == DOCTYPE_ATTLIST_ATTRIBUTE_DECLARATION_AFTER_STATE) {
4453          if ($is_space->{$self->{nc}}) {
4454            ## Stay in the state.
4455            !!!next-input-character;
4456            redo A;
4457          } elsif ($self->{nc} == 0x0022) { # "
4458            $self->{ca}->{value} = '';
4459            $self->{state} = ATTRIBUTE_VALUE_DOUBLE_QUOTED_STATE;
4460            !!!next-input-character;
4461            redo A;
4462          } elsif ($self->{nc} == 0x0027) { # '
4463            $self->{ca}->{value} = '';
4464            $self->{state} = ATTRIBUTE_VALUE_SINGLE_QUOTED_STATE;
4465            !!!next-input-character;
4466            redo A;
4467          } elsif ($self->{nc} == 0x003E) { # >
4468            push @{$self->{ct}->{attrdefs}}, $self->{ca};
4469            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4470            !!!next-input-character;
4471            !!!emit ($self->{ct}); # ATTLIST
4472            redo A;
4473          } elsif ($self->{nc} == -1) {
4474            ## XML5: No parse error.
4475            !!!parse-error (type => 'unclosed md'); ## TODO: type
4476            push @{$self->{ct}->{attrdefs}}, $self->{ca};
4477            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE; ## XML5: "Data state".
4478            !!!next-input-character;
4479            !!!emit ($self->{ct});
4480            redo A;
4481          } else {
4482            ## XML5: Not defined yet.
4483            if ($self->{ca}->{default} eq 'FIXED') {
4484              $self->{state} = ATTRIBUTE_VALUE_UNQUOTED_STATE;
4485            } else {
4486              push @{$self->{ct}->{attrdefs}}, $self->{ca};
4487              $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4488            }
4489            ## Reconsume.
4490            redo A;
4491          }
4492        } elsif ($self->{state} == AFTER_ATTLIST_ATTR_VALUE_QUOTED_STATE) {
4493          if ($is_space->{$self->{nc}} or
4494              $self->{nc} == -1 or
4495              $self->{nc} == 0x003E) { # >
4496            $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4497            ## Reconsume.
4498            redo A;
4499          } else {
4500            !!!parse-error (type => 'no space before attr name'); ## TODO: type
4501            $self->{state} = DOCTYPE_ATTLIST_NAME_AFTER_STATE;
4502            ## Reconsume.
4503            redo A;
4504          }
4505    
4506        } elsif ($self->{state} == BOGUS_MD_STATE) {
4507          if ($self->{nc} == 0x003E) { # >
4508            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4509            !!!next-input-character;
4510            !!!emit ($self->{ct}); # ATTLIST/ENTITY/NOTATION
4511            redo A;
4512          } elsif ($self->{nc} == -1) {
4513            $self->{state} = DOCTYPE_INTERNAL_SUBSET_STATE;
4514            ## Reconsume.
4515            !!!emit ($self->{ct}); # ATTLIST/ENTITY/NOTATION
4516            redo A;
4517          } else {
4518            ## Stay in the state.
4519          !!!next-input-character;          !!!next-input-character;
4520          redo A;          redo A;
4521        }        }
           
4522      } else {      } else {
4523        die "$0: $self->{state}: Unknown state";        die "$0: $self->{state}: Unknown state";
4524      }      }
# Line 3259  sub _get_next_token ($) { Line 4529  sub _get_next_token ($) {
4529    
4530  1;  1;
4531  ## $Date$  ## $Date$
4532                                    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.17

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24