Search in sources :

Example 51 with PsiBuilder

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

the class GherkinParser method parseFeatureElements.

private static void parseFeatureElements(PsiBuilder builder) {
    while (builder.getTokenType() != GherkinTokenTypes.FEATURE_KEYWORD && !builder.eof()) {
        final PsiBuilder.Marker marker = builder.mark();
        // tags
        parseTags(builder);
        // scenarios
        IElementType startTokenType = builder.getTokenType();
        final boolean outline = startTokenType == GherkinTokenTypes.SCENARIO_OUTLINE_KEYWORD;
        builder.advanceLexer();
        parseScenario(builder, outline);
        marker.done(outline ? GherkinElementTypes.SCENARIO_OUTLINE : GherkinElementTypes.SCENARIO);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 52 with PsiBuilder

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

the class GherkinParser method parseFeature.

private static void parseFeature(PsiBuilder builder) {
    final PsiBuilder.Marker marker = builder.mark();
    assert builder.getTokenType() == GherkinTokenTypes.FEATURE_KEYWORD;
    final int featureEnd = builder.getCurrentOffset() + getTokenLength(builder.getTokenText());
    PsiBuilder.Marker descMarker = null;
    while (true) {
        final IElementType tokenType = builder.getTokenType();
        if (tokenType == GherkinTokenTypes.TEXT && descMarker == null) {
            if (hadLineBreakBefore(builder, featureEnd)) {
                descMarker = builder.mark();
            }
        }
        if (tokenType == GherkinTokenTypes.SCENARIO_KEYWORD || tokenType == GherkinTokenTypes.BACKGROUND_KEYWORD || tokenType == GherkinTokenTypes.SCENARIO_OUTLINE_KEYWORD || tokenType == GherkinTokenTypes.TAG) {
            if (descMarker != null) {
                descMarker.done(GherkinElementTypes.FEATURE_HEADER);
                descMarker = null;
            }
            parseFeatureElements(builder);
            if (builder.getTokenType() == GherkinTokenTypes.FEATURE_KEYWORD) {
                break;
            }
        }
        builder.advanceLexer();
        if (builder.eof())
            break;
    }
    if (descMarker != null) {
        descMarker.done(GherkinElementTypes.FEATURE_HEADER);
    }
    marker.done(GherkinElementTypes.FEATURE);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 53 with PsiBuilder

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

the class GherkinParser method parseTable.

private static void parseTable(PsiBuilder builder) {
    final PsiBuilder.Marker marker = builder.mark();
    PsiBuilder.Marker rowMarker = builder.mark();
    int prevCellEnd = -1;
    boolean isHeaderRow = true;
    PsiBuilder.Marker cellMarker = null;
    IElementType prevToken = null;
    while (builder.getTokenType() == GherkinTokenTypes.PIPE || builder.getTokenType() == GherkinTokenTypes.TABLE_CELL) {
        final IElementType tokenType = builder.getTokenType();
        final boolean hasLineBreakBefore = hadLineBreakBefore(builder, prevCellEnd);
        // cell - is all between pipes
        if (prevToken == GherkinTokenTypes.PIPE) {
            // it's not a cell, we just need to close a row
            if (!hasLineBreakBefore) {
                cellMarker = builder.mark();
            }
        }
        if (tokenType == GherkinTokenTypes.PIPE) {
            if (cellMarker != null) {
                closeCell(cellMarker);
                cellMarker = null;
            }
        }
        if (hasLineBreakBefore) {
            closeRowMarker(rowMarker, isHeaderRow);
            isHeaderRow = false;
            rowMarker = builder.mark();
        }
        prevCellEnd = builder.getCurrentOffset() + getTokenLength(builder.getTokenText());
        prevToken = tokenType;
        builder.advanceLexer();
    }
    if (cellMarker != null) {
        closeCell(cellMarker);
    }
    closeRowMarker(rowMarker, isHeaderRow);
    marker.done(GherkinElementTypes.TABLE);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 54 with PsiBuilder

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

the class TemplateToolkitParserUtil method parseTryCatchBlock.

public static boolean parseTryCatchBlock(PsiBuilder b, int l, PsiBuilder.Marker branchMarker, IElementType branchTokenType) {
    while (!b.eof()) {
        PsiBuilder.Marker currentMarker = b.mark();
        if (TemplateToolkitParser.element(b, l)) {
            LighterASTNode latestDoneMarker = b.getLatestDoneMarker();
            if (latestDoneMarker != null) {
                if (latestDoneMarker.getTokenType() == END_DIRECTIVE) {
                    branchMarker.doneBefore(branchTokenType, currentMarker);
                    branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
                    currentMarker.drop();
                    branchMarker = null;
                    break;
                } else if (latestDoneMarker.getTokenType() == CATCH_DIRECTIVE) {
                    branchMarker.doneBefore(branchTokenType, currentMarker);
                    branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
                    branchMarker = currentMarker.precede();
                    branchTokenType = CATCH_BRANCH;
                } else if (latestDoneMarker.getTokenType() == FINAL_DIRECTIVE) {
                    branchMarker.doneBefore(branchTokenType, currentMarker);
                    branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
                    branchMarker = currentMarker.precede();
                    branchTokenType = FINAL_BRANCH;
                } else {
                    currentMarker.error(PerlBundle.message("ttk2.catch.final.end.expected"));
                }
                currentMarker.drop();
            }
        } else {
            b.advanceLexer();
            currentMarker.error(PerlBundle.message("ttk2.unexpected.token"));
        }
    }
    if (branchMarker != null) {
        branchMarker.done(branchTokenType);
        branchMarker.precede().error(PerlBundle.message("ttk2.error.unclosed.block.directive"));
        branchMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
    }
    return true;
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 55 with PsiBuilder

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

the class TemplateToolkitParserUtil method parsePerlCode.

/**
 * Collapses perl code for lazy parsing
 *
 * @param b builder
 * @param l level
 * @return result of end parsing.
 */
public static boolean parsePerlCode(PsiBuilder b, int l, PsiBuilder.Marker outerMarker, IElementType perlTokenType, IElementType blockTokenType) {
    PsiBuilder.Marker perlMarker = b.mark();
    while (!b.eof() && !isEndTagAhead(b, l)) {
        b.advanceLexer();
    }
    boolean recoverBlock = true;
    if (isEndTagAhead(b, l)) {
        perlMarker.collapse(perlTokenType);
        perlMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
    } else {
        perlMarker.drop();
    }
    if (TemplateToolkitParser.element(b, l)) {
        LighterASTNode latestDoneMarker = b.getLatestDoneMarker();
        if (latestDoneMarker != null && latestDoneMarker.getTokenType() == END_DIRECTIVE) {
            outerMarker.done(blockTokenType);
            recoverBlock = false;
        }
    }
    if (recoverBlock) {
        while (!b.eof() || b.getTokenType() == TT2_OUTLINE_TAG || b.getTokenType() == TT2_OPEN_TAG) {
            b.advanceLexer();
        }
        outerMarker.done(blockTokenType);
        outerMarker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, WhitespacesBinders.GREEDY_RIGHT_BINDER);
        outerMarker.precede().error(PerlBundle.message("ttk2.error.unclosed.perl.block"));
    }
    return true;
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) 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