Search in sources :

Example 1 with GroovyElementType

use of org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType 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 2 with GroovyElementType

use of org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType 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)

Example 3 with GroovyElementType

use of org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType in project intellij-community by JetBrains.

the class ShiftExpression method parse.

public static boolean parse(PsiBuilder builder, GroovyParser parser) {
    PsiBuilder.Marker marker = builder.mark();
    if (BinaryExpression.ADDITIVE.parseBinary(builder, parser)) {
        GroovyElementType shiftOrRange = isRangeOrShift(builder);
        if (!shiftOrRange.equals(GroovyElementTypes.WRONGWAY)) {
            if (ParserUtils.getToken(builder, RANGES) || getCompositeSign(builder)) {
                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);
                shiftOrRange = isRangeOrShift(builder);
                if (RANGES.contains(builder.getTokenType()) || getCompositeSign(builder)) {
                    subParse(builder, newMarker, shiftOrRange, parser);
                } else {
                    newMarker.drop();
                }
            } else {
                marker.drop();
            }
        } else {
            marker.drop();
        }
        return true;
    } else {
        marker.drop();
        return false;
    }
}
Also used : GroovyElementType(org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 4 with GroovyElementType

use of org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType in project intellij-community by JetBrains.

the class PrimaryExpression method parsePrimaryExpression.

public static IElementType parsePrimaryExpression(PsiBuilder builder, GroovyParser parser, boolean literalsAsRefExprs) {
    final IElementType tokenType = builder.getTokenType();
    if (TokenSets.BUILT_IN_TYPES.contains(tokenType)) {
        ParserUtils.eatElement(builder, GroovyElementTypes.BUILT_IN_TYPE_EXPRESSION);
        return GroovyElementTypes.BUILT_IN_TYPE_EXPRESSION;
    }
    if (GroovyTokenTypes.kNEW == tokenType) {
        PsiBuilder.Marker marker = builder.mark();
        final GroovyElementType type = newExprParse(builder, parser);
        marker.done(type);
        return type;
    }
    if (GroovyTokenTypes.mIDENT == tokenType || GroovyTokenTypes.kSUPER == tokenType || GroovyTokenTypes.kTHIS == tokenType || TokenSets.CODE_REFERENCE_ELEMENT_NAME_TOKENS.contains(tokenType) && PathExpression.isQualificationDotAhead(builder)) {
        return ParserUtils.eatElement(builder, GroovyElementTypes.REFERENCE_EXPRESSION);
    }
    if (GroovyTokenTypes.mGSTRING_BEGIN == tokenType) {
        final boolean result = CompoundStringExpression.parse(builder, parser, false, GroovyTokenTypes.mGSTRING_BEGIN, GroovyTokenTypes.mGSTRING_CONTENT, GroovyTokenTypes.mGSTRING_END, null, GroovyElementTypes.GSTRING, GroovyBundle.message("string.end.expected"));
        return result ? GroovyElementTypes.GSTRING : GroovyElementTypes.LITERAL;
    }
    if (GroovyTokenTypes.mREGEX_BEGIN == tokenType) {
        CompoundStringExpression.parse(builder, parser, false, GroovyTokenTypes.mREGEX_BEGIN, GroovyTokenTypes.mREGEX_CONTENT, GroovyTokenTypes.mREGEX_END, GroovyTokenTypes.mREGEX_LITERAL, GroovyElementTypes.REGEX, GroovyBundle.message("regex.end.expected"));
        return GroovyElementTypes.REGEX;
    }
    if (GroovyTokenTypes.mDOLLAR_SLASH_REGEX_BEGIN == tokenType) {
        CompoundStringExpression.parse(builder, parser, false, GroovyTokenTypes.mDOLLAR_SLASH_REGEX_BEGIN, GroovyTokenTypes.mDOLLAR_SLASH_REGEX_CONTENT, GroovyTokenTypes.mDOLLAR_SLASH_REGEX_END, GroovyTokenTypes.mDOLLAR_SLASH_REGEX_LITERAL, GroovyElementTypes.REGEX, GroovyBundle.message("dollar.slash.end.expected"));
        return GroovyElementTypes.REGEX;
    }
    if (GroovyTokenTypes.mLBRACK == tokenType) {
        return ListOrMapConstructorExpression.parse(builder, parser);
    }
    if (GroovyTokenTypes.mLPAREN == tokenType) {
        return parenthesizedExprParse(builder, parser);
    }
    if (GroovyTokenTypes.mLCURLY == tokenType) {
        return OpenOrClosableBlock.parseClosableBlock(builder, parser);
    }
    if (tokenType == GroovyTokenTypes.mSTRING_LITERAL || tokenType == GroovyTokenTypes.mGSTRING_LITERAL) {
        return ParserUtils.eatElement(builder, literalsAsRefExprs ? GroovyElementTypes.REFERENCE_EXPRESSION : GroovyElementTypes.LITERAL);
    }
    if (TokenSets.CONSTANTS.contains(tokenType)) {
        return ParserUtils.eatElement(builder, GroovyElementTypes.LITERAL);
    }
    return GroovyElementTypes.WRONGWAY;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GroovyElementType(org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 5 with GroovyElementType

use of org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType in project intellij-community by JetBrains.

the class BranchStatement method breakOrContinueParse.

/**
   * (BREAK | CONTINUE) ...
   *
   * @param builder
   * @return
   */
private static void breakOrContinueParse(PsiBuilder builder) {
    PsiBuilder.Marker marker = builder.mark();
    GroovyElementType result = GroovyTokenTypes.kBREAK.equals(builder.getTokenType()) ? GroovyElementTypes.BREAK_STATEMENT : GroovyElementTypes.CONTINUE_STATEMENT;
    builder.advanceLexer();
    ParserUtils.getToken(builder, GroovyTokenTypes.mIDENT);
    marker.done(result);
}
Also used : GroovyElementType(org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Aggregations

PsiBuilder (com.intellij.lang.PsiBuilder)5 GroovyElementType (org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType)5 IElementType (com.intellij.psi.tree.IElementType)1 NotNull (org.jetbrains.annotations.NotNull)1