void Parser::xmlElementContent(XmlContext* ctx) { for (;;) { xmlAtom(); switch (T0) { case T_XmlProcessingInstruction: case T_XmlComment: case T_XmlCDATA: case T_XmlName: case T_XmlWhitespace: case T_XmlText: case T_XmlString: case T_XmlRightBrace: case T_XmlRightAngle: case T_XmlSlashRightAngle: case T_XmlEquals: xmlAssert(ctx, T0); continue; case T_XmlLeftBrace: xmlExpression(ctx, ESC_elementValue); continue; case T_XmlLeftAngle: xmlAssert(ctx, T0); xmlAtomSkipSpace(); xmlElement(ctx); continue; case T_XmlLeftAngleSlash: return; default: compiler->internalError(position(), "Unexpected state in XML parsing"); } } }
void Parser::xmlAttributes(XmlContext* ctx) { bool first = true; while (T0 != T_XmlRightAngle && T0 != T_XmlSlashRightAngle) { if (!first) { ctx->addText(" "); first = false; } if (T0 == T_XmlLeftBrace) { xmlExpression(ctx, ESC_attributeValue); xmlAtomSkipSpace(); // {E} = V is an extension required by the test suite, not in Ecma-357 if (T0 == T_XmlEquals) goto attrvalue; } else { xmlAssert(ctx, T_XmlName); xmlAtomSkipSpace(); attrvalue: xmlAssert(ctx, T_XmlEquals); xmlAtomSkipSpace(); if (T0 == T_XmlLeftBrace) { ctx->addText("\""); xmlExpression(ctx, ESC_attributeValue); ctx->addText("\""); } else xmlAssert(ctx, T_XmlString, ESC_attributeValue); xmlAtomSkipSpace(); } } }
void Parser::xmlListInitializer(XmlContext* ctx) { xmlAssert(ctx, T_XmlRightAngle); xmlElementContent(ctx); xmlAssert(ctx, T_XmlLeftAngleSlash); xmlAtomSkipSpace(); xmlAssert(ctx, T_XmlRightAngle); }
void Parser::xmlTagName(XmlContext* ctx) { if (T0 == T_XmlLeftBrace) xmlExpression(ctx, ESC_none); else xmlAssert(ctx, T_XmlName); xmlAtomSkipSpace(); }
void Parser::xmlElement(XmlContext* ctx) { xmlTagName(ctx); if (T0 != T_XmlRightAngle && T0 != T_XmlSlashRightAngle) { ctx->addText(" "); xmlAttributes(ctx); } if (T0 == T_XmlRightAngle) { xmlAssert(ctx, T0); xmlElementContent(ctx); xmlAssert(ctx, T_XmlLeftAngleSlash); xmlAtomSkipSpace(); xmlTagName(ctx); xmlAssert(ctx, T_XmlRightAngle); } else xmlAssert(ctx, T_XmlSlashRightAngle); }
void Parser::xmlExpression(XmlContext* ctx, Escapement esc) { AvmAssert( T0 == T_XmlLeftBrace ); next(); // re-enter normal lexing Expr* expr = commaExpression(0); if (esc != ESC_none) expr = ALLOC(EscapeExpr, (expr, esc)); ctx->addExpr(expr); AvmAssert( T0 == T_RightBrace && T1 == T_LAST ); xmlPushback('}'); xmlAtom(); xmlAssert(ctx, T_XmlRightBrace); }
Expr* Parser::xmlInitializer() { AvmAssert( (T0 == T_BreakXml || T0 == T_LessThan) && T1 == T_LAST ); XmlContext ctx(compiler); bool is_list = false; uint32_t pos = position(); if (T0 == T_LessThan) xmlPushback('<'); xmlAtom(); switch (T0) { case T_XmlComment: case T_XmlCDATA: case T_XmlProcessingInstruction: xmlAssert(&ctx, T0); break; case T_XmlLeftAngle: xmlAssert(&ctx, T0); xmlAtomSkipSpace(); if (T0 == T_XmlRightAngle) { is_list = true; xmlListInitializer(&ctx); } else xmlElement(&ctx); break; default: compiler->internalError(position(), "error state in xml handling"); /*NOTREACHED*/ break; } next(); // Re-synchronize the lexer for normal lexing return ALLOC(XmlInitializer, (ctx.get(), is_list, pos)); }