Search in sources :

Example 41 with PsiBuilder

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

the class ArgumentList method argumentLabelStartCheck.

/**
   * Checks for argument label. In case when it is so, a caret will not be restored at
   * initial position
   *
   * @param builder
   * @return pair of two booleans, first value indicates that label was parsed, second value indicates that argument was parsed.
   * If first value is {@code true} then second is always {@code null}.
   */
public static Pair<Boolean, Boolean> argumentLabelStartCheck(PsiBuilder builder, GroovyParser parser) {
    PsiBuilder.Marker marker = builder.mark();
    if (ParserUtils.lookAhead(builder, GroovyTokenTypes.mSTAR, GroovyTokenTypes.mCOLON)) {
        builder.advanceLexer();
        marker.done(GroovyElementTypes.ARGUMENT_LABEL);
        return Pair.create(true, null);
    }
    final IElementType type = builder.getTokenType();
    if (ParserUtils.lookAhead(builder, GroovyTokenTypes.mIDENT, GroovyTokenTypes.mCOLON) || TokenSets.KEYWORDS.contains(type) || GroovyTokenTypes.mSTRING_LITERAL.equals(type) || GroovyTokenTypes.mGSTRING_LITERAL.equals(type)) {
        builder.advanceLexer();
        if (GroovyTokenTypes.mCOLON.equals(builder.getTokenType())) {
            marker.done(GroovyElementTypes.ARGUMENT_LABEL);
            return Pair.create(true, null);
        } else {
            marker.rollbackTo();
            return Pair.create(false, false);
        }
    }
    if (GroovyTokenTypes.mGSTRING_BEGIN.equals(type) || GroovyTokenTypes.mREGEX_BEGIN.equals(type) || GroovyTokenTypes.mDOLLAR_SLASH_REGEX_BEGIN.equals(type) || TokenSets.NUMBERS.contains(type) || GroovyTokenTypes.mLBRACK.equals(type) || GroovyTokenTypes.mLPAREN.equals(type) || GroovyTokenTypes.mLCURLY.equals(type)) {
        PsiBuilder.Marker label = builder.mark();
        if (AssignmentExpression.parse(builder, parser)) {
            if (GroovyTokenTypes.mCOLON.equals(builder.getTokenType())) {
                label.done(GroovyElementTypes.ARGUMENT_LABEL);
                ParserUtils.getToken(builder, GroovyTokenTypes.mCOLON, GroovyBundle.message("colon.expected"));
                if (AssignmentExpression.parse(builder, parser)) {
                    marker.done(GroovyElementTypes.NAMED_ARGUMENT);
                } else {
                    builder.error(GroovyBundle.message("expression.expected"));
                    marker.drop();
                }
            } else {
                label.drop();
                marker.drop();
            }
            return Pair.create(false, true);
        } else {
            label.drop();
            marker.rollbackTo();
        }
    } else {
        marker.drop();
    }
    return Pair.create(false, false);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 42 with PsiBuilder

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

the class GroovyDocTagValueTokenType method parseImpl.

private ASTNode parseImpl(ASTNode chameleon) {
    final PsiElement parentElement = chameleon.getTreeParent().getPsi();
    final Project project = parentElement.getProject();
    final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new GroovyLexer(), getLanguage(), chameleon.getText());
    PsiBuilder.Marker rootMarker = builder.mark();
    if (BUILT_IN_TYPES.contains(chameleon.getText())) {
        builder.advanceLexer();
    } else {
        ReferenceElement.parse(builder, false, false, false, false, false);
        while (!builder.eof()) {
            builder.advanceLexer();
        }
    }
    rootMarker.done(this);
    return builder.getTreeBuilt().getFirstChildNode();
}
Also used : Project(com.intellij.openapi.project.Project) GroovyLexer(org.jetbrains.plugins.groovy.lang.lexer.GroovyLexer) PsiBuilder(com.intellij.lang.PsiBuilder) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 43 with PsiBuilder

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

the class GroovyDocParsing method parseSeeOrLinkTagReference.

