var insertionMode_InitialPhase = 0;
var insertionMode_RootElementPhase = 1;
var insertionMode_MainPhase_BeforeHead = 2;
var insertionMode_MainPhase_InHead = 3;
var insertionMode_MainPhase_InHeadNoscript = 4;
var insertionMode_MainPhase_AfterHead = 5;
var insertionMode_MainPhase_InBody = 6;
var insertionMode_MainPhase_InTable = 7;
var insertionMode_MainPhase_InCaption = 8;
var insertionMode_MainPhase_InColumnGroup = 9;
var insertionMode_MainPhase_InTableBody = 10;
var insertionMode_MainPhase_InRow = 11;
var insertionMode_MainPhase_InCell = 12;
var insertionMode_MainPhase_InSelect = 13;
var insertionMode_MainPhase_AfterBody = 14;
var insertionMode_MainPhase_InFrameset = 15;
var insertionMode_MainPhase_AfterFrameset = 16;
var insertionMode_TrailingEndPhase = 17;

TreeConstructor.prototype.IsSpecial = { "address": true, "area": true, "base": true, "basefont": true, "bgsound": true, "blockquote": true, "body": true, "br": true, "center": true, "col": true, "colgroup": true, "dd": true, "dir": true, "div": true, "dl": true, "dt": true, "embed": true, "fieldset": true, "form": true, "frame": true, "frameset": true, "h1": true, "h2": true, "h3": true, "h4": true, "h5": true, "h6": true, "head": true, "hr": true, "iframe": true, "image": true, "img": true, "input": true, "isindex": true, "li": true, "link": true, "listing": true, "menu": true, "meta": true, "noembed": true, "noframes": true, "noscript": true, "ol": true, "optgroup": true, "option": true, "p": true, "param": true, "plaintext": true, "pre": true, "script": true, "select": true, "spacer": true, "style": true, "tbody": true, "textarea": true, "tfoot": true, "thead": true, "title": true, "tr": true, "ul": true, "wbr": true };
TreeConstructor.prototype.IsScoping = { "button": true, "caption": true, "html": true, "marquee": true, "object": true, "table": true, "td": true, "th": true };
TreeConstructor.prototype.IsFormatting = { "a": true, "b": true, "big": true, "em": true, "font": true, "i": true, "nobr": true, "s": true, "small": true, "strike": true, "strong": true, "tt": true, "u": true };

