Search in sources :

Example 6 with PsiBuilder

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

the class StatementParsing method parseImportElements.

private void parseImportElements(IElementType elementType, boolean is_module_import, boolean in_parens, final boolean from_future) {
    PsiBuilder builder = myContext.getBuilder();
    while (true) {
        final PsiBuilder.Marker asMarker = builder.mark();
        if (is_module_import) {
            // import _
            if (!parseDottedNameAsAware(true, false)) {
                asMarker.drop();
                break;
            }
        } else {
            // from X import _
            String token_text = parseIdentifier(getReferenceType());
            if (from_future) {
                // TODO: mark all known future feature names
                if (TOK_WITH_STATEMENT.equals(token_text)) {
                    myFutureFlags.add(FUTURE.WITH_STATEMENT);
                } else if (TOK_NESTED_SCOPES.equals(token_text)) {
                    myFutureFlags.add(FUTURE.NESTED_SCOPES);
                } else if (TOK_PRINT_FUNCTION.equals(token_text)) {
                    myFutureFlags.add(FUTURE.PRINT_FUNCTION);
                }
            }
        }
        // possible 'as' comes as an ident; reparse it as keyword if found
        setExpectAsKeyword(true);
        if (builder.getTokenType() == PyTokenTypes.AS_KEYWORD) {
            builder.advanceLexer();
            setExpectAsKeyword(false);
            parseIdentifier(PyElementTypes.TARGET_EXPRESSION);
        }
        asMarker.done(elementType);
        setExpectAsKeyword(false);
        if (builder.getTokenType() == PyTokenTypes.COMMA) {
            builder.advanceLexer();
            if (in_parens && builder.getTokenType() == PyTokenTypes.RPAR) {
                break;
            }
        } else {
            break;
        }
    }
}
Also used : PsiBuilder(com.intellij.lang.PsiBuilder)

Example 7 with PsiBuilder

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

the class RestParser method parseMarkup.

private static void parseMarkup(PsiBuilder builder) {
    PsiBuilder.Marker marker = builder.mark();
    IElementType type = builder.getTokenType();
    if (type == RestTokenTypes.SUBSTITUTION) {
        builder.advanceLexer();
        marker.done(RestElementTypes.REFERENCE_TARGET);
        builder.advanceLexer();
        marker = builder.mark();
        type = builder.getTokenType();
    }
    if (type == RestTokenTypes.DIRECTIVE) {
        gotoNextWhiteSpaces(builder);
        if (builder.getTokenType() != RestTokenTypes.WHITESPACE) {
            builder.advanceLexer();
            marker.done(RestElementTypes.DIRECTIVE_BLOCK);
            return;
        }
        skipBlankLines(builder);
        if (builder.getTokenType() != RestTokenTypes.WHITESPACE || "\n".equals(builder.getTokenText())) {
            marker.done(RestElementTypes.DIRECTIVE_BLOCK);
            return;
        }
        String white = builder.getTokenText();
        parseDirective(builder, white, marker);
    } else if (type == RestTokenTypes.FOOTNOTE || type == RestTokenTypes.CITATION || type == RestTokenTypes.HYPERLINK || type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
        builder.advanceLexer();
        marker.done(RestElementTypes.REFERENCE_TARGET);
    } else {
        builder.advanceLexer();
        marker.drop();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 8 with PsiBuilder

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

the class RestParser method parse.

@NotNull
public ASTNode parse(IElementType root, PsiBuilder builder) {
    final PsiBuilder.Marker rootMarker = builder.mark();
    while (!builder.eof()) {
        IElementType type = builder.getTokenType();
        if (type == RestTokenTypes.EXPLISIT_MARKUP_START) {
            builder.advanceLexer();
            parseMarkup(builder);
        } else if (type == RestTokenTypes.REFERENCE_NAME || type == RestTokenTypes.SUBSTITUTION) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestTokenTypes.REFERENCE_NAME);
        } else if (type == RestTokenTypes.TITLE) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestTokenTypes.TITLE);
        } else if (type == RestTokenTypes.FIELD) {
            parseFieldList(builder);
        } else if (type == RestTokenTypes.INLINE_LINE) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestElementTypes.INLINE_BLOCK);
        } else if (type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
            PsiBuilder.Marker marker = builder.mark();
            builder.advanceLexer();
            marker.done(RestElementTypes.REFERENCE_TARGET);
        } else if (type == RestTokenTypes.LINE) {
            parseLineText(builder, type);
        } else
            builder.advanceLexer();
    }
    rootMarker.done(root);
    return builder.getTreeBuilt();
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PsiBuilder

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

the class XPath2Parser method parseSequenceType.

private boolean parseSequenceType(PsiBuilder builder) {
    PsiBuilder.Marker mark = builder.mark();
    final IElementType type = parseItemOrEmptySequenceType(builder);
    if (type != null) {
        if (type == XPath2TokenTypes.ITEM) {
            if (XPath2TokenTypes.OCCURRENCE_OPS.contains(builder.getTokenType())) {
                makeToken(builder);
            }
        }
        mark.done(XPath2ElementTypes.SEQUENCE_TYPE);
        return true;
    } else if (parseNodeType(builder) || parseQName(builder)) {
        if (builder.getTokenType() == XPathTokenTypes.MULT) {
            builder.remapCurrentToken(XPathTokenTypes.STAR);
        }
        if (XPath2TokenTypes.OCCURRENCE_OPS.contains(builder.getTokenType())) {
            makeToken(builder);
        }
        mark.done(XPath2ElementTypes.SEQUENCE_TYPE);
        return true;
    }
    mark.drop();
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 10 with PsiBuilder

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

the class XPathParser method parseAxisSpecifier.

/**
   * [5]    AxisSpecifier    ::=    AxisName '::' | AbbreviatedAxisSpecifier
   * <p/>
   * [13]   AbbreviatedAxisSpecifier    ::=    '@'?
   */
private boolean parseAxisSpecifier(PsiBuilder builder) {
    final PsiBuilder.Marker marker = builder.mark();
    final IElementType tokenType = builder.getTokenType();
    if (XPathTokenTypes.AXIS.contains(tokenType)) {
        builder.advanceLexer();
        checkMatches(builder, XPathTokenTypes.COLCOL, ":: expected");
    } else {
        if (tokenType == XPathTokenTypes.AT) {
            builder.advanceLexer();
        } else if (tokenType == XPathTokenTypes.DOT || tokenType == XPathTokenTypes.DOTDOT) {
            marker.drop();
            return false;
        } else {
            final PsiBuilder.Marker m = builder.mark();
            final boolean b = parseNodeTest(builder);
            m.rollbackTo();
            if (!b) {
                marker.drop();
                return false;
            }
        }
    }
    marker.done(XPathElementTypes.AXIS_SPECIFIER);
    return true;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) 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