Search in sources :

Example 46 with LighterASTNode

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

the class TemplateToolkitParserUtil method parseDirective.

public static boolean parseDirective(PsiBuilder b, int l) {
    IElementType tokenType = b.getTokenType();
    boolean r = false;
    LighterASTNode latestDoneMarker = null;
    PsiBuilder.Marker outerMarker = b.mark();
    boolean isAfterSemi = tokenType != TT2_OPEN_TAG && tokenType != TT2_OUTLINE_TAG && isAfterSemi(b);
    if (isAfterSemi || tokenType == TT2_OPEN_TAG) {
        if (!isAfterSemi) {
            b.advanceLexer();
        }
        if (TemplateToolkitParser.directive(b, l)) {
            latestDoneMarker = b.getLatestDoneMarker();
        }
        if (latestDoneMarker == null || latestDoneMarker.getTokenType() != MACRO_DIRECTIVE) {
            PsiBuilder.Marker m = null;
            while (!b.eof()) {
                if (isBlockEndMarker(b)) {
                    break;
                }
                if (m == null) {
                    m = b.mark();
                }
                b.advanceLexer();
            }
            if (m != null) {
                m.error(PerlBundle.message("ttk2.unexpected.token"));
            }
            consumeToken(b, TT2_SEMI);
            consumeToken(b, TT2_CLOSE_TAG);
        }
        r = true;
    } else if (tokenType == TT2_OUTLINE_TAG) {
        b.advanceLexer();
        if (TemplateToolkitParser.directive(b, l)) {
            latestDoneMarker = b.getLatestDoneMarker();
        }
        if (latestDoneMarker == null || latestDoneMarker.getTokenType() != MACRO_DIRECTIVE) {
            PsiBuilder.Marker m = null;
            while (!b.eof()) {
                if (b.getTokenType() == TT2_HARD_NEWLINE) {
                    break;
                }
                if (m == null) {
                    m = b.mark();
                }
                b.advanceLexer();
            }
            if (m != null) {
                m.error("ttk2.unexpected.token");
            }
            // parseHardNewLine(b, l); // fixme this breaks lastMarker mechanism, need to figure out something
            if (b.getTokenType() == TT2_HARD_NEWLINE) {
                // this is irreversable change, so not sure it's a good idea
                b.remapCurrentToken(TokenType.WHITE_SPACE);
                b.advanceLexer();
            }
        }
        r = true;
    }
    processMarkers(b, l, latestDoneMarker, outerMarker);
    return r;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) LighterASTNode(com.intellij.lang.LighterASTNode) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 47 with LighterASTNode

use of com.intellij.lang.LighterASTNode in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoParserUtil method isBuiltin.

public static boolean isBuiltin(@NotNull PsiBuilder builder_, @SuppressWarnings("UnusedParameters") int level) {
    LighterASTNode marker = builder_.getLatestDoneMarker();
    if (marker == null)
        return false;
    String text = String.valueOf(builder_.getOriginalText().subSequence(marker.getStartOffset(), marker.getEndOffset())).trim();
    return "make".equals(text) || "new".equals(text);
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode)

Example 48 with LighterASTNode

use of com.intellij.lang.LighterASTNode in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoParserUtil method prevIsType.

public static boolean prevIsType(@NotNull PsiBuilder builder_, @SuppressWarnings("UnusedParameters") int level) {
    LighterASTNode marker = builder_.getLatestDoneMarker();
    IElementType type = marker != null ? marker.getTokenType() : null;
    return type == GoTypes.ARRAY_OR_SLICE_TYPE || type == GoTypes.MAP_TYPE || type == GoTypes.STRUCT_TYPE;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) LighterASTNode(com.intellij.lang.LighterASTNode)

Aggregations

LighterASTNode (com.intellij.lang.LighterASTNode)48 IElementType (com.intellij.psi.tree.IElementType)14 Nullable (org.jetbrains.annotations.Nullable)12 NotNull (org.jetbrains.annotations.NotNull)11 PsiBuilder (com.intellij.lang.PsiBuilder)6 LighterAST (com.intellij.lang.LighterAST)4 ValueConstraint (com.intellij.codeInspection.dataFlow.MethodContract.ValueConstraint)3 TypeInfo (com.intellij.psi.impl.cache.TypeInfo)3 SmartList (com.intellij.util.SmartList)3 JavaTokenType (com.intellij.psi.JavaTokenType)2 JavaLightTreeUtil (com.intellij.psi.impl.source.JavaLightTreeUtil)2 JavaLightTreeUtil.findExpressionChild (com.intellij.psi.impl.source.JavaLightTreeUtil.findExpressionChild)2 JavaLightTreeUtil.getExpressionChildren (com.intellij.psi.impl.source.JavaLightTreeUtil.getExpressionChildren)2 ElementType (com.intellij.psi.impl.source.tree.ElementType)2 JavaElementType (com.intellij.psi.impl.source.tree.JavaElementType)2 LightTreeUtil.firstChildOfType (com.intellij.psi.impl.source.tree.LightTreeUtil.firstChildOfType)2 LightTreeUtil.getChildrenOfType (com.intellij.psi.impl.source.tree.LightTreeUtil.getChildrenOfType)2 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 DuplicatesProfile (com.intellij.dupLocator.DuplicatesProfile)1 DuplocatorState (com.intellij.dupLocator.DuplocatorState)1