Mozilla bug 664104 - Implement new ruby model in parser. r=wchen
authorYuki Sekiguchi <Yuki.Sekiguchi@access-company.com>
Fri, 20 Jun 2014 16:57:39 -0700
changeset 779 28a5898b09ba45d48805f4b0f94e6d46da1bd3a6
parent 778 3344e4f41d7ec245e41c69de8262576c0b51cecb
child 780 f3e3440d025429cfbe2b9a0994738926558890e7
push id116
push userwchen@mozilla.com
push dateSat, 21 Jun 2014 00:13:19 +0000
reviewerswchen
bugs664104
Mozilla bug 664104 - Implement new ruby model in parser. r=wchen
src/nu/validator/htmlparser/impl/ElementName.java
src/nu/validator/htmlparser/impl/TreeBuilder.java
--- a/src/nu/validator/htmlparser/impl/ElementName.java
+++ b/src/nu/validator/htmlparser/impl/ElementName.java
@@ -351,18 +351,20 @@ public final class ElementName
 //            case TreeBuilder.DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
 //                return "DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU";
 //            case TreeBuilder.FIELDSET:
 //                return "FIELDSET";
 //            case TreeBuilder.ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SECTION_OR_SUMMARY:
 //                return "ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SECTION_OR_SUMMARY";
 //            case TreeBuilder.RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR:
 //                return "RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR";
-//            case TreeBuilder.RT_OR_RP:
-//                return "RT_OR_RP";
+//            case TreeBuilder.RB_OR_RP_OR_RTC:
+//                return "RB_OR_RP_OR_RTC";
+//            case TreeBuilder.RT:
+//                return "RT";
 //            case TreeBuilder.PARAM_OR_SOURCE_OR_TRACK:
 //                return "PARAM_OR_SOURCE_OR_TRACK";
 //            case TreeBuilder.MGLYPH_OR_MALIGNMARK:
 //                return "MGLYPH_OR_MALIGNMARK";
 //            case TreeBuilder.MI_MO_MN_MS_MTEXT:
 //                return "MI_MO_MN_MS_MTEXT";
 //            case TreeBuilder.ANNOTATION_XML:
 //                return "ANNOTATION_XML";
@@ -440,18 +442,19 @@ public final class ElementName
     public static final ElementName LT = new ElementName("lt", "lt", TreeBuilder.OTHER);
     public static final ElementName MI = new ElementName("mi", "mi", TreeBuilder.MI_MO_MN_MS_MTEXT | SCOPING_AS_MATHML);
     public static final ElementName MN = new ElementName("mn", "mn", TreeBuilder.MI_MO_MN_MS_MTEXT | SCOPING_AS_MATHML);
     public static final ElementName MO = new ElementName("mo", "mo", TreeBuilder.MI_MO_MN_MS_MTEXT | SCOPING_AS_MATHML);
     public static final ElementName MS = new ElementName("ms", "ms", TreeBuilder.MI_MO_MN_MS_MTEXT | SCOPING_AS_MATHML);
     public static final ElementName OL = new ElementName("ol", "ol", TreeBuilder.UL_OR_OL_OR_DL | SPECIAL);
     public static final ElementName OR = new ElementName("or", "or", TreeBuilder.OTHER);
     public static final ElementName PI = new ElementName("pi", "pi", TreeBuilder.OTHER);
-    public static final ElementName RP = new ElementName("rp", "rp", TreeBuilder.RT_OR_RP | OPTIONAL_END_TAG);
-    public static final ElementName RT = new ElementName("rt", "rt", TreeBuilder.RT_OR_RP | OPTIONAL_END_TAG);
+    public static final ElementName RB = new ElementName("rb", "rb", TreeBuilder.RB_OR_RP_OR_RTC | OPTIONAL_END_TAG);
+    public static final ElementName RP = new ElementName("rp", "rp", TreeBuilder.RB_OR_RP_OR_RTC | OPTIONAL_END_TAG);
+    public static final ElementName RT = new ElementName("rt", "rt", TreeBuilder.RT | OPTIONAL_END_TAG);
     public static final ElementName TD = new ElementName("td", "td", TreeBuilder.TD_OR_TH | SPECIAL | SCOPING | OPTIONAL_END_TAG);
     public static final ElementName TH = new ElementName("th", "th", TreeBuilder.TD_OR_TH | SPECIAL | SCOPING | OPTIONAL_END_TAG);
     public static final ElementName TR = new ElementName("tr", "tr", TreeBuilder.TR | SPECIAL | FOSTER_PARENTING | OPTIONAL_END_TAG);
     public static final ElementName TT = new ElementName("tt", "tt", TreeBuilder.B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U);
     public static final ElementName UL = new ElementName("ul", "ul", TreeBuilder.UL_OR_OL_OR_DL | SPECIAL);
     public static final ElementName AND = new ElementName("and", "and", TreeBuilder.OTHER);
     public static final ElementName ARG = new ElementName("arg", "arg", TreeBuilder.OTHER);
     public static final ElementName ABS = new ElementName("abs", "abs", TreeBuilder.OTHER);
