Search in sources :

Example 1 with ICustomParsingType

use of com.intellij.psi.tree.ICustomParsingType in project intellij-community by JetBrains.

the class XmlParsing method parseTagContent.

public void parseTagContent() {
    PsiBuilder.Marker xmlText = null;
    while (token() != XML_END_TAG_START && !eof()) {
        final IElementType tt = token();
        if (tt == XML_START_TAG_START) {
            xmlText = terminateText(xmlText);
            parseTag(false);
        } else if (tt == XML_PI_START) {
            xmlText = terminateText(xmlText);
            parseProcessingInstruction();
        } else if (tt == XML_ENTITY_REF_TOKEN) {
            xmlText = terminateText(xmlText);
            parseReference();
        } else if (tt == XML_CHAR_ENTITY_REF) {
            xmlText = startText(xmlText);
            parseReference();
        } else if (tt == XML_CDATA_START) {
            xmlText = startText(xmlText);
            parseCData();
        } else if (isCommentToken(tt)) {
            xmlText = terminateText(xmlText);
            parseComment();
        } else if (tt == XML_BAD_CHARACTER) {
            xmlText = startText(xmlText);
            final PsiBuilder.Marker error = mark();
            advance();
            error.error(XmlErrorMessages.message("unescaped.ampersand.or.nonterminated.character.entity.reference"));
        } else if (tt instanceof ICustomParsingType || tt instanceof ILazyParseableElementType) {
            xmlText = terminateText(xmlText);
            advance();
        } else {
            xmlText = startText(xmlText);
            advance();
        }
    }
    terminateText(xmlText);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ILazyParseableElementType(com.intellij.psi.tree.ILazyParseableElementType) PsiBuilder(com.intellij.lang.PsiBuilder) ICustomParsingType(com.intellij.psi.tree.ICustomParsingType)

Example 2 with ICustomParsingType

use of com.intellij.psi.tree.ICustomParsingType in project intellij-community by JetBrains.

the class HtmlParsing method parseTag.

private void parseTag() {
    assert token() == XmlTokenType.XML_START_TAG_START : "Tag start expected";
    String originalTagName;
    PsiBuilder.Marker xmlText = null;
    while (!eof()) {
        final IElementType tt = token();
        if (tt == XmlTokenType.XML_START_TAG_START) {
            xmlText = terminateText(xmlText);
            final PsiBuilder.Marker tag = mark();
            // Start tag header
            advance();
            if (token() != XmlTokenType.XML_NAME) {
                error(XmlErrorMessages.message("xml.parsing.tag.name.expected"));
                originalTagName = "";
            } else {
                originalTagName = myBuilder.getTokenText();
                advance();
            }
            String tagName = StringUtil.toLowerCase(originalTagName);
            while (childTerminatesParentInStack(tagName)) {
                PsiBuilder.Marker top = closeTag();
                top.doneBefore(XmlElementType.HTML_TAG, tag);
            }
            myTagMarkersStack.push(tag);
            myTagNamesStack.push(tagName);
            myOriginalTagNamesStack.push(originalTagName);
            parseHeader(tagName);
            if (token() == XmlTokenType.XML_EMPTY_ELEMENT_END) {
                advance();
                doneTag(tag);
                continue;
            }
            if (token() == XmlTokenType.XML_TAG_END) {
                advance();
            } else {
                error(XmlErrorMessages.message("tag.start.is.not.closed"));
                doneTag(tag);
                continue;
            }
            if (HtmlUtil.isSingleHtmlTagL(tagName)) {
                final PsiBuilder.Marker footer = mark();
                if (token() == XmlTokenType.XML_END_TAG_START) {
                    advance();
                    if (token() == XmlTokenType.XML_NAME) {
                        if (tagName.equalsIgnoreCase(myBuilder.getTokenText())) {
                            advance();
                            footer.drop();
                            if (token() == XmlTokenType.XML_TAG_END) {
                                advance();
                            }
                            doneTag(tag);
                            continue;
                        }
                    }
                }
                footer.rollbackTo();
                doneTag(tag);
            }
        } else if (tt == XmlTokenType.XML_PI_START) {
            xmlText = terminateText(xmlText);
            parseProcessingInstruction();
        } else if (tt == XmlTokenType.XML_ENTITY_REF_TOKEN || tt == XmlTokenType.XML_CHAR_ENTITY_REF) {
            xmlText = startText(xmlText);
            parseReference();
        } else if (tt == XmlTokenType.XML_CDATA_START) {
            xmlText = startText(xmlText);
            parseCData();
        } else if (tt == XmlTokenType.XML_COMMENT_START) {
            xmlText = startText(xmlText);
            parseComment();
        } else if (tt == XmlTokenType.XML_BAD_CHARACTER) {
            xmlText = startText(xmlText);
            final PsiBuilder.Marker error = mark();
            advance();
            error.error(XmlErrorMessages.message("unescaped.ampersand.or.nonterminated.character.entity.reference"));
        } else if (tt instanceof ICustomParsingType || tt instanceof ILazyParseableElementType) {
            xmlText = terminateText(xmlText);
            advance();
        } else if (token() == XmlTokenType.XML_END_TAG_START) {
            xmlText = terminateText(xmlText);
            final PsiBuilder.Marker footer = mark();
            advance();
            if (token() == XmlTokenType.XML_NAME) {
                String endName = StringUtil.toLowerCase(myBuilder.getTokenText());
                final String parentTagName = !myTagNamesStack.isEmpty() ? myTagNamesStack.peek() : "";
                if (!parentTagName.equals(endName) && !endName.endsWith(COMPLETION_NAME)) {
                    final boolean isOptionalTagEnd = HtmlUtil.isOptionalEndForHtmlTagL(parentTagName);
                    final boolean hasChancesToMatch = HtmlUtil.isOptionalEndForHtmlTagL(endName) ? childTerminatesParentInStack(endName) : myTagNamesStack.contains(endName);
                    if (hasChancesToMatch) {
                        footer.rollbackTo();
                        if (isOptionalTagEnd) {
                            doneTag(myTagMarkersStack.peek());
                        } else {
                            error(XmlErrorMessages.message("named.element.is.not.closed", myOriginalTagNamesStack.peek()));
                            doneTag(myTagMarkersStack.peek());
                        }
                        continue;
                    } else {
                        advance();
                        if (token() == XmlTokenType.XML_TAG_END)
                            advance();
                        footer.error(XmlErrorMessages.message("xml.parsing.closing.tag.matches.nothing"));
                        continue;
                    }
                }
                advance();
                while (token() != XmlTokenType.XML_TAG_END && token() != XmlTokenType.XML_START_TAG_START && token() != XmlTokenType.XML_END_TAG_START && !eof()) {
                    error(XmlErrorMessages.message("xml.parsing.unexpected.token"));
                    advance();
                }
            } else {
                error(XmlErrorMessages.message("xml.parsing.closing.tag.name.missing"));
            }
            footer.drop();
            if (token() == XmlTokenType.XML_TAG_END) {
                advance();
            } else {
                error(XmlErrorMessages.message("xml.parsing.closing.tag.is.not.done"));
            }
            if (hasTags())
                doneTag(myTagMarkersStack.peek());
        } else if ((token() == XmlTokenType.XML_REAL_WHITE_SPACE || token() == XmlTokenType.XML_DATA_CHARACTERS) && !hasTags()) {
            xmlText = terminateText(xmlText);
            advance();
        } else {
            xmlText = startText(xmlText);
            advance();
        }
    }
    terminateText(xmlText);
    while (hasTags()) {
        final String tagName = myTagNamesStack.peek();
        if (!HtmlUtil.isOptionalEndForHtmlTagL(tagName) && !"html".equals(tagName) && !"body".equals(tagName)) {
            error(XmlErrorMessages.message("named.element.is.not.closed", myOriginalTagNamesStack.peek()));
        }
        doneTag(myTagMarkersStack.peek());
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ILazyParseableElementType(com.intellij.psi.tree.ILazyParseableElementType) PsiBuilder(com.intellij.lang.PsiBuilder) ICustomParsingType(com.intellij.psi.tree.ICustomParsingType)

Aggregations

PsiBuilder (com.intellij.lang.PsiBuilder)2 ICustomParsingType (com.intellij.psi.tree.ICustomParsingType)2 IElementType (com.intellij.psi.tree.IElementType)2 ILazyParseableElementType (com.intellij.psi.tree.ILazyParseableElementType)2