Search in sources :

Example 1 with PerlBuilder

use of com.perl5.lang.perl.parser.builder.PerlBuilder in project Perl5-IDEA by Camelcade.

the class PerlParserImpl method parseStatementSemi.

public boolean parseStatementSemi(PsiBuilder b, int l) {
    IElementType tokenType = b.getTokenType();
    if (((PerlBuilder) b).getPerlParser().getConsumableSemicolonTokens().contains(tokenType)) {
        b.advanceLexer();
        return true;
    } else if (((PerlBuilder) b).getPerlParser().getUnconsumableSemicolonTokens().contains(tokenType)) {
        return true;
    } else if (// eof
    b.eof()) {
        return true;
    }
    b.mark().error("Semicolon expected");
    return true;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PerlBuilder(com.perl5.lang.perl.parser.builder.PerlBuilder)

Example 2 with PerlBuilder

use of com.perl5.lang.perl.parser.builder.PerlBuilder in project Perl5-IDEA by Camelcade.

the class PerlSwitchParserExtensionImpl method parseStatement.

@Override
public boolean parseStatement(PerlBuilder b, int l) {
    IElementType tokenType = b.getTokenType();
    if (tokenType == RESERVED_SWITCH) {
        PerlBuilder.Marker m = b.mark();
        if (parseSwitchStatement(b, l)) {
            m.done(SWITCH_COMPOUND);
            return true;
        }
        m.rollbackTo();
    } else if (tokenType == RESERVED_CASE) {
        return parseCaseSequence(b, l);
    }
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PerlBuilder(com.perl5.lang.perl.parser.builder.PerlBuilder)

Example 3 with PerlBuilder

use of com.perl5.lang.perl.parser.builder.PerlBuilder in project Perl5-IDEA by Camelcade.

the class PerlParserUtil method parseArrowSmart.

/**
 * Smart parser for ->, makes }->[ optional
 *
 * @param b PerlBuilder
 * @param l parsing level
 * @return parsing result
 */
public static boolean parseArrowSmart(PsiBuilder b, @SuppressWarnings("unused") int l) {
    IElementType tokenType = b.getTokenType();
    if (b.getTokenType() == OPERATOR_DEREFERENCE) {
        return consumeToken(b, OPERATOR_DEREFERENCE);
    } else {
        assert b instanceof PerlBuilder;
        PerlTokenData prevToken = ((PerlBuilder) b).lookupToken(-1);
        IElementType prevTokenType = prevToken == null ? null : prevToken.getTokenType();
        // optional }->[ or ]->{
        if ((prevTokenType == RIGHT_BRACE || prevTokenType == RIGHT_BRACKET) && (tokenType == LEFT_BRACE || tokenType == LEFT_BRACKET || tokenType == LEFT_PAREN)) {
            return true;
        }
    }
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PerlBuilder(com.perl5.lang.perl.parser.builder.PerlBuilder)

Example 4 with PerlBuilder

use of com.perl5.lang.perl.parser.builder.PerlBuilder in project Perl5-IDEA by Camelcade.

the class PerlParserUtil method parseUseParameters.

/**
 * Parses use parameters with package processor if it's possible. If not, uses default parsing logic.
 */
public static boolean parseUseParameters(@NotNull PsiBuilder b, int l, @NotNull Parser defaultParser) {
    if (b.getTokenType() == PACKAGE) {
        String packageName = b.getTokenText();
        if (StringUtil.isEmpty(packageName)) {
            return false;
        }
        PerlPackageProcessor packageProcessor = PerlPackageProcessorEP.EP.findSingle(packageName);
        if (packageProcessor != null) {
            assert b instanceof PerlBuilder;
            PsiBuilder.Marker m = b.mark();
            if (packageProcessor.parseUseParameters((PerlBuilder) b, l)) {
                m.drop();
                return true;
            }
            m.rollbackTo();
        }
    }
    return defaultParser.parse(b, l);
}
Also used : PerlPackageProcessor(com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor) PerlBuilder(com.perl5.lang.perl.parser.builder.PerlBuilder) PsiBuilder(com.intellij.lang.PsiBuilder)

Example 5 with PerlBuilder

use of com.perl5.lang.perl.parser.builder.PerlBuilder in project Perl5-IDEA by Camelcade.

the class MooseParserExtension method parseDefault.

private static boolean parseDefault(PerlBuilder b, int l) {
    PerlBuilder.Marker m = b.mark();
    IElementType tokenType = b.getTokenType();
    if (PARSER_TOKEN_SET.contains(tokenType)) {
        b.advanceLexer();
        if (PerlParserImpl.expr(b, l, -1)) {
            PerlParserUtil.parseStatementModifier(b, l);
            m.done(RESERVED_TO_STATEMENT_MAP.get(tokenType));
            return true;
        }
    }
    m.rollbackTo();
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PerlBuilder(com.perl5.lang.perl.parser.builder.PerlBuilder)

Aggregations

PerlBuilder (com.perl5.lang.perl.parser.builder.PerlBuilder)5 IElementType (com.intellij.psi.tree.IElementType)4 PsiBuilder (com.intellij.lang.PsiBuilder)1 PerlPackageProcessor (com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor)1