@@ -479,16 +482,17 @@ public final class ElementName
     public static final ElementName MIN = new ElementName("min", "min", TreeBuilder.OTHER);
     public static final ElementName MAP = new ElementName("map", "map", TreeBuilder.OTHER);
     public static final ElementName MTR = new ElementName("mtr", "mtr", TreeBuilder.OTHER);
     public static final ElementName MAX = new ElementName("max", "max", TreeBuilder.OTHER);
     public static final ElementName NEQ = new ElementName("neq", "neq", TreeBuilder.OTHER);
     public static final ElementName NOT = new ElementName("not", "not", TreeBuilder.OTHER);
     public static final ElementName NAV = new ElementName("nav", "nav", TreeBuilder.ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SECTION_OR_SUMMARY | SPECIAL);
     public static final ElementName PRE = new ElementName("pre", "pre", TreeBuilder.PRE_OR_LISTING | SPECIAL);
+    public static final ElementName RTC = new ElementName("rtc", "rtc", TreeBuilder.RB_OR_RP_OR_RTC | OPTIONAL_END_TAG);
     public static final ElementName REM = new ElementName("rem", "rem", TreeBuilder.OTHER);
     public static final ElementName SUB = new ElementName("sub", "sub", TreeBuilder.RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR);
     public static final ElementName SEC = new ElementName("sec", "sec", TreeBuilder.OTHER);
     public static final ElementName SVG = new ElementName("svg", "svg", TreeBuilder.SVG);
     public static final ElementName SUM = new ElementName("sum", "sum", TreeBuilder.OTHER);
     public static final ElementName SIN = new ElementName("sin", "sin", TreeBuilder.OTHER);
     public static final ElementName SEP = new ElementName("sep", "sep", TreeBuilder.OTHER);
     public static final ElementName SUP = new ElementName("sup", "sup", TreeBuilder.RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR);
@@ -835,16 +839,17 @@ public final class ElementName
     LT,
     MI,
     MN,
     MO,
     MS,
     OL,
     OR,
     PI,
+    RB,
     RP,
     RT,
     TD,
     TH,
     TR,
     TT,
     UL,
     AND,
@@ -874,16 +879,17 @@ public final class ElementName
     MIN,
     MAP,
     MTR,
     MAX,
     NEQ,
     NOT,
     NAV,
     PRE,
+    RTC,
     REM,
     SUB,
     SEC,
     SVG,
     SUM,
     SIN,
     SEP,
     SUP,
@@ -1231,16 +1237,17 @@ public final class ElementName
     78476,
     79149,
     79309,
     79341,
     79469,
     81295,
     81487,
     82224,
+    84050,
     84498,
     84626,
     86164,
     86292,
     86612,
     86676,
     87445,
     3183041,
@@ -1270,16 +1277,17 @@ public final class ElementName
     3586349,
     3588141,
     3590797,
     3596333,
     3622062,
     3625454,
     3627054,
     3675728,
+    3739282,
     3749042,
     3771059,
     3771571,
     3776211,
     3782323,
     3782963,
     3784883,
     3785395,
--- a/src/nu/validator/htmlparser/impl/TreeBuilder.java
+++ b/src/nu/validator/htmlparser/impl/TreeBuilder.java
@@ -168,17 +168,17 @@ public abstract class TreeBuilder<T> imp
     final static int AREA_OR_WBR = 49;
 
     final static int DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU = 50;
 
     final static int ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SECTION_OR_SUMMARY = 51;
 
     final static int RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR = 52;
 
-    final static int RT_OR_RP = 53;
+    final static int RB_OR_RP_OR_RTC = 53;
 
     final static int PARAM_OR_SOURCE_OR_TRACK = 55;
 
     final static int MGLYPH_OR_MALIGNMARK = 56;
 
     final static int MI_MO_MN_MS_MTEXT = 57;
 
     final static int ANNOTATION_XML = 58;
@@ -198,16 +198,18 @@ public abstract class TreeBuilder<T> imp
     final static int KEYGEN = 65;
 
     final static int MENUITEM = 66;
 
     final static int TEMPLATE = 67;
 
     final static int IMG = 68;
 
+    final static int RT = 69;
+
     // start insertion modes
 
     private static final int IN_ROW = 0;
 
     private static final int IN_TABLE_BODY = 1;
 
     private static final int IN_TABLE = 2;
 
