Search in sources :

Example 1 with GroovyParserRuleContext

use of org.apache.groovy.parser.antlr4.GroovyParser.GroovyParserRuleContext in project groovy by apache.

the class AstBuilder method visitContinueStatement.

@Override
public ContinueStatement visitContinueStatement(final ContinueStatementContext ctx) {
    if (visitingLoopStatementCount == 0) {
        throw createParsingFailedException("continue statement is only allowed inside loops", ctx);
    }
    GroovyParserRuleContext gprc = switchExpressionRuleContextStack.peek();
    if (gprc instanceof SwitchExpressionContext) {
        throw createParsingFailedException("switch expression does not support `continue`", ctx);
    }
    String label = asBoolean(ctx.identifier()) ? this.visitIdentifier(ctx.identifier()) : null;
    return configureAST(new ContinueStatement(label), ctx);
}
Also used : GroovyParserRuleContext(org.apache.groovy.parser.antlr4.GroovyParser.GroovyParserRuleContext) SwitchExpressionContext(org.apache.groovy.parser.antlr4.GroovyLangParser.SwitchExpressionContext) ContinueStatement(org.codehaus.groovy.ast.stmt.ContinueStatement)

Example 2 with GroovyParserRuleContext

use of org.apache.groovy.parser.antlr4.GroovyParser.GroovyParserRuleContext in project groovy by apache.

the class AstBuilder method visitBreakStatement.

@Override
public BreakStatement visitBreakStatement(final BreakStatementContext ctx) {
    if (0 == visitingLoopStatementCount && 0 == visitingSwitchStatementCount) {
        throw createParsingFailedException("break statement is only allowed inside loops or switches", ctx);
    }
    GroovyParserRuleContext gprc = switchExpressionRuleContextStack.peek();
    if (gprc instanceof SwitchExpressionContext) {
        throw createParsingFailedException("switch expression does not support `break`", ctx);
    }
    String label = asBoolean(ctx.identifier()) ? this.visitIdentifier(ctx.identifier()) : null;
    return configureAST(new BreakStatement(label), ctx);
}
Also used : BreakStatement(org.codehaus.groovy.ast.stmt.BreakStatement) GroovyParserRuleContext(org.apache.groovy.parser.antlr4.GroovyParser.GroovyParserRuleContext) SwitchExpressionContext(org.apache.groovy.parser.antlr4.GroovyLangParser.SwitchExpressionContext)

Aggregations

SwitchExpressionContext (org.apache.groovy.parser.antlr4.GroovyLangParser.SwitchExpressionContext)2 GroovyParserRuleContext (org.apache.groovy.parser.antlr4.GroovyParser.GroovyParserRuleContext)2 BreakStatement (org.codehaus.groovy.ast.stmt.BreakStatement)1 ContinueStatement (org.codehaus.groovy.ast.stmt.ContinueStatement)1