Search in sources :

Example 1 with AOperatorPredicate

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

the class RulesMachineChecker method checkFailedRuleErrorTypeOperator.

private void checkFailedRuleErrorTypeOperator(AOperatorPredicate node, final List<PExpression> arguments) {
    if (arguments.size() != 2) {
        this.errorList.add(new CheckException("The FAILED_RULE_ERROR_TYPE predicate operator expects exactly two arguments.", node));
        return;
    }
    PExpression pExpression = node.getIdentifiers().get(0);
    if (!(pExpression instanceof AIdentifierExpression)) {
        this.errorList.add(new CheckException("The first argument of FAILED_RULE_ERROR_TYPE must be an identifier.", node));
        return;
    }
    PExpression secondArg = node.getIdentifiers().get(1);
    if (!(secondArg instanceof AIntegerExpression)) {
        this.errorList.add(new CheckException("The second argument of FAILED_RULE_ERROR_TYPE must be an integer literal.", node));
        return;
    }
    this.referencedRuleOperations.add((AIdentifierExpression) arguments.get(0));
    return;
}
Also used : AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 2 with AOperatorPredicate

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

the class RulesTransformation method outAOperatorPredicate.

@Override
public void outAOperatorPredicate(AOperatorPredicate node) {
    // currently all operator handle rule names
    final List<PExpression> arguments = new ArrayList<>(node.getIdentifiers());
    final String operatorName = node.getName().getText();
    final AIdentifierExpression ruleIdentifier = (AIdentifierExpression) arguments.get(0);
    final String ruleName = ruleIdentifier.getIdentifier().get(0).getText();
    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;
    switch(operatorName) {
        case RulesGrammar.SUCCEEDED_RULE:
            replacePredicateOperator(node, arguments, RULE_SUCCESS);
            return;
        case RulesGrammar.SUCCEEDED_RULE_ERROR_TYPE:
            replaceSucceededRuleErrorTypeOperator(node, ruleName, rule);
            return;
        case RulesGrammar.FAILED_RULE:
            replacePredicateOperator(node, arguments, RULE_FAIL);
            return;
        case RulesGrammar.FAILED_RULE_ALL_ERROR_TYPES:
            replaceFailedRuleAllErrorTypesOperator(node, rule);
            return;
        case RulesGrammar.FAILED_RULE_ERROR_TYPE:
            replaceFailedRuleErrorTypeOperator(node, rule);
            return;
        case RulesGrammar.NOT_CHECKED_RULE:
            replacePredicateOperator(node, arguments, RULE_NOT_CHECKED);
            return;
        case RulesGrammar.DISABLED_RULE:
            replacePredicateOperator(node, arguments, RULE_DISABLED);
            return;
        default:
            throw new AssertionError("should not happen: " + operatorName);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList)

Example 3 with AOperatorPredicate

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

the class RulesLanguageExceptionTest method testUnkownPredicateOperatorException.

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

Example 4 with AOperatorPredicate

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

the class RulesMachineChecker method checkSucceededRuleErrorTypeOperator.

private void checkSucceededRuleErrorTypeOperator(AOperatorPredicate node, final List<PExpression> arguments) {
    if (arguments.size() != 2) {
        this.errorList.add(new CheckException("The SUCCEEDED_RULE_ERROR_TYPE predicate operator expects exactly two arguments.", node));
        return;
    }
    PExpression pExpression = node.getIdentifiers().get(0);
    if (!(pExpression instanceof AIdentifierExpression)) {
        this.errorList.add(new CheckException("The first argument of SUCCEEDED_RULE_ERROR_TYPE must be an identifier.", node));
        return;
    }
    PExpression secondArg = node.getIdentifiers().get(1);
    if (!(secondArg instanceof AIntegerExpression)) {
        this.errorList.add(new CheckException("The second argument of SUCCEEDED_RULE_ERROR_TYPE must be an integer value.", node));
        return;
    }
    this.referencedRuleOperations.add((AIdentifierExpression) arguments.get(0));
    return;
}
Also used : AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) 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)2 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)2 AOperatorPredicate (de.be4.classicalb.core.parser.node.AOperatorPredicate)1 TKwPredicateOperator (de.be4.classicalb.core.parser.node.TKwPredicateOperator)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1