private boolean parseSeeOrLinkTagReference(PsiBuilder builder) {
    IElementType type = builder.getTokenType();
    if (!REFERENCE_BEGIN.contains(type))
        return false;
    PsiBuilder.Marker marker = builder.mark();
    if (GroovyDocTokenTypes.mGDOC_TAG_VALUE_TOKEN == type) {
        builder.advanceLexer();
    }
    if (GroovyDocTokenTypes.mGDOC_TAG_VALUE_SHARP_TOKEN == builder.getTokenType()) {
        builder.advanceLexer();
        RESULT result = parseFieldOrMethod(builder);
        if (result == RESULT.ERROR) {
            marker.drop();
        } else if (result == RESULT.METHOD) {
            marker.done(GroovyDocElementTypes.GDOC_METHOD_REF);
        } else {
            marker.done(GroovyDocElementTypes.GDOC_FIELD_REF);
        }
        return true;
    }
    marker.drop();
    return true;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 44 with PsiBuilder

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

the class PathExpression method pathElementParse.

@NotNull
private static Result pathElementParse(@NotNull PsiBuilder builder, @NotNull PsiBuilder.Marker marker, @NotNull GroovyParser parser, @NotNull Result result) {
    // Property reference
    if (isQualificationDot(builder)) {
        if (ParserUtils.lookAhead(builder, GroovyTokenTypes.mNLS, GroovyTokenTypes.mDOT)) {
            ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
        }
        ParserUtils.getToken(builder, DOTS);
        ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
        TypeArguments.parseTypeArguments(builder, true);
        GroovyElementType res = namePartParse(builder, parser);
        if (res != GroovyElementTypes.WRONGWAY) {
            PsiBuilder.Marker newMarker = marker.precede();
            marker.done(res);
            return parseAfterReference(builder, parser, newMarker);
        } else {
            builder.error(GroovyBundle.message("path.selector.expected"));
            marker.drop();
            return result;
        }
    } else if (checkForLParenth(builder)) {
        PrimaryExpression.methodCallArgsParse(builder, parser);
        return parseAfterArguments(builder, marker, parser);
    } else if (checkForLCurly(builder)) {
        ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
        appendedBlockParse(builder, parser);
        return parseAfterArguments(builder, marker, parser);
    } else if (checkForArrayAccess(builder)) {
        indexPropertyArgsParse(builder, parser);
        PsiBuilder.Marker newMarker = marker.precede();
        marker.done(GroovyElementTypes.PATH_INDEX_PROPERTY);
        return parseAfterReference(builder, parser, newMarker);
    } else {
        marker.drop();
        return result;
    }
}
Also used : GroovyElementType(org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType) PsiBuilder(com.intellij.lang.PsiBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with PsiBuilder

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

the class ShiftExpression method subParse.

private static void subParse(PsiBuilder builder, PsiBuilder.Marker marker, GroovyElementType shiftOrRange, GroovyParser parser) {
    ParserUtils.getToken(builder, RANGES);
    ParserUtils.getToken(builder, GroovyTokenTypes.mNLS);
    if (!BinaryExpression.ADDITIVE.parseBinary(builder, parser)) {
        builder.error(GroovyBundle.message("expression.expected"));
    }
    PsiBuilder.Marker newMarker = marker.precede();
    marker.done(shiftOrRange);
    GroovyElementType newShiftOrRange = isRangeOrShift(builder);
    if (RANGES.contains(builder.getTokenType()) || getCompositeSign(builder)) {
        subParse(builder, newMarker, newShiftOrRange, parser);
    } else {
        newMarker.drop();
    }
}
Also used : GroovyElementType(org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Aggregations

PsiBuilder (com.intellij.lang.PsiBuilder)104 IElementType (com.intellij.psi.tree.IElementType)78 Nullable (org.jetbrains.annotations.Nullable)18 NotNull (org.jetbrains.annotations.NotNull)16 Project (com.intellij.openapi.project.Project)5 GroovyElementType (org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType)5 Language (com.intellij.lang.Language)3 ASTNode (com.intellij.lang.ASTNode)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 HtmlParsing (com.intellij.lang.html.HtmlParsing)1 Lexer (com.intellij.lexer.Lexer)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 SmartList (com.intellij.util.SmartList)1 Stack (com.intellij.util.containers.Stack)1