use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLElementLiteral in project ballerina by ballerina-lang.
the class TypeChecker method validateTags.
private void validateTags(BLangXMLElementLiteral bLangXMLElementLiteral, SymbolEnv xmlElementEnv) {
// check type for start and end tags
BLangExpression startTagName = (BLangExpression) bLangXMLElementLiteral.startTagName;
checkExpr(startTagName, xmlElementEnv, Lists.of(symTable.stringType));
BLangExpression endTagName = (BLangExpression) bLangXMLElementLiteral.endTagName;
if (endTagName != null) {
checkExpr(endTagName, xmlElementEnv, Lists.of(symTable.stringType));
}
if (endTagName == null) {
return;
}
if (startTagName.getKind() == NodeKind.XML_QNAME && startTagName.getKind() == NodeKind.XML_QNAME && startTagName.equals(endTagName)) {
return;
}
if (startTagName.getKind() != NodeKind.XML_QNAME && startTagName.getKind() != NodeKind.XML_QNAME) {
return;
}
dlog.error(startTagName.pos, DiagnosticCode.XML_TAGS_MISMATCH);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLElementLiteral in project ballerina by ballerina-lang.
the class CodeGenerator method visit.
@Override
public void visit(BLangXMLElementLiteral xmlElementLiteral) {
SymbolEnv xmlElementEnv = SymbolEnv.getXMLElementEnv(xmlElementLiteral, env);
xmlElementLiteral.regIndex = calcAndGetExprRegIndex(xmlElementLiteral);
// Visit in-line namespace declarations. These needs to be visited first before visiting the
// attributes, start and end tag names of the element.
xmlElementLiteral.inlineNamespaces.forEach(xmlns -> {
genNode(xmlns, xmlElementEnv);
});
// Create start tag name
BLangExpression startTagName = (BLangExpression) xmlElementLiteral.getStartTagName();
RegIndex startTagNameRegIndex = visitXMLTagName(startTagName, xmlElementEnv, xmlElementLiteral);
// Create end tag name. If there is no endtag name (empty XML tag),
// then consider start tag name as the end tag name too.
BLangExpression endTagName = (BLangExpression) xmlElementLiteral.getEndTagName();
RegIndex endTagNameRegIndex = endTagName == null ? startTagNameRegIndex : visitXMLTagName(endTagName, xmlElementEnv, xmlElementLiteral);
// Create an XML with the given QName
RegIndex defaultNsURIIndex = getNamespaceURIIndex(xmlElementLiteral.defaultNsSymbol, xmlElementEnv);
emit(InstructionCodes.NEWXMLELEMENT, xmlElementLiteral.regIndex, startTagNameRegIndex, endTagNameRegIndex, defaultNsURIIndex);
// Add namespaces decelerations visible to this element.
xmlElementLiteral.namespacesInScope.forEach((name, symbol) -> {
BLangXMLQName nsQName = new BLangXMLQName(name.getValue(), XMLConstants.XMLNS_ATTRIBUTE);
genNode(nsQName, xmlElementEnv);
RegIndex uriIndex = getNamespaceURIIndex(symbol, xmlElementEnv);
emit(InstructionCodes.XMLATTRSTORE, xmlElementLiteral.regIndex, nsQName.regIndex, uriIndex);
});
// Add attributes
xmlElementLiteral.attributes.forEach(attribute -> {
genNode(attribute, xmlElementEnv);
emit(InstructionCodes.XMLATTRSTORE, xmlElementLiteral.regIndex, attribute.name.regIndex, attribute.value.regIndex);
});
// Add children
xmlElementLiteral.modifiedChildren.forEach(child -> {
genNode(child, xmlElementEnv);
emit(InstructionCodes.XMLSEQSTORE, xmlElementLiteral.regIndex, child.regIndex);
});
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLElementLiteral in project ballerina by ballerina-lang.
the class BLangPackageBuilder method endXMLElement.
public void endXMLElement(Set<Whitespace> ws) {
BLangExpression endTag = (BLangExpression) exprNodeStack.pop();
BLangXMLElementLiteral xmlElement = (BLangXMLElementLiteral) exprNodeStack.peek();
xmlElement.addWS(ws);
xmlElement.endTagName = endTag;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLElementLiteral in project ballerina by ballerina-lang.
the class BLangPackageBuilder method addXMLTextToElement.
public void addXMLTextToElement(DiagnosticPos pos, Set<Whitespace> ws, Stack<String> precedingTextFragments, String endingText) {
List<BLangExpression> templateExprs = getExpressionsInTemplate(pos, ws, precedingTextFragments, endingText, NodeKind.XML_TEXT_LITERAL);
BLangXMLElementLiteral parentElement = (BLangXMLElementLiteral) exprNodeStack.peek();
templateExprs.forEach(expr -> parentElement.addChild(expr));
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLElementLiteral in project ballerina by ballerina-lang.
the class BLangPackageBuilder method startXMLElement.
public void startXMLElement(DiagnosticPos pos, Set<Whitespace> ws, boolean isRoot) {
BLangXMLElementLiteral xmlElement = (BLangXMLElementLiteral) TreeBuilder.createXMLElementLiteralNode();
BLangExpression startTag = (BLangExpression) exprNodeStack.pop();
xmlElement.addWS(ws);
xmlElement.startTagName = startTag;
xmlElement.pos = pos;
xmlElement.isRoot = isRoot;
xmlAttributeNodeStack.forEach(attribute -> xmlElement.addAttribute(attribute));
xmlAttributeNodeStack.clear();
addExpressionNode(xmlElement);
}
Aggregations