Search in sources :

Example 1 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class RestParser method parseMarkup.

private static void parseMarkup(PsiBuilder builder) {
    PsiBuilder.Marker marker = builder.mark();
    IElementType type = builder.getTokenType();
    if (type == RestTokenTypes.SUBSTITUTION) {
        builder.advanceLexer();
        marker.done(RestElementTypes.REFERENCE_TARGET);
        builder.advanceLexer();
        marker = builder.mark();
        type = builder.getTokenType();
    }
    if (type == RestTokenTypes.DIRECTIVE) {
        gotoNextWhiteSpaces(builder);
        if (builder.getTokenType() != RestTokenTypes.WHITESPACE) {
            builder.advanceLexer();
            marker.done(RestElementTypes.DIRECTIVE_BLOCK);
            return;
        }
        skipBlankLines(builder);
        if (builder.getTokenType() != RestTokenTypes.WHITESPACE || "\n".equals(builder.getTokenText())) {
            marker.done(RestElementTypes.DIRECTIVE_BLOCK);
            return;
        }
        String white = builder.getTokenText();
        parseDirective(builder, white, marker);
    } else if (type == RestTokenTypes.FOOTNOTE || type == RestTokenTypes.CITATION || type == RestTokenTypes.HYPERLINK || type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
        builder.advanceLexer();
        marker.done(RestElementTypes.REFERENCE_TARGET);
    } else {
        builder.advanceLexer();
        marker.drop();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 2 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class RestParser method parse.

@NotNull
public ASTNode parse(IElementType root, PsiBuilder builder) {
    final PsiBuilder.Marker rootMarker = builder.mark();
    while (!builder.eof()) {
        IElementType type = builder.getTokenType();
        if (type == RestTokenTypes.EXPLISIT_MARKUP_START) {
            builder.advanceLexer();
            parseMarkup(builder);
        } else if (type == RestTokenTypes.REFERENCE_NAME || type == RestTokenTypes.SUBSTITUTION) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestTokenTypes.REFERENCE_NAME);
        } else if (type == RestTokenTypes.TITLE) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestTokenTypes.TITLE);
        } else if (type == RestTokenTypes.FIELD) {
            parseFieldList(builder);
        } else if (type == RestTokenTypes.INLINE_LINE) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestElementTypes.INLINE_BLOCK);
        } else if (type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestElementTypes.REFERENCE_TARGET);
        } else if (type == RestTokenTypes.LINE) {
            parseLineText(builder, type);
        } else
            builder.advanceLexer();
    }
    rootMarker.done(root);
    return builder.getTreeBuilt();
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class XPath2Parser method parseSequenceType.

private boolean parseSequenceType(PsiBuilder builder) {
    PsiBuilder.Marker mark = builder.mark();
    final IElementType type = parseItemOrEmptySequenceType(builder);
    if (type != null) {
        if (type == XPath2TokenTypes.ITEM) {
            if (XPath2TokenTypes.OCCURRENCE_OPS.contains(builder.getTokenType())) {
                makeToken(builder);
            }
        }
        mark.done(XPath2ElementTypes.SEQUENCE_TYPE);
        return true;
    } else if (parseNodeType(builder) || parseQName(builder)) {
        if (builder.getTokenType() == XPathTokenTypes.MULT) {
            builder.remapCurrentToken(XPathTokenTypes.STAR);
        }
        if (XPath2TokenTypes.OCCURRENCE_OPS.contains(builder.getTokenType())) {
            makeToken(builder);
        }
        mark.done(XPath2ElementTypes.SEQUENCE_TYPE);
        return true;
    }
    mark.drop();
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 4 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class XPathParser method parseAxisSpecifier.

/**
   * [5]    AxisSpecifier    ::=    AxisName '::' | AbbreviatedAxisSpecifier
   * <p/>
   * [13]   AbbreviatedAxisSpecifier    ::=    '@'?
   */
private boolean parseAxisSpecifier(PsiBuilder builder) {
    final PsiBuilder.Marker marker = builder.mark();
    final IElementType tokenType = builder.getTokenType();
    if (XPathTokenTypes.AXIS.contains(tokenType)) {
        builder.advanceLexer();
        checkMatches(builder, XPathTokenTypes.COLCOL, ":: expected");
    } else {
        if (tokenType == XPathTokenTypes.AT) {
            builder.advanceLexer();
        } else if (tokenType == XPathTokenTypes.DOT || tokenType == XPathTokenTypes.DOTDOT) {
            marker.drop();
            return false;
        } else {
            final PsiBuilder.Marker m = builder.mark();
            final boolean b = parseNodeTest(builder);
            m.rollbackTo();
            if (!b) {
                marker.drop();
                return false;
            }
        }
    }
    marker.done(XPathElementTypes.AXIS_SPECIFIER);
    return true;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 5 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.

the class StatementParsing method parseImportStatement.

protected void parseImportStatement(IElementType statementType, IElementType elementType) {
    final PsiBuilder builder = myContext.getBuilder();
    final PsiBuilder.Marker importStatement = builder.mark();
    builder.advanceLexer();
    parseImportElements(elementType, true, false, false);
    checkEndOfStatement();
    importStatement.done(statementType);
}
Also used : PsiBuilder(com.intellij.lang.PsiBuilder)

Aggregations

PsiBuilder (com.intellij.lang.PsiBuilder)124 IElementType (com.intellij.psi.tree.IElementType)90 Nullable (org.jetbrains.annotations.Nullable)18 NotNull (org.jetbrains.annotations.NotNull)16 Project (com.intellij.openapi.project.Project)7 LighterASTNode (com.intellij.lang.LighterASTNode)6 GroovyElementType (org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType)5 Language (com.intellij.lang.Language)3 ASTNode (com.intellij.lang.ASTNode)2 PsiElement (com.intellij.psi.PsiElement)2 ILazyParseableElementType (com.intellij.psi.tree.ILazyParseableElementType)2 ParsingContext (com.jetbrains.python.parsing.ParsingContext)2 StatementParsing (com.jetbrains.python.parsing.StatementParsing)2 ParserDefinition (com.intellij.lang.ParserDefinition)1 PsiParser (com.intellij.lang.PsiParser)1 HtmlParsing (com.intellij.lang.html.HtmlParsing)1 Lexer (com.intellij.lexer.Lexer)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1