Search in sources :

Example 1 with AOperatorExpression

use of de.be4.classicalb.core.parser.node.AOperatorExpression in project probparsers by bendisposto.

the class RulesMachineChecker method checkStringFormatOperator.

private void checkStringFormatOperator(AOperatorExpression node, final LinkedList<PExpression> parameters) {
    PExpression firstParam = parameters.get(0);
    Integer count = countPlaceHoldersInExpression(firstParam);
    if (count != null && count != parameters.size() - 1) {
        this.errorList.add(new CheckException("The number of arguments (" + (parameters.size() - 1) + ") does not match the number of placeholders (" + count + ") in the string.", node));
    }
    LinkedList<PExpression> identifiers = node.getIdentifiers();
    for (PExpression pExpression : identifiers) {
        pExpression.apply(this);
    }
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 2 with AOperatorExpression

use of de.be4.classicalb.core.parser.node.AOperatorExpression in project probparsers by bendisposto.

the class RulesTransformation method translateGetRuleCounterExamplesOperator.

private void translateGetRuleCounterExamplesOperator(AOperatorExpression node) {
    final PExpression pExpression = node.getIdentifiers().get(0);
    final AIdentifierExpression id = (AIdentifierExpression) pExpression;
    final String ruleName = id.getIdentifier().get(0).getText();
    final AbstractOperation operation = allOperations.get(ruleName);
    if (operation == null || !(operation instanceof RuleOperation)) {
        errorList.add(new CheckException(String.format("'%s' does not match any rule visible to this machine.", ruleName), node));
        return;
    }
    final RuleOperation rule = (RuleOperation) operation;
    final String name = id.getIdentifier().get(0).getText() + RULE_COUNTER_EXAMPLE_VARIABLE_SUFFIX;
    if (node.getIdentifiers().size() == 1) {
        final AIdentifierExpression ctVariable = createIdentifier(name, pExpression);
        final ARangeExpression range = createPositinedNode(new ARangeExpression(ctVariable), node);
        node.replaceBy(range);
    } else {
        PExpression funcCall = getSetOfErrorMessagesByErrorType(name, node.getIdentifiers().get(1), rule.getNumberOfErrorTypes());
        node.replaceBy(funcCall);
    }
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException)

Example 3 with AOperatorExpression

use of de.be4.classicalb.core.parser.node.AOperatorExpression in project probparsers by bendisposto.

the class RulesLanguageExceptionTest method testUnkownExpressionOperatorException.

@Test(expected = AssertionError.class)
public void testUnkownExpressionOperatorException() throws Exception {
    AOperatorExpression operator = new AOperatorExpression(new TKwExpressionOperator("foo"), new ArrayList<PExpression>());
    RulesMachineChecker rulesMachineVisitor = new RulesMachineChecker(null, null, null, null);
    operator.apply(rulesMachineVisitor);
}
Also used : AOperatorExpression(de.be4.classicalb.core.parser.node.AOperatorExpression) TKwExpressionOperator(de.be4.classicalb.core.parser.node.TKwExpressionOperator) PExpression(de.be4.classicalb.core.parser.node.PExpression) Test(org.junit.Test)

Example 4 with AOperatorExpression

use of de.be4.classicalb.core.parser.node.AOperatorExpression in project probparsers by bendisposto.

the class RulesMachineChecker method checkGetRuleCounterExamplesOperator.

private void checkGetRuleCounterExamplesOperator(AOperatorExpression node, final LinkedList<PExpression> parameters) {
    // the grammar ensures at least one argument
    if (parameters.size() > 2) {
        this.errorList.add(new CheckException("Invalid number of arguments. Expected one or two arguments.", node));
    }
    PExpression pExpression = node.getIdentifiers().get(0);
    if (!(pExpression instanceof AIdentifierExpression)) {
        this.errorList.add(new CheckException("The first argument of GET_RULE_COUNTEREXAMPLES must be an identifier.", node));
        return;
    }
    this.referencedRuleOperations.add((AIdentifierExpression) pExpression);
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)3 PExpression (de.be4.classicalb.core.parser.node.PExpression)3 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)1 AOperatorExpression (de.be4.classicalb.core.parser.node.AOperatorExpression)1 TKwExpressionOperator (de.be4.classicalb.core.parser.node.TKwExpressionOperator)1 Test (org.junit.Test)1