TreeConstructor.prototype.processToken = function (token, mode)
{
    switch (mode)
    {
    case insertionMode_InitialPhase:
    {
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# InitialPhase Character [9, 10, 11, 12, 32]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "Comment")
        {
            debug("# InitialPhase Comment");
            debug("# - AppendCommentTokenToDocument");
            this.appendCommentToDocument(token);
        }
        else
        if (token[0] == "DOCTYPE")
        {
            debug("# InitialPhase Doctype");
            debug("# - DoDoctypeStuff");
            this.doDoctypeStuff(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_RootElementPhase);
        }
        else
        if (token[0] == "StartTag")
        {
            debug("# InitialPhase Start tag");
            debug("# - ParseError");
            this.parseError("InitialPhase - Start tag");
            debug("# - SetCompatMode");
            debug("TODO: SetCompatMode");
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_RootElementPhase);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "EndTag")
        {
            debug("# InitialPhase End tag");
            debug("# - ParseError");
            this.parseError("InitialPhase - End tag");
            debug("# - SetCompatMode");
            debug("TODO: SetCompatMode");
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_RootElementPhase);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "Character" && !(token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# InitialPhase Character not [9, 10, 11, 12, 32]");
            debug("# - ParseError");
            this.parseError("InitialPhase - Character not [9, 10, 11, 12, 32]");
            debug("# - SetCompatMode");
            debug("TODO: SetCompatMode");
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_RootElementPhase);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token == "EndOfFile")
        {
            debug("# InitialPhase EOF");
            debug("# - ParseError");
            this.parseError("InitialPhase - EOF");
            debug("# - SetCompatMode");
            debug("TODO: SetCompatMode");
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_RootElementPhase);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        break;
    }
    
    case insertionMode_RootElementPhase:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# RootElementPhase Doctype");
            debug("# - ParseError");
            this.parseError("RootElementPhase - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "Comment")
        {
            debug("# RootElementPhase Comment");
            debug("# - AppendCommentTokenToDocument");
            this.appendCommentToDocument(token);
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# RootElementPhase Character [9, 10, 11, 12, 32]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "Character" && !(token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# RootElementPhase Character not [9, 10, 11, 12, 32]");
            debug("# - InsertHTMLElement");
            this.insertHTMLElement();
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_BeforeHead);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "StartTag")
        {
            debug("# RootElementPhase Start tag");
            debug("# - InsertHTMLElement");
            this.insertHTMLElement();
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_BeforeHead);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "EndTag")
        {
            debug("# RootElementPhase End tag");
            debug("# - InsertHTMLElement");
            this.insertHTMLElement();
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_BeforeHead);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token == "EndOfFile")
        {
            debug("# RootElementPhase EOF");
            debug("# - InsertHTMLElement");
            this.insertHTMLElement();
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_BeforeHead);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        break;
    }
    
    case insertionMode_MainPhase_BeforeHead:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_BeforeHead Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_BeforeHead - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_BeforeHead Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_BeforeHead EOF");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'head', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_BeforeHead Character [9, 10, 11, 12, 32]");
            debug("# - AppendCharacterTokensToCurrentNode");
            this.appendCharacterToCurrentNode(token);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_BeforeHead Comment");
            debug("# - AppendCommentTokenToCurrentNode");
            this.appendCommentToCurrentNode(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "head"))
        {
            debug("# MainPhase_BeforeHead Start tag [head]");
            debug("# - InsertElementAndSetHeadElementPointer");
            this.headElement = this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InHead);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "base" || token[1] == "link" || token[1] == "meta" || token[1] == "script" || token[1] == "style" || token[1] == "title"))
        {
            debug("# MainPhase_BeforeHead Start tag [base, link, meta, script, style, title]");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'head', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "head" || token[1] == "body" || token[1] == "html" || token[1] == "p" || token[1] == "br"))
        {
            debug("# MainPhase_BeforeHead End tag [head, body, html, p, br]");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'head', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "EndTag")
        {
            debug("# MainPhase_BeforeHead End tag");
            debug("# - ParseError");
            this.parseError("MainPhase_BeforeHead - End tag");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "Character" && !(token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_BeforeHead Character not [9, 10, 11, 12, 32]");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'head', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "StartTag")
        {
            debug("# MainPhase_BeforeHead Start tag");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'head', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        break;
    }
    
    case insertionMode_MainPhase_InHead:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InHead Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InHead - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InHead Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InHead EOF");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'head'], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_InHead Character [9, 10, 11, 12, 32]");
            debug("# - AppendCharacterTokensToCurrentNode");
            this.appendCharacterToCurrentNode(token);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_InHead Comment");
            debug("# - AppendCommentTokenToCurrentNode");
            this.appendCommentToCurrentNode(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "base" || token[1] == "link"))
        {
            debug("# MainPhase_InHead Start tag [base, link]");
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
        }
        else
        if (token[0] == "StartTag" && (token[1] == "meta"))
        {
            debug("# MainPhase_InHead Start tag [meta]");
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
            debug("# - CharsetEncodingStuff");
            debug("TODO: CharsetEncodingStuff");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "title"))
        {
            debug("# MainPhase_InHead Start tag [title]");
            debug("# - GenericRCDATAWithHeadOrCurrent");
            debug("TODO: GenericRCDATAWithHeadOrCurrent");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "style"))
        {
            debug("# MainPhase_InHead Start tag [style]");
            debug("# - GenericCDATAWithCurrent");
            debug("TODO: GenericCDATAWithCurrent");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "script"))
        {
            debug("# MainPhase_InHead Start tag [script]");
            debug("# - GenericCDATAWithCurrent");
            debug("TODO: GenericCDATAWithCurrent");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "head"))
        {
            debug("# MainPhase_InHead End tag [head]");
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_AfterHead);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "body" || token[1] == "html" || token[1] == "p" || token[1] == "br"))
        {
            debug("# MainPhase_InHead End tag [body, html, p, br]");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'head'], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "head"))
        {
            debug("# MainPhase_InHead Start tag [head]");
            debug("# - ParseError");
            this.parseError("MainPhase_InHead - Start tag [head]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "EndTag")
        {
            debug("# MainPhase_InHead End tag");
            debug("# - ParseError");
            this.parseError("MainPhase_InHead - End tag");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (true)
        {
            debug("# MainPhase_InHead Anything else");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'head'], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        break;
    }
    
    case insertionMode_MainPhase_InHeadNoscript:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InHeadNoscript Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InHeadNoscript - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InHeadNoscript Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InHeadNoscript EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InHeadNoscript - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InHeadNoscript - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "noscript"))
        {
            debug("# MainPhase_InHeadNoscript End tag [noscript]");
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InHead);
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_InHeadNoscript Character [9, 10, 11, 12, 32]");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InHead);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_InHeadNoscript Comment");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InHead);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "link" || token[1] == "meta" || token[1] == "style"))
        {
            debug("# MainPhase_InHeadNoscript Start tag [link, meta, style]");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InHead);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "p" || token[1] == "br"))
        {
            debug("# MainPhase_InHeadNoscript End tag [p, br]");
            debug("# - ParseError");
            this.parseError("?");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'noscript'], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "head" || token[1] == "noscript"))
        {
            debug("# MainPhase_InHeadNoscript Start tag [head, noscript]");
            debug("# - ParseError");
            this.parseError("MainPhase_InHeadNoscript - Start tag [head, noscript]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "EndTag")
        {
            debug("# MainPhase_InHeadNoscript End tag");
            debug("# - ParseError");
            this.parseError("MainPhase_InHeadNoscript - End tag");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (true)
        {
            debug("# MainPhase_InHeadNoscript Anything else");
            debug("# - ParseError");
            this.parseError("MainPhase_InHeadNoscript - Anything else");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'noscript'], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        break;
    }
    
    case insertionMode_MainPhase_AfterHead:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_AfterHead Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_AfterHead - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_AfterHead Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_AfterHead EOF");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'body', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_AfterHead Character [9, 10, 11, 12, 32]");
            debug("# - AppendCharacterTokensToCurrentNode");
            this.appendCharacterToCurrentNode(token);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_AfterHead Comment");
            debug("# - AppendCommentTokenToCurrentNode");
            this.appendCommentToCurrentNode(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "body"))
        {
            debug("# MainPhase_AfterHead Start tag [body]");
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InBody);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "frameset"))
        {
            debug("# MainPhase_AfterHead Start tag [frameset]");
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InFrameset);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "base" || token[1] == "link" || token[1] == "meta" || token[1] == "script" || token[1] == "style" || token[1] == "title"))
        {
            debug("# MainPhase_AfterHead Start tag [base, link, meta, script, style, title]");
            debug("# - ParseError");
            this.parseError("MainPhase_AfterHead - Start tag [base, link, meta, script, style, title]");
            debug("# - PushHeadElementPointerOntoStack");
            debug("TODO: PushHeadElementPointerOntoStack");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InHead);
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
        }
        else
        if (true)
        {
            debug("# MainPhase_AfterHead Anything else");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'body', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        break;
    }
    
    case insertionMode_MainPhase_InBody:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InBody Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InBody - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InBody Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InBody EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InBody - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InBody - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "Character")
        {
            debug("# MainPhase_InBody Character");
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - AppendCharacterTokensToCurrentNode");
            this.appendCharacterToCurrentNode(token);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_InBody Comment");
            debug("# - AppendCommentTokenToCurrentNode");
            this.appendCommentToCurrentNode(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "base" || token[1] == "link" || token[1] == "meta" || token[1] == "script" || token[1] == "style"))
        {
            debug("# MainPhase_InBody Start tag [base, link, meta, script, style]");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InHead);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "title"))
        {
            debug("# MainPhase_InBody Start tag [title]");
            debug("# - ParseError");
            this.parseError("MainPhase_InBody - Start tag [title]");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InHead);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "body"))
        {
            debug("# MainPhase_InBody Start tag [body]");
            debug("# - ParseError");
            this.parseError("MainPhase_InBody - Start tag [body]");
            debug("# - If");
            if (false)
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - MergeAttributesIntoBodyElement");
                debug("TODO: MergeAttributesIntoBodyElement");
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "body"))
        {
            debug("# MainPhase_InBody End tag [body]");
            debug("# - If");
            if (false)
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InBody - End tag [body]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - ParseError");
                    this.parseError("stack contains a bad node");
                }
            }
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_AfterBody);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InBody End tag [html]");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'body'], this.insertionMode);
            debug("# - If");
            if (true)
            {
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "address" || token[1] == "blockquote" || token[1] == "center" || token[1] == "dir" || token[1] == "div" || token[1] == "dl" || token[1] == "fieldset" || token[1] == "listing" || token[1] == "menu" || token[1] == "ol" || token[1] == "p" || token[1] == "ul"))
        {
            debug("# MainPhase_InBody Start tag [address, blockquote, center, dir, div, dl, fieldset, listing, menu, ol, p, ul]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'p'], this.insertionMode);
            }
            debug("# - InsertElement");
            this.insertElement(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "pre"))
        {
            debug("# MainPhase_InBody Start tag [pre]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'p'], this.insertionMode);
            }
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - IgnoreNextTokenIfLinefeed");
            debug("TODO: IgnoreNextTokenIfLinefeed");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "form"))
        {
            debug("# MainPhase_InBody Start tag [form]");
            debug("# - If");
            if (this.formElement)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InBody - Start tag [form]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - If");
                if (this.hasElementInScope(false, [ "p" ]))
                {
                    debug("# - ActAsIfEndTag");
                    this.processToken(['EndTag', 'p'], this.insertionMode);
                }
                debug("# - InsertElementAndSetFormElementPointer");
                debug("TODO: InsertElementAndSetFormElementPointer");
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "li"))
        {
            debug("# MainPhase_InBody Start tag [li]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'p'], this.insertionMode);
            }
            debug("# - FixupForListElement");
            debug("TODO: FixupForListElement");
            debug("# - InsertElement");
            this.insertElement(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "dd" || token[1] == "dt"))
        {
            debug("# MainPhase_InBody Start tag [dd, dt]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'p'], this.insertionMode);
            }
            debug("# - FixupForListElement");
            debug("TODO: FixupForListElement");
            debug("# - InsertElement");
            this.insertElement(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "plaintext"))
        {
            debug("# MainPhase_InBody Start tag [plaintext]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'p'], this.insertionMode);
            }
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetContentModelFlag");
            debug("TODO: SetContentModelFlag");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "address" || token[1] == "blockquote" || token[1] == "center" || token[1] == "dir" || token[1] == "div" || token[1] == "dl" || token[1] == "fieldset" || token[1] == "listing" || token[1] == "menu" || token[1] == "ol" || token[1] == "pre" || token[1] == "ul"))
        {
            debug("# MainPhase_InBody End tag [address, blockquote, center, dir, div, dl, fieldset, listing, menu, ol, pre, ul]");
            debug("# - If");
            if (this.hasElementInScope(false, [ token[1] ]))
            {
                debug("# - GenerateImpliedEndTags");
                this.generateImpliedEndTags([  ]);
            }
            debug("# - If");
            if (!(this.currentNodeHasName(token[1])))
            {
                debug("# - ParseError");
                this.parseError("current node has wrong name");
            }
            debug("# - If");
            if (this.hasElementInScope(false, [ token[1] ]))
            {
                debug("# - PopElementsFromStackUntilOneOf");
                this.popUntilOneOf([ token[1] ]);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "form"))
        {
            debug("# MainPhase_InBody End tag [form]");
            debug("# - If");
            if (this.hasElementInScope(false, [ token[1] ]))
            {
                debug("# - GenerateImpliedEndTags");
                this.generateImpliedEndTags([  ]);
            }
            debug("# - If");
            if (!(this.currentNodeHasName(token[1])))
            {
                debug("# - ParseError");
                this.parseError("current node has wrong name");
            }
            else
            {
                debug("# - PopCurrentNodeFromStack");
                this.popCurrentNode();
            }
            debug("# - SetFormElementPointerToNull");
            debug("TODO: SetFormElementPointerToNull");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "p"))
        {
            debug("# MainPhase_InBody End tag [p]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - GenerateImpliedEndTags");
                this.generateImpliedEndTags([ "p" ]);
            }
            debug("# - If");
            if (!(this.currentNodeHasName("p")))
            {
                debug("# - ParseError");
                this.parseError("current node is not p");
            }
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - PopElementsFromStackUntilNo");
                while (this.hasElementInScope(false, [ "p" ]))
                {
                    this.popCurrentNode();
                }
            }
            else
            {
                debug("# - ActAsIfStartTag");
                this.processToken(['StartTag', 'p', []], this.insertionMode);
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "dd" || token[1] == "dt" || token[1] == "li"))
        {
            debug("# MainPhase_InBody End tag [dd, dt, li]");
            debug("# - If");
            if (this.hasElementInScope(false, [ token[1] ]))
            {
                debug("# - GenerateImpliedEndTags");
                this.generateImpliedEndTags([ token[1] ]);
            }
            debug("# - If");
            if (!(this.currentNodeHasName(token[1])))
            {
                debug("# - ParseError");
                this.parseError("current node has wrong name");
            }
            debug("# - If");
            if (this.hasElementInScope(false, [ token[1] ]))
            {
                debug("# - PopElementsFromStackUntilOneOf");
                this.popUntilOneOf([ token[1] ]);
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "h1" || token[1] == "h2" || token[1] == "h3" || token[1] == "h4" || token[1] == "h5" || token[1] == "h6"))
        {
            debug("# MainPhase_InBody Start tag [h1, h2, h3, h4, h5, h6]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'p'], this.insertionMode);
            }
            debug("# - InsertElement");
            this.insertElement(token);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "h1" || token[1] == "h2" || token[1] == "h3" || token[1] == "h4" || token[1] == "h5" || token[1] == "h6"))
        {
            debug("# MainPhase_InBody End tag [h1, h2, h3, h4, h5, h6]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "h1", "h2", "h3", "h4", "h5", "h6" ]))
            {
                debug("# - GenerateImpliedEndTags");
                this.generateImpliedEndTags([  ]);
            }
            debug("# - If");
            if (!(this.currentNodeHasName(token[1])))
            {
                debug("# - ParseError");
                this.parseError("current node has wrong name");
            }
            debug("# - If");
            if (this.hasElementInScope(false, [ "h1", "h2", "h3", "h4", "h5", "h6" ]))
            {
                debug("# - PopElementsFromStackUntilOneOf");
                this.popUntilOneOf([ "h1", "h2", "h3", "h4", "h5", "h6" ]);
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "a"))
        {
            debug("# MainPhase_InBody Start tag [a]");
            debug("# - If");
            if (this.activeListContainsA())
            {
                debug("# - ParseError");
                this.parseError("list of active formatting elements contains a");
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'a'], this.insertionMode);
                debug("# - RemoveThatAElementIfNecessary");
                this.removeThatAElement();
            }
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - InsertElementAndAddToListOfActive");
            this.addToActiveList(this.insertElement(token));
        }
        else
        if (token[0] == "StartTag" && (token[1] == "b" || token[1] == "big" || token[1] == "em" || token[1] == "font" || token[1] == "i" || token[1] == "s" || token[1] == "small" || token[1] == "strike" || token[1] == "strong" || token[1] == "tt" || token[1] == "u"))
        {
            debug("# MainPhase_InBody Start tag [b, big, em, font, i, s, small, strike, strong, tt, u]");
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - InsertElementAndAddToListOfActive");
            this.addToActiveList(this.insertElement(token));
        }
        else
        if (token[0] == "StartTag" && (token[1] == "nobr"))
        {
            debug("# MainPhase_InBody Start tag [nobr]");
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - If");
            if (this.hasElementInScope(false, [ "nobr" ]))
            {
                debug("# - ParseError");
                this.parseError("stack has nobr in scope");
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'nobr'], this.insertionMode);
                debug("# - ReconstructActiveFormattingElements");
                this.reconstructActiveFormattingElements();
            }
            debug("# - InsertElementAndAddToListOfActive");
            this.addToActiveList(this.insertElement(token));
        }
        else
        if (token[0] == "EndTag" && (token[1] == "a" || token[1] == "b" || token[1] == "big" || token[1] == "em" || token[1] == "font" || token[1] == "i" || token[1] == "nobr" || token[1] == "s" || token[1] == "small" || token[1] == "strike" || token[1] == "strong" || token[1] == "tt" || token[1] == "u"))
        {
            debug("# MainPhase_InBody End tag [a, b, big, em, font, i, nobr, s, small, strike, strong, tt, u]");
            debug("# - AdoptionAgency");
            this.adoptionAgency(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "button"))
        {
            debug("# MainPhase_InBody Start tag [button]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "button" ]))
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InBody - Start tag [button]");
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'button'], this.insertionMode);
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
            else
            {
                debug("# - ReconstructActiveFormattingElements");
                this.reconstructActiveFormattingElements();
                debug("# - InsertElement");
                this.insertElement(token);
                debug("# - AddMarkerToActiveList");
                this.addToActiveList(null);
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "marquee" || token[1] == "object"))
        {
            debug("# MainPhase_InBody Start tag [marquee, object]");
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - AddMarkerToActiveList");
            this.addToActiveList(null);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "button" || token[1] == "marquee" || token[1] == "object"))
        {
            debug("# MainPhase_InBody End tag [button, marquee, object]");
            debug("# - If");
            if (this.hasElementInScope(false, [ token[1] ]))
            {
                debug("# - GenerateImpliedEndTags");
                this.generateImpliedEndTags([  ]);
            }
            debug("# - If");
            if (!(this.currentNodeHasName(token[1])))
            {
                debug("# - ParseError");
                this.parseError("current node has wrong name");
            }
            debug("# - If");
            if (this.hasElementInScope(false, [ token[1] ]))
            {
                debug("# - PopElementsFromStackUntilOneOf");
                this.popUntilOneOf([ token[1] ]);
                debug("# - ClearActiveListUpToMarker");
                this.clearActiveListUpToMarker();
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "xmp"))
        {
            debug("# MainPhase_InBody Start tag [xmp]");
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - GenericCDATAWithCurrent");
            debug("TODO: GenericCDATAWithCurrent");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "table"))
        {
            debug("# MainPhase_InBody Start tag [table]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'p'], this.insertionMode);
            }
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InTable);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "area" || token[1] == "basefont" || token[1] == "bgsound" || token[1] == "br" || token[1] == "embed" || token[1] == "img" || token[1] == "param" || token[1] == "spacer" || token[1] == "wbr"))
        {
            debug("# MainPhase_InBody Start tag [area, basefont, bgsound, br, embed, img, param, spacer, wbr]");
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
        }
        else
        if (token[0] == "StartTag" && (token[1] == "hr"))
        {
            debug("# MainPhase_InBody Start tag [hr]");
            debug("# - If");
            if (this.hasElementInScope(false, [ "p" ]))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'p'], this.insertionMode);
            }
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
        }
        else
        if (token[0] == "StartTag" && (token[1] == "image"))
        {
            debug("# MainPhase_InBody Start tag [image]");
            debug("# - ParseError");
            this.parseError("MainPhase_InBody - Start tag [image]");
            debug("# - ActAsIfStartTagName");
            this.processToken(['StartTag', 'img', token[2]], this.insertionMode);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "input"))
        {
            debug("# MainPhase_InBody Start tag [input]");
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - If");
            if (this.formElement)
            {
                debug("# - AssociateCurrentNodeWithFormElementPointer");
                debug("TODO: AssociateCurrentNodeWithFormElementPointer");
            }
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
        }
        else
        if (token[0] == "StartTag" && (token[1] == "isindex"))
        {
            debug("# MainPhase_InBody Start tag [isindex]");
            debug("# - TODO");
            debug("TODO: TODO");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "textarea"))
        {
            debug("# MainPhase_InBody Start tag [textarea]");
            debug("# - TODO");
            debug("TODO: TODO");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "iframe" || token[1] == "noembed" || token[1] == "noframes"))
        {
            debug("# MainPhase_InBody Start tag [iframe, noembed, noframes]");
            debug("# - GenericCDATAWithCurrent");
            debug("TODO: GenericCDATAWithCurrent");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "select"))
        {
            debug("# MainPhase_InBody Start tag [select]");
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InSelect);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "br"))
        {
            debug("# MainPhase_InBody End tag [br]");
            debug("# - ParseError");
            this.parseError("MainPhase_InBody - End tag [br]");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'br', []], this.insertionMode);
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "frame" || token[1] == "frameset" || token[1] == "head" || token[1] == "option" || token[1] == "optgroup" || token[1] == "tbody" || token[1] == "td" || token[1] == "tfoot" || token[1] == "th" || token[1] == "thead" || token[1] == "tr"))
        {
            debug("# MainPhase_InBody Start tag [caption, col, colgroup, frame, frameset, head, option, optgroup, tbody, td, tfoot, th, thead, tr]");
            debug("# - ParseError");
            this.parseError("MainPhase_InBody - Start tag [caption, col, colgroup, frame, frameset, head, option, optgroup, tbody, td, tfoot, th, thead, tr]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "frame" || token[1] == "frameset" || token[1] == "head" || token[1] == "option" || token[1] == "optgroup" || token[1] == "tbody" || token[1] == "td" || token[1] == "tfoot" || token[1] == "th" || token[1] == "thead" || token[1] == "tr"))
        {
            debug("# MainPhase_InBody End tag [caption, col, colgroup, frame, frameset, head, option, optgroup, tbody, td, tfoot, th, thead, tr]");
            debug("# - ParseError");
            this.parseError("MainPhase_InBody - End tag [caption, col, colgroup, frame, frameset, head, option, optgroup, tbody, td, tfoot, th, thead, tr]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "area" || token[1] == "basefont" || token[1] == "bgsound" || token[1] == "br" || token[1] == "embed" || token[1] == "hr" || token[1] == "iframe" || token[1] == "image" || token[1] == "img" || token[1] == "input" || token[1] == "isindex" || token[1] == "noembed" || token[1] == "noframes" || token[1] == "param" || token[1] == "select" || token[1] == "spacer" || token[1] == "table" || token[1] == "textarea" || token[1] == "wbr"))
        {
            debug("# MainPhase_InBody End tag [area, basefont, bgsound, br, embed, hr, iframe, image, img, input, isindex, noembed, noframes, param, select, spacer, table, textarea, wbr]");
            debug("# - ParseError");
            this.parseError("MainPhase_InBody - End tag [area, basefont, bgsound, br, embed, hr, iframe, image, img, input, isindex, noembed, noframes, param, select, spacer, table, textarea, wbr]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "event-source" || token[1] == "section" || token[1] == "nav" || token[1] == "article" || token[1] == "aside" || token[1] == "header" || token[1] == "footer" || token[1] == "datagrid" || token[1] == "command"))
        {
            debug("# MainPhase_InBody Start tag [event-source, section, nav, article, aside, header, footer, datagrid, command]");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "event-source" || token[1] == "section" || token[1] == "nav" || token[1] == "article" || token[1] == "aside" || token[1] == "header" || token[1] == "footer" || token[1] == "datagrid" || token[1] == "command"))
        {
            debug("# MainPhase_InBody End tag [event-source, section, nav, article, aside, header, footer, datagrid, command]");
        }
        else
        if (token[0] == "StartTag")
        {
            debug("# MainPhase_InBody Start tag");
            debug("# - ReconstructActiveFormattingElements");
            this.reconstructActiveFormattingElements();
            debug("# - InsertElement");
            this.insertElement(token);
        }
        else
        if (token[0] == "EndTag")
        {
            debug("# MainPhase_InBody End tag");
            debug("# - ApplyEndTag");
            this.applyEndTag(token);
        }
        break;
    }
    
    case insertionMode_MainPhase_InTable:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InTable Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InTable - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InTable Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InTable EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InTable - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InTable - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_InTable Character [9, 10, 11, 12, 32]");
            debug("# - AppendCharacterTokensToCurrentNode");
            this.appendCharacterToCurrentNode(token);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_InTable Comment");
            debug("# - AppendCommentTokenToCurrentNode");
            this.appendCommentToCurrentNode(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "caption"))
        {
            debug("# MainPhase_InTable Start tag [caption]");
            debug("# - ClearStackToContext");
            this.clearStackToContext([ "table", "html" ]);
            debug("# - AddMarkerToActiveList");
            this.addToActiveList(null);
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InCaption);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "colgroup"))
        {
            debug("# MainPhase_InTable Start tag [colgroup]");
            debug("# - ClearStackToContext");
            this.clearStackToContext([ "table", "html" ]);
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InColumnGroup);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "col"))
        {
            debug("# MainPhase_InTable Start tag [col]");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'colgroup', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "tbody" || token[1] == "tfoot" || token[1] == "thead"))
        {
            debug("# MainPhase_InTable Start tag [tbody, tfoot, thead]");
            debug("# - ClearStackToContext");
            this.clearStackToContext([ "table", "html" ]);
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InTableBody);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "td" || token[1] == "th" || token[1] == "tr"))
        {
            debug("# MainPhase_InTable Start tag [td, th, tr]");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'tbody', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "table"))
        {
            debug("# MainPhase_InTable Start tag [table]");
            debug("# - ParseError");
            this.parseError("MainPhase_InTable - Start tag [table]");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'table'], this.insertionMode);
            debug("# - If");
            if (true)
            {
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "table"))
        {
            debug("# MainPhase_InTable End tag [table]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ token[1] ])))
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InTable - End tag [table]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - GenerateImpliedEndTags");
                this.generateImpliedEndTags([  ]);
                debug("# - If");
                if (!(this.currentNodeHasName("table")))
                {
                    debug("# - ParseError");
                    this.parseError("current node is not table");
                }
                debug("# - PopElementsFromStackUntilOneOf");
                this.popUntilOneOf([ "table" ]);
                debug("# - ResetInsertionModeAppropriately");
                this.resetInsertionModeAppropriately();
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "body" || token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "html" || token[1] == "tbody" || token[1] == "td" || token[1] == "tfoot" || token[1] == "th" || token[1] == "thead" || token[1] == "tr"))
        {
            debug("# MainPhase_InTable End tag [body, caption, col, colgroup, html, tbody, td, tfoot, th, thead, tr]");
            debug("# - ParseError");
            this.parseError("MainPhase_InTable - End tag [body, caption, col, colgroup, html, tbody, td, tfoot, th, thead, tr]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (true)
        {
            debug("# MainPhase_InTable Anything else");
            debug("# - ParseError");
            this.parseError("MainPhase_InTable - Anything else");
            debug("# - ReprocessWithFosteringAsIf");
            this.reprocessWithFosteringAsIf(token, insertionMode_MainPhase_InBody);
        }
        break;
    }
    
    case insertionMode_MainPhase_InCaption:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InCaption Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InCaption - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InCaption Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InCaption EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InCaption - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InCaption - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "caption"))
        {
            debug("# MainPhase_InCaption End tag [caption]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ token[1] ])))
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InCaption - End tag [caption]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - GenerateImpliedEndTags");
                this.generateImpliedEndTags([  ]);
                debug("# - If");
                if (!(this.currentNodeHasName("caption")))
                {
                    debug("# - ParseError");
                    this.parseError("current node is not caption");
                }
                debug("# - PopElementsFromStackUntilOneOf");
                this.popUntilOneOf([ "caption" ]);
                debug("# - ClearActiveListUpToMarker");
                this.clearActiveListUpToMarker();
                debug("# - SetInsertionMode");
                this.setInsertionMode(insertionMode_MainPhase_InTable);
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "tbody" || token[1] == "td" || token[1] == "tfoot" || token[1] == "th" || token[1] == "thead" || token[1] == "tr"))
        {
            debug("# MainPhase_InCaption Start tag [caption, col, colgroup, tbody, td, tfoot, th, thead, tr]");
            debug("# - ParseError");
            this.parseError("MainPhase_InCaption - Start tag [caption, col, colgroup, tbody, td, tfoot, th, thead, tr]");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'caption'], this.insertionMode);
            debug("# - If");
            if (true)
            {
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "table"))
        {
            debug("# MainPhase_InCaption End tag [table]");
            debug("# - ParseError");
            this.parseError("MainPhase_InCaption - End tag [table]");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'caption'], this.insertionMode);
            debug("# - If");
            if (true)
            {
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "body" || token[1] == "col" || token[1] == "colgroup" || token[1] == "html" || token[1] == "tbody" || token[1] == "td" || token[1] == "tfoot" || token[1] == "th" || token[1] == "thead" || token[1] == "tr"))
        {
            debug("# MainPhase_InCaption End tag [body, col, colgroup, html, tbody, td, tfoot, th, thead, tr]");
            debug("# - ParseError");
            this.parseError("MainPhase_InCaption - End tag [body, col, colgroup, html, tbody, td, tfoot, th, thead, tr]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (true)
        {
            debug("# MainPhase_InCaption Anything else");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InBody);
        }
        break;
    }
    
    case insertionMode_MainPhase_InColumnGroup:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InColumnGroup Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InColumnGroup - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InColumnGroup Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InColumnGroup EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InColumnGroup - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InColumnGroup - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_InColumnGroup Character [9, 10, 11, 12, 32]");
            debug("# - AppendCharacterTokensToCurrentNode");
            this.appendCharacterToCurrentNode(token);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_InColumnGroup Comment");
            debug("# - AppendCommentTokenToCurrentNode");
            this.appendCommentToCurrentNode(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "col"))
        {
            debug("# MainPhase_InColumnGroup Start tag [col]");
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
        }
        else
        if (token[0] == "EndTag" && (token[1] == "colgroup"))
        {
            debug("# MainPhase_InColumnGroup End tag [colgroup]");
            debug("# - If");
            if (this.currentNodeHasName("html"))
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InColumnGroup - End tag [colgroup]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - PopCurrentNodeFromStack");
                this.popCurrentNode();
                debug("# - SetInsertionMode");
                this.setInsertionMode(insertionMode_MainPhase_InTable);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "col"))
        {
            debug("# MainPhase_InColumnGroup End tag [col]");
            debug("# - ParseError");
            this.parseError("MainPhase_InColumnGroup - End tag [col]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (true)
        {
            debug("# MainPhase_InColumnGroup Anything else");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'colgroup'], this.insertionMode);
            debug("# - If");
            if (true)
            {
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        break;
    }
    
    case insertionMode_MainPhase_InTableBody:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InTableBody Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InTableBody - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InTableBody Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InTableBody EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InTableBody - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InTableBody - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "tr"))
        {
            debug("# MainPhase_InTableBody Start tag [tr]");
            debug("# - ClearStackToContext");
            this.clearStackToContext([ "tbody", "thead", "tfoot", "html" ]);
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InRow);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "th" || token[1] == "td"))
        {
            debug("# MainPhase_InTableBody Start tag [th, td]");
            debug("# - ParseError");
            this.parseError("MainPhase_InTableBody - Start tag [th, td]");
            debug("# - ActAsIfStartTag");
            this.processToken(['StartTag', 'tr', []], this.insertionMode);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "tbody" || token[1] == "tfoot" || token[1] == "thead"))
        {
            debug("# MainPhase_InTableBody End tag [tbody, tfoot, thead]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ token[1] ])))
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InTableBody - End tag [tbody, tfoot, thead]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - ClearStackToContext");
                this.clearStackToContext([ "tbody", "thead", "tfoot", "html" ]);
                debug("# - PopCurrentNodeFromStack");
                this.popCurrentNode();
                debug("# - SetInsertionMode");
                this.setInsertionMode(insertionMode_MainPhase_InTable);
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "tbody" || token[1] == "tfoot" || token[1] == "thead"))
        {
            debug("# MainPhase_InTableBody Start tag [caption, col, colgroup, tbody, tfoot, thead]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ "tbody", "thead", "tfoot" ])))
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InTableBody - Start tag [caption, col, colgroup, tbody, tfoot, thead]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - ClearStackToContext");
                this.clearStackToContext([ "tbody", "thead", "tfoot", "html" ]);
                debug("# - PopCurrentNodeFromStack");
                this.popCurrentNode();
                debug("# - SetInsertionMode");
                this.setInsertionMode(insertionMode_MainPhase_InTable);
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "table"))
        {
            debug("# MainPhase_InTableBody End tag [table]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ "tbody", "thead", "tfoot" ])))
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InTableBody - End tag [table]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - ClearStackToContext");
                this.clearStackToContext([ "tbody", "thead", "tfoot", "html" ]);
                debug("# - PopCurrentNodeFromStack");
                this.popCurrentNode();
                debug("# - SetInsertionMode");
                this.setInsertionMode(insertionMode_MainPhase_InTable);
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "body" || token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "html" || token[1] == "td" || token[1] == "th" || token[1] == "tr"))
        {
            debug("# MainPhase_InTableBody End tag [body, caption, col, colgroup, html, td, th, tr]");
            debug("# - ParseError");
            this.parseError("MainPhase_InTableBody - End tag [body, caption, col, colgroup, html, td, th, tr]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (true)
        {
            debug("# MainPhase_InTableBody Anything else");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InTable);
        }
        break;
    }
    
    case insertionMode_MainPhase_InRow:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InRow Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InRow - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InRow Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InRow EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InRow - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InRow - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "th" || token[1] == "td"))
        {
            debug("# MainPhase_InRow Start tag [th, td]");
            debug("# - ClearStackToContext");
            this.clearStackToContext([ "tr", "html" ]);
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InCell);
            debug("# - AddMarkerToActiveList");
            this.addToActiveList(null);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "tr"))
        {
            debug("# MainPhase_InRow End tag [tr]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ token[1] ])))
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InRow - End tag [tr]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - ClearStackToContext");
                this.clearStackToContext([ "tr", "html" ]);
                debug("# - PopCurrentNodeFromStack");
                this.popCurrentNode();
                debug("# - SetInsertionMode");
                this.setInsertionMode(insertionMode_MainPhase_InTableBody);
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "tbody" || token[1] == "tfoot" || token[1] == "thead" || token[1] == "tr"))
        {
            debug("# MainPhase_InRow Start tag [caption, col, colgroup, tbody, tfoot, thead, tr]");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'tr'], this.insertionMode);
            debug("# - If");
            if (true)
            {
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "table"))
        {
            debug("# MainPhase_InRow End tag [table]");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'tr'], this.insertionMode);
            debug("# - If");
            if (true)
            {
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "tbody" || token[1] == "tfoot" || token[1] == "thead"))
        {
            debug("# MainPhase_InRow End tag [tbody, tfoot, thead]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ token[1] ])))
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InRow - End tag [tbody, tfoot, thead]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'tr'], this.insertionMode);
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "body" || token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "html" || token[1] == "td" || token[1] == "th"))
        {
            debug("# MainPhase_InRow End tag [body, caption, col, colgroup, html, td, th]");
            debug("# - ParseError");
            this.parseError("MainPhase_InRow - End tag [body, caption, col, colgroup, html, td, th]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (true)
        {
            debug("# MainPhase_InRow Anything else");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InTable);
        }
        break;
    }
    
    case insertionMode_MainPhase_InCell:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InCell Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InCell - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InCell Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InCell EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InCell - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InCell - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "td" || token[1] == "th"))
        {
            debug("# MainPhase_InCell End tag [td, th]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ token[1] ])))
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InCell - End tag [td, th]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - GenerateImpliedEndTags");
                this.generateImpliedEndTags([ token[1] ]);
                debug("# - If");
                if (!(this.currentNodeHasName(token[1])))
                {
                    debug("# - ParseError");
                    this.parseError("current node has wrong name");
                }
                debug("# - PopElementsFromStackUntilOneOf");
                this.popUntilOneOf([ token[1] ]);
                debug("# - ClearActiveListUpToMarker");
                this.clearActiveListUpToMarker();
                debug("# - SetInsertionMode");
                this.setInsertionMode(insertionMode_MainPhase_InRow);
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "tbody" || token[1] == "td" || token[1] == "tfoot" || token[1] == "th" || token[1] == "thead" || token[1] == "tr"))
        {
            debug("# MainPhase_InCell Start tag [caption, col, colgroup, tbody, td, tfoot, th, thead, tr]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ "td", "th" ])))
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InCell - Start tag [caption, col, colgroup, tbody, td, tfoot, th, thead, tr]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - If");
                if (this.hasElementInScope(true, [ "td" ]))
                {
                    debug("# - ActAsIfEndTag");
                    this.processToken(['EndTag', 'td'], this.insertionMode);
                }
                else
                {
                    debug("# - ActAsIfEndTag");
                    this.processToken(['EndTag', 'th'], this.insertionMode);
                }
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "body" || token[1] == "caption" || token[1] == "col" || token[1] == "colgroup" || token[1] == "html"))
        {
            debug("# MainPhase_InCell End tag [body, caption, col, colgroup, html]");
            debug("# - ParseError");
            this.parseError("MainPhase_InCell - End tag [body, caption, col, colgroup, html]");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "table" || token[1] == "tbody" || token[1] == "tfoot" || token[1] == "thead" || token[1] == "tr"))
        {
            debug("# MainPhase_InCell End tag [table, tbody, tfoot, thead, tr]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ token[1] ])))
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InCell - End tag [table, tbody, tfoot, thead, tr]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - If");
                if (this.hasElementInScope(true, [ "td" ]))
                {
                    debug("# - ActAsIfEndTag");
                    this.processToken(['EndTag', 'td'], this.insertionMode);
                }
                else
                {
                    debug("# - ActAsIfEndTag");
                    this.processToken(['EndTag', 'th'], this.insertionMode);
                }
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
        }
        else
        if (true)
        {
            debug("# MainPhase_InCell Anything else");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InBody);
        }
        break;
    }
    
    case insertionMode_MainPhase_InSelect:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InSelect Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InSelect - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InSelect Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InSelect EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InSelect - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InSelect - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "Character")
        {
            debug("# MainPhase_InSelect Character");
            debug("# - AppendCharacterTokensToCurrentNode");
            this.appendCharacterToCurrentNode(token);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_InSelect Comment");
            debug("# - AppendCommentTokenToCurrentNode");
            this.appendCommentToCurrentNode(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "option"))
        {
            debug("# MainPhase_InSelect Start tag [option]");
            debug("# - If");
            if (this.currentNodeHasName("option"))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'option'], this.insertionMode);
            }
            debug("# - InsertElement");
            this.insertElement(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "optgroup"))
        {
            debug("# MainPhase_InSelect Start tag [optgroup]");
            debug("# - If");
            if (this.currentNodeHasName("option"))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'option'], this.insertionMode);
            }
            debug("# - If");
            if (this.currentNodeHasName("optgroup"))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'optgroup'], this.insertionMode);
            }
            debug("# - InsertElement");
            this.insertElement(token);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "optgroup"))
        {
            debug("# MainPhase_InSelect End tag [optgroup]");
            debug("# - If");
            if (this.currentNodeHasName("option"))
            {
                debug("# - If");
                if (this.nodeBeforeCurrentHasName("optgroup"))
                {
                    debug("# - ActAsIfEndTag");
                    this.processToken(['EndTag', 'option'], this.insertionMode);
                }
            }
            debug("# - If");
            if (this.currentNodeHasName("optgroup"))
            {
                debug("# - PopCurrentNodeFromStack");
                this.popCurrentNode();
            }
            else
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InSelect - End tag [optgroup]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "option"))
        {
            debug("# MainPhase_InSelect End tag [option]");
            debug("# - If");
            if (this.currentNodeHasName("option"))
            {
                debug("# - PopCurrentNodeFromStack");
                this.popCurrentNode();
            }
            else
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InSelect - End tag [option]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
        }
        else
        if (token[0] == "EndTag" && (token[1] == "select"))
        {
            debug("# MainPhase_InSelect End tag [select]");
            debug("# - If");
            if (!(this.hasElementInScope(true, [ token[1] ])))
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InSelect - End tag [select]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - PopElementsFromStackUntilOneOf");
                this.popUntilOneOf([ "select" ]);
                debug("# - ResetInsertionModeAppropriately");
                this.resetInsertionModeAppropriately();
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "select"))
        {
            debug("# MainPhase_InSelect Start tag [select]");
            debug("# - ParseError");
            this.parseError("MainPhase_InSelect - Start tag [select]");
            debug("# - ActAsIfEndTag");
            this.processToken(['EndTag', 'select'], this.insertionMode);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "caption" || token[1] == "table" || token[1] == "tbody" || token[1] == "tfoot" || token[1] == "thead" || token[1] == "tr" || token[1] == "td" || token[1] == "th"))
        {
            debug("# MainPhase_InSelect End tag [caption, table, tbody, tfoot, thead, tr, td, th]");
            debug("# - ParseError");
            this.parseError("MainPhase_InSelect - End tag [caption, table, tbody, tfoot, thead, tr, td, th]");
            debug("# - If");
            if (this.hasElementInScope(true, [ token[1] ]))
            {
                debug("# - ActAsIfEndTag");
                this.processToken(['EndTag', 'select'], this.insertionMode);
                debug("# - ReprocessCurrentToken");
                this.processToken(token, this.insertionMode);
            }
            else
            {
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
        }
        else
        if (true)
        {
            debug("# MainPhase_InSelect Anything else");
            debug("# - ParseError");
            this.parseError("MainPhase_InSelect - Anything else");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        break;
    }
    
    case insertionMode_MainPhase_AfterBody:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_AfterBody Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_AfterBody - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_AfterBody Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_AfterBody EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_AfterBody - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_AfterBody - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_AfterBody Character [9, 10, 11, 12, 32]");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InBody);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_AfterBody Comment");
            debug("# - AppendCommentTokenToHTMLElement");
            debug("TODO: AppendCommentTokenToHTMLElement");
        }
        else
        if (token[0] == "EndTag" && (token[1] == "html"))
        {
            debug("# MainPhase_AfterBody End tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_AfterBody - End tag [html]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - SetInsertionMode");
                this.setInsertionMode(insertionMode_TrailingEndPhase);
            }
        }
        else
        if (true)
        {
            debug("# MainPhase_AfterBody Anything else");
            debug("# - ParseError");
            this.parseError("MainPhase_AfterBody - Anything else");
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_InBody);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        break;
    }
    
    case insertionMode_MainPhase_InFrameset:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_InFrameset Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_InFrameset - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_InFrameset Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_InFrameset EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_InFrameset - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_InFrameset - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_InFrameset Character [9, 10, 11, 12, 32]");
            debug("# - AppendCharacterTokensToCurrentNode");
            this.appendCharacterToCurrentNode(token);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_InFrameset Comment");
            debug("# - AppendCommentTokenToCurrentNode");
            this.appendCommentToCurrentNode(token);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "frameset"))
        {
            debug("# MainPhase_InFrameset Start tag [frameset]");
            debug("# - InsertElement");
            this.insertElement(token);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "frameset"))
        {
            debug("# MainPhase_InFrameset End tag [frameset]");
            debug("# - If");
            if (this.currentNodeHasName("html"))
            {
                debug("# - AssertFragmentCase");
                debug("TODO: AssertFragmentCase");
                debug("# - ParseError");
                this.parseError("MainPhase_InFrameset - End tag [frameset]");
                debug("# - IgnoreToken");
                debug("TODO: IgnoreToken");
            }
            else
            {
                debug("# - PopCurrentNodeFromStack");
                this.popCurrentNode();
            }
            debug("# - If");
            if (false)
            {
            }
            else
            {
                debug("# - If");
                if (!(this.currentNodeHasName("frameset")))
                {
                    debug("# - SetInsertionMode");
                    this.setInsertionMode(insertionMode_MainPhase_AfterFrameset);
                }
            }
        }
        else
        if (token[0] == "StartTag" && (token[1] == "frame"))
        {
            debug("# MainPhase_InFrameset Start tag [frame]");
            debug("# - InsertElement");
            this.insertElement(token);
            debug("# - PopCurrentNodeFromStack");
            this.popCurrentNode();
        }
        else
        if (token[0] == "StartTag" && (token[1] == "noframes"))
        {
            debug("# MainPhase_InFrameset Start tag [noframes]");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InBody);
        }
        else
        if (true)
        {
            debug("# MainPhase_InFrameset Anything else");
            debug("# - ParseError");
            this.parseError("MainPhase_InFrameset - Anything else");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        break;
    }
    
    case insertionMode_MainPhase_AfterFrameset:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# MainPhase_AfterFrameset Doctype");
            debug("# - ParseError");
            this.parseError("MainPhase_AfterFrameset - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "StartTag" && (token[1] == "html"))
        {
            debug("# MainPhase_AfterFrameset Start tag [html]");
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("not the first start tag token");
            }
            debug("# - MergeAttributesIntoHTMLElement");
            debug("TODO: MergeAttributesIntoHTMLElement");
        }
        else
        if (token == "EndOfFile")
        {
            debug("# MainPhase_AfterFrameset EOF");
            debug("# - GenerateImpliedEndTags");
            this.generateImpliedEndTags([  ]);
            debug("# - If");
            if (false)
            {
                debug("# - ParseError");
                this.parseError("MainPhase_AfterFrameset - EOF");
            }
            else
            {
                debug("# - If");
                if (false)
                {
                    debug("# - If");
                    if (false)
                    {
                        debug("# - ParseError");
                        this.parseError("MainPhase_AfterFrameset - EOF");
                    }
                }
            }
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# MainPhase_AfterFrameset Character [9, 10, 11, 12, 32]");
            debug("# - AppendCharacterTokensToCurrentNode");
            this.appendCharacterToCurrentNode(token);
        }
        else
        if (token[0] == "Comment")
        {
            debug("# MainPhase_AfterFrameset Comment");
            debug("# - AppendCommentTokenToCurrentNode");
            this.appendCommentToCurrentNode(token);
        }
        else
        if (token[0] == "EndTag" && (token[1] == "html"))
        {
            debug("# MainPhase_AfterFrameset End tag [html]");
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_TrailingEndPhase);
        }
        else
        if (token[0] == "StartTag" && (token[1] == "noframes"))
        {
            debug("# MainPhase_AfterFrameset Start tag [noframes]");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_InBody);
        }
        else
        if (true)
        {
            debug("# MainPhase_AfterFrameset Anything else");
            debug("# - ParseError");
            this.parseError("MainPhase_AfterFrameset - Anything else");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        break;
    }
    
    case insertionMode_TrailingEndPhase:
    {
        if (token[0] == "DOCTYPE")
        {
            debug("# TrailingEndPhase Doctype");
            debug("# - ParseError");
            this.parseError("TrailingEndPhase - Doctype");
            debug("# - IgnoreToken");
            debug("TODO: IgnoreToken");
        }
        else
        if (token[0] == "Comment")
        {
            debug("# TrailingEndPhase Comment");
            debug("# - AppendCommentTokenToDocument");
            this.appendCommentToDocument(token);
        }
        else
        if (token[0] == "Character" && (token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# TrailingEndPhase Character [9, 10, 11, 12, 32]");
            debug("# - ReprocessAsIf");
            this.reprocessAsIf(token, insertionMode_MainPhase_AfterBody);
        }
        else
        if (token[0] == "Character" && !(token[1].charCodeAt(0) == 9 || token[1].charCodeAt(0) == 10 || token[1].charCodeAt(0) == 11 || token[1].charCodeAt(0) == 12 || token[1].charCodeAt(0) == 32))
        {
            debug("# TrailingEndPhase Character not [9, 10, 11, 12, 32]");
            debug("# - ParseError");
            this.parseError("TrailingEndPhase - Character not [9, 10, 11, 12, 32]");
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_AfterBody);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "StartTag")
        {
            debug("# TrailingEndPhase Start tag");
            debug("# - ParseError");
            this.parseError("TrailingEndPhase - Start tag");
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_AfterBody);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token[0] == "EndTag")
        {
            debug("# TrailingEndPhase End tag");
            debug("# - ParseError");
            this.parseError("TrailingEndPhase - End tag");
            debug("# - SetInsertionMode");
            this.setInsertionMode(insertionMode_MainPhase_AfterBody);
            debug("# - ReprocessCurrentToken");
            this.processToken(token, this.insertionMode);
        }
        else
        if (token == "EndOfFile")
        {
            debug("# TrailingEndPhase EOF");
            debug("# - StopParsing");
            debug("TODO: StopParsing");
        }
        break;
    }
    
    }
};

TreeConstructor.prototype.run = function ()
{
    var token;
    while (true)
    {
        token = this.tokenStream[this.tokenStreamPos];
        if (!(token))
        {
            return;
        }
        this.processToken(token, this.insertionMode);
        this.tokenStreamPos = this.tokenStreamPos + 1;
    }
};