@@ -2403,33 +2405,52 @@ public abstract class TreeBuilder<T> imp
                                     pop();
                                 }
                                 reconstructTheActiveFormattingElements();
                                 appendToCurrentNodeAndPushElementMayFoster(
                                         elementName,
                                         attributes);
                                 attributes = null; // CPP
                                 break starttagloop;
-                            case RT_OR_RP:
+                            case RB_OR_RP_OR_RTC:
                                 eltPos = findLastInScope("ruby");
                                 if (eltPos != NOT_FOUND_ON_STACK) {
                                     generateImpliedEndTags();
                                 }
                                 if (eltPos != currentPtr) {
                                     if (eltPos != NOT_FOUND_ON_STACK) {
                                         errStartTagSeenWithoutRuby(name);
                                     } else {
                                         errUnclosedChildrenInRuby();
                                     }
                                 }
                                 appendToCurrentNodeAndPushElementMayFoster(
                                         elementName,
                                         attributes);
                                 attributes = null; // CPP
                                 break starttagloop;
+                            case RT:
+                                eltPos = findLastInScope("ruby");
+                                if (eltPos != NOT_FOUND_ON_STACK) {
+                                    generateImpliedEndTagsExceptFor("rtc");
+                                }
+                                if (eltPos != currentPtr) {
+                                    if (!isCurrent("rtc")) {
+                                        if (eltPos != NOT_FOUND_ON_STACK) {
+                                            errStartTagSeenWithoutRuby(name);
+                                        } else {
+                                            errUnclosedChildrenInRuby();
+                                        }
+                                    }
+                                }
+                                appendToCurrentNodeAndPushElementMayFoster(
+                                        elementName,
+                                        attributes);
+                                attributes = null; // CPP
+                                break starttagloop;
                             case MATH:
                                 reconstructTheActiveFormattingElements();
                                 attributes.adjustForMath();
                                 if (selfClosing) {
                                     appendVoidElementToCurrentMayFosterMathML(
                                             elementName, attributes);
                                     selfClosing = false;
                                 } else {
@@ -3524,17 +3545,18 @@ public abstract class TreeBuilder<T> imp
                             if (errorHandler != null) {
                                 uncloseloop1: for (int i = 2; i <= currentPtr; i++) {
                                     switch (stack[i].getGroup()) {
                                         case DD_OR_DT:
                                         case LI:
                                         case OPTGROUP:
                                         case OPTION: // is this possible?
                                         case P:
-                                        case RT_OR_RP:
+                                        case RB_OR_RP_OR_RTC:
+                                        case RT:
                                         case TD_OR_TH:
                                         case TBODY_OR_THEAD_OR_TFOOT:
                                             break;
                                         default:
                                             errEndWithUnclosedElements(name);
                                             break uncloseloop1;
                                     }
                                 }
@@ -3548,16 +3570,18 @@ public abstract class TreeBuilder<T> imp
                                 break endtagloop;
                             }
                             if (errorHandler != null) {
                                 uncloseloop2: for (int i = 0; i <= currentPtr; i++) {
                                     switch (stack[i].getGroup()) {
                                         case DD_OR_DT:
                                         case LI:
                                         case P:
+                                        case RB_OR_RP_OR_RTC:
+                                        case RT:
                                         case TBODY_OR_THEAD_OR_TFOOT:
                                         case TD_OR_TH:
                                         case BODY:
                                         case HTML:
                                             break;
                                         default:
                                             errEndWithUnclosedElements(name);
                                             break uncloseloop2;
@@ -4165,17 +4189,18 @@ public abstract class TreeBuilder<T> imp
         for (;;) {
             StackNode<T> node = stack[currentPtr];
             switch (node.getGroup()) {
                 case P:
                 case LI:
                 case DD_OR_DT:
                 case OPTION:
                 case OPTGROUP:
-                case RT_OR_RP:
+                case RB_OR_RP_OR_RTC:
+                case RT:
                     if (node.ns == "http://www.w3.org/1999/xhtml" && node.name == name) {
                         return;
                     }
                     pop();
                     continue;
                 default:
                     return;
             }
@@ -4185,17 +4210,18 @@ public abstract class TreeBuilder<T> imp
     private void generateImpliedEndTags() throws SAXException {
         for (;;) {
             switch (stack[currentPtr].getGroup()) {
                 case P:
                 case LI:
                 case DD_OR_DT:
                 case OPTION:
                 case OPTGROUP:
-                case RT_OR_RP:
+                case RB_OR_RP_OR_RTC:
+                case RT:
                     pop();
                     continue;
                 default:
                     return;
             }
         }
     }