Search in sources :

Example 11 with PsiBuilder

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

the class MasqueradingPsiBuilderAdapter method synchronizePositions.

/**
   * @param exact if true then positions should be equal;
   *              else delegate should be behind, not including exactly all foreign (skipped) or whitespace tokens
   */
private void synchronizePositions(boolean exact) {
    final PsiBuilder delegate = getDelegate();
    if (myLexPosition >= myShrunkSequence.size() || delegate.eof()) {
        myLexPosition = myShrunkSequence.size();
        while (!delegate.eof()) {
            delegate.advanceLexer();
        }
        return;
    }
    if (delegate.getCurrentOffset() > myShrunkSequence.get(myLexPosition).realStart) {
        LOG.error("delegate is ahead of my builder!");
        return;
    }
    final int keepUpPosition = getKeepUpPosition(exact);
    while (!delegate.eof()) {
        final int delegatePosition = delegate.getCurrentOffset();
        if (delegatePosition < keepUpPosition) {
            delegate.advanceLexer();
        } else {
            break;
        }
    }
}
Also used : PsiBuilder(com.intellij.lang.PsiBuilder)

Example 12 with PsiBuilder

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

the class RegExpParser method parseBranch.

/**
   * BRANCH  ::= ATOM BRANCH | ""
   */
private boolean parseBranch(PsiBuilder builder) {
    final PsiBuilder.Marker marker = builder.mark();
    if (!parseAtom(builder)) {
        final IElementType token = builder.getTokenType();
        if (token == RegExpTT.GROUP_END || token == RegExpTT.UNION || token == null) {
            // empty branches are allowed
            marker.done(RegExpElementTypes.BRANCH);
            return true;
        }
        marker.drop();
        return false;
    }
    //noinspection StatementWithEmptyBody
    while (parseAtom(builder)) {
    }
    marker.done(RegExpElementTypes.BRANCH);
    return true;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 13 with PsiBuilder

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

the class RegExpParser method parseCharacterRange.

private void parseCharacterRange(PsiBuilder builder) {
    final PsiBuilder.Marker rangeMarker = builder.mark();
    parseCharacter(builder);
    if (builder.getTokenType() == RegExpTT.MINUS) {
        final PsiBuilder.Marker minusMarker = builder.mark();
        builder.advanceLexer();
        final IElementType t = builder.getTokenType();
        if (RegExpTT.CHARACTERS.contains(t) || t == RegExpTT.NAMED_CHARACTER) {
            minusMarker.drop();
            parseCharacter(builder);
            rangeMarker.done(RegExpElementTypes.CHAR_RANGE);
        } else {
            if (t == RegExpTT.CLASS_END) {
                // [a-]
                rangeMarker.drop();
                minusMarker.done(RegExpElementTypes.CHAR);
            } else if (t == RegExpTT.CLASS_BEGIN) {
                // [a-[b]]\
                rangeMarker.drop();
                minusMarker.done(RegExpElementTypes.CHAR);
                parseClassdef(builder);
            } else {
                minusMarker.drop();
                builder.error("Illegal character range");
                rangeMarker.done(RegExpElementTypes.CHAR_RANGE);
            }
        }
    } else {
        rangeMarker.drop();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 14 with PsiBuilder

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

the class StandardHeaderParser method parse.

@Override
public void parse(@NotNull PsiBuilder builder) {
    PsiBuilder.Marker marker = builder.mark();
    while (!builder.eof() && !ManifestParser.HEADER_END_TOKENS.contains(builder.getTokenType())) {
        IElementType lastToken = builder.getTokenType();
        builder.advanceLexer();
        if (lastToken == ManifestTokenType.NEWLINE && builder.getTokenType() != ManifestTokenType.SIGNIFICANT_SPACE) {
            break;
        }
    }
    marker.done(ManifestElementType.HEADER_VALUE_PART);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 15 with PsiBuilder

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

the class ManifestParser method parseHeader.

private void parseHeader(PsiBuilder builder) {
    PsiBuilder.Marker header = builder.mark();
    String headerName = builder.getTokenText();
    assert headerName != null : "[" + builder.getOriginalText() + "]@" + builder.getCurrentOffset();
    builder.advanceLexer();
    if (builder.getTokenType() == ManifestTokenType.COLON) {
        builder.advanceLexer();
        if (!expect(builder, ManifestTokenType.SIGNIFICANT_SPACE)) {
            builder.error(ManifestBundle.message("manifest.whitespace.expected"));
        }
        HeaderParser headerParser = notNull(myRepository.getHeaderParser(headerName), StandardHeaderParser.INSTANCE);
        headerParser.parse(builder);
    } else {
        PsiBuilder.Marker marker = builder.mark();
        consumeHeaderValue(builder);
        marker.error(ManifestBundle.message("manifest.colon.expected"));
    }
    header.done(ManifestElementType.HEADER);
}
Also used : StandardHeaderParser(org.jetbrains.lang.manifest.header.impl.StandardHeaderParser) HeaderParser(org.jetbrains.lang.manifest.header.HeaderParser) 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