Search in sources :

Example 61 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project Perl5-IDEA by Camelcade.

the class MojoliciousParser method parseTerm.

@Override
public boolean parseTerm(PsiBuilder b, int l) {
    IElementType tokenType = b.getTokenType();
    if (tokenType == MOJO_BEGIN) {
        PsiBuilder.Marker subMarker = b.mark();
        b.advanceLexer();
        PsiBuilder.Marker blockMarker = b.mark();
        PerlParserImpl.block_content(b, l);
        if (b.getTokenType() == MOJO_END) {
            blockMarker.done(BLOCK);
            blockMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
            subMarker.done(SUB_EXPR);
            return true;
        } else {
            blockMarker.drop();
            subMarker.rollbackTo();
        }
    }
    return super.parseTerm(b, l);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 62 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project Perl5-IDEA by Camelcade.

the class PerlLazyBlockElementType method parseContents.

@Override
public ASTNode parseContents(ASTNode chameleon) {
    PsiElement parentElement = chameleon.getTreeParent().getPsi();
    Project project = parentElement.getProject();
    PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, getLexer(parentElement.getProject()), getLanguage(), chameleon.getText());
    return getParser().parse(this, builder).getFirstChildNode();
}
Also used : Project(com.intellij.openapi.project.Project) PsiBuilder(com.intellij.lang.PsiBuilder) PsiElement(com.intellij.psi.PsiElement)

Example 63 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project netbeans-mmd-plugin by raydac.

the class MMPsiParser method recursiveParseTopic.

private int recursiveParseTopic(@Nonnull final PsiBuilder builder, final int level) {
    while (!builder.eof()) {
        final PsiBuilder.Marker marker = builder.mark();
        final IElementType token = builder.getTokenType();
        if (token == null) {
            marker.drop();
        } else {
            if (token == MMTokens.TOPIC_LEVEL) {
                final PsiBuilder.Marker levelMarker = builder.mark();
                levelMarker.done(token);
                final int theTopicLevel = ModelUtils.calcCharsOnStart('#', builder.getTokenText());
                if (theTopicLevel <= 1) {
                    marker.done(MMTokens.UNKNOWN);
                } else {
                    if (theTopicLevel <= level) {
                        marker.rollbackTo();
                        return theTopicLevel;
                    } else {
                        builder.advanceLexer();
                        final int parsedTopicLevel = recursiveParseTopic(builder, theTopicLevel);
                        marker.done(MMTokens.TOPIC);
                        if (parsedTopicLevel < theTopicLevel)
                            return parsedTopicLevel;
                        if (parsedTopicLevel == theTopicLevel)
                            continue;
                    }
                }
            } else if (token == MMTokens.TOPIC_TITLE || token == MMTokens.CODE_SNIPPET_BODY || token == MMTokens.CODE_SNIPPET_END || token == MMTokens.CODE_SNIPPET_START || token == MMTokens.ATTRIBUTES) {
                marker.done(token);
            } else if (token == MMTokens.EXTRA_TYPE) {
                try {
                    if (parseExtraBlock(builder))
                        continue;
                } finally {
                    marker.done(MMTokens.EXTRA_DATA);
                }
            } else if (token == MMTokens.WHITE_SPACE) {
                marker.done(token);
            } else {
                marker.done(MMTokens.UNKNOWN);
            }
        }
        builder.advanceLexer();
    }
    return level;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 64 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project netbeans-mmd-plugin by raydac.

the class MMPsiParser method parseExtraBlock.

private boolean parseExtraBlock(@Nonnull final PsiBuilder builder) {
    // read type
    final PsiBuilder.Marker type = builder.mark();
    if (builder.getTokenType() != MMTokens.EXTRA_TYPE)
        throw Assertions.fail("Unexpected token " + builder.getTokenType());
    builder.advanceLexer();
    type.done(MMTokens.EXTRA_TYPE);
    boolean dataFound = false;
    // read body
    while (!builder.eof()) {
        final PsiBuilder.Marker marker = builder.mark();
        if (builder.eof() || builder.getTokenType() == null) {
            marker.drop();
            break;
        } else {
            final IElementType token = builder.getTokenType();
            if (token == MMTokens.TOPIC_LEVEL || token == MMTokens.EXTRA_TYPE) {
                marker.rollbackTo();
                return true;
            } else if (token == MMTokens.EXTRA_BODY || token == MMTokens.WHITE_SPACE) {
                if (dataFound && token == MMTokens.EXTRA_BODY) {
                    builder.advanceLexer();
                    marker.done(MMTokens.UNKNOWN);
                    break;
                } else {
                    builder.advanceLexer();
                    marker.done(token);
                    dataFound = dataFound || token == MMTokens.EXTRA_BODY;
                }
            } else {
                marker.done(MMTokens.UNKNOWN);
                break;
            }
        }
    }
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 65 with PsiBuilder

use of com.intellij.lang.PsiBuilder in project netbeans-mmd-plugin by raydac.

the class MMPsiParser method parseHeader.

private void parseHeader(@Nonnull final PsiBuilder builder) {
    boolean doLoop = true;
    while (doLoop && !builder.eof()) {
        final PsiBuilder.Marker marker = builder.mark();
        if (builder.getTokenType() == null) {
            marker.drop();
        } else {
            final IElementType token = builder.getTokenType();
            if (token == MMTokens.HEADER_DELIMITER) {
                marker.done(token);
                doLoop = false;
            } else if (token == MMTokens.HEADER_LINE || token == MMTokens.UNKNOWN || token == MMTokens.WHITE_SPACE || token == MMTokens.ATTRIBUTES) {
                marker.done(token);
            } else {
                throw Assertions.fail("Unexpected header token : " + token);
            }
        }
        builder.advanceLexer();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) 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