Search in sources :

Example 46 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 47 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)

Example 48 with PsiBuilder

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

the class MarkdownLazyElementType method doParseContents.

@Override
protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi) {
    final Project project = psi.getProject();
    final Lexer lexer = new MarkdownLexerAdapter();
    final CharSequence chars = chameleon.getChars();
    final org.intellij.markdown.ast.ASTNode node = new MarkdownParser(MarkdownParserManager.FLAVOUR).parseInline(MarkdownElementType.markdownType(chameleon.getElementType()), chars, 0, chars.length());
    final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, lexer, getLanguage(), chars);
    assert builder.getCurrentOffset() == 0;
    new PsiBuilderFillingVisitor(builder).visitNode(node);
    assert builder.eof();
    return builder.getTreeBuilt().getFirstChildNode();
}
Also used : Project(com.intellij.openapi.project.Project) Lexer(com.intellij.lexer.Lexer) MarkdownLexerAdapter(org.intellij.plugins.markdown.lang.lexer.MarkdownLexerAdapter) PsiBuilder(com.intellij.lang.PsiBuilder) MarkdownParser(org.intellij.markdown.parser.MarkdownParser) PsiBuilderFillingVisitor(org.intellij.plugins.markdown.lang.parser.PsiBuilderFillingVisitor)

Example 49 with PsiBuilder

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

the class OsgiHeaderParser method parseClause.

private static boolean parseClause(PsiBuilder builder) {
    PsiBuilder.Marker clause = builder.mark();
    boolean result = true;
    while (!builder.eof()) {
        if (!parseSubClause(builder, false)) {
            result = false;
            break;
        }
        IElementType tokenType = builder.getTokenType();
        if (CLAUSE_END_TOKENS.contains(tokenType)) {
            break;
        } else if (tokenType == ManifestTokenType.SEMICOLON) {
            builder.advanceLexer();
        }
    }
    clause.done(OsgiManifestElementType.CLAUSE);
    return result;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 50 with PsiBuilder

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

the class DartGeneratedParserUtilBase method lazyParseableBlockImpl.

public static boolean lazyParseableBlockImpl(PsiBuilder builder, int level) {
    if (builder.getTokenType() != LBRACE)
        return false;
    final PsiBuilder.Marker marker = builder.mark();
    builder.advanceLexer();
    int braceCount = 1;
    while (true) {
        final IElementType tokenType = builder.getTokenType();
        if (tokenType == null) {
            break;
        }
        if (tokenType == LBRACE) {
            braceCount++;
        } else if (tokenType == RBRACE) {
            braceCount--;
        }
        builder.advanceLexer();
        if (braceCount == 0) {
            break;
        }
    }
    marker.collapse(LAZY_PARSEABLE_BLOCK);
    return true;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiBuilder(com.intellij.lang.PsiBuilder)

Aggregations

PsiBuilder (com.intellij.lang.PsiBuilder)124 IElementType (com.intellij.psi.tree.IElementType)90 Nullable (org.jetbrains.annotations.Nullable)18 NotNull (org.jetbrains.annotations.NotNull)16 Project (com.intellij.openapi.project.Project)7 LighterASTNode (com.intellij.lang.LighterASTNode)6 GroovyElementType (org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType)5 Language (com.intellij.lang.Language)3 ASTNode (com.intellij.lang.ASTNode)2 PsiElement (com.intellij.psi.PsiElement)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 PsiParser (com.intellij.lang.PsiParser)1 HtmlParsing (com.intellij.lang.html.HtmlParsing)1 Lexer (com.intellij.lexer.Lexer)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1