Search in sources :

Example 1 with APredicateAttributeOperationAttribute

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

the class RulesMachineChecker method checkOperationPredicateAttribute.

private void checkOperationPredicateAttribute(OccurredAttributes occurredAttributes, POperationAttribute pOperationAttribute) throws AssertionError {
    APredicateAttributeOperationAttribute attr = (APredicateAttributeOperationAttribute) pOperationAttribute;
    PPredicate predicate = attr.getPredicate();
    final String attrName = attr.getName().getText();
    occurredAttributes.add(attrName, pOperationAttribute);
    switch(attrName) {
        case RulesGrammar.ACTIVATION:
            if (currentOperation instanceof FunctionOperation) {
                errorList.add(new CheckException("ACTIVATION is not a valid attribute of a FUNCTION operation.", pOperationAttribute));
            } else {
                currentOperation.setActivationPredicate(predicate);
            }
            break;
        case RulesGrammar.PRECONDITION:
            if (currentOperation instanceof FunctionOperation) {
                FunctionOperation func = (FunctionOperation) currentOperation;
                func.setPreconditionPredicate(predicate);
            } else {
                errorList.add(new CheckException("PRECONDITION clause is not allowed for a RULE or COMPUTATION operation", pOperationAttribute));
            }
            break;
        case RulesGrammar.POSTCONDITION:
            if (currentOperation instanceof RuleOperation) {
                errorList.add(new CheckException("POSTCONDITION attribute is not allowed for a RULE operation", pOperationAttribute));
            } else {
                currentOperation.setPostcondition(predicate);
            }
            break;
        default:
            throw new AssertionError("Unexpected operation attribute: " + attrName);
    }
    predicate.apply(this);
}
Also used : APredicateAttributeOperationAttribute(de.be4.classicalb.core.parser.node.APredicateAttributeOperationAttribute) ARuleOperation(de.be4.classicalb.core.parser.node.ARuleOperation) AFunctionOperation(de.be4.classicalb.core.parser.node.AFunctionOperation) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) PPredicate(de.be4.classicalb.core.parser.node.PPredicate)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)1 AFunctionOperation (de.be4.classicalb.core.parser.node.AFunctionOperation)1 APredicateAttributeOperationAttribute (de.be4.classicalb.core.parser.node.APredicateAttributeOperationAttribute)1 ARuleOperation (de.be4.classicalb.core.parser.node.ARuleOperation)1 PPredicate (de.be4.classicalb.core.parser.node.PPredicate)1