Search in sources :

Example 1 with RuleOperation

use of de.be4.classicalb.core.parser.rules.RuleOperation 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)

Example 2 with RuleOperation

use of de.be4.classicalb.core.parser.rules.RuleOperation in project probparsers by bendisposto.

the class RulesMachineChecker method checkClassificationAttribute.

private void checkClassificationAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
    if (currentOperation instanceof RuleOperation) {
        final RuleOperation rule = (RuleOperation) currentOperation;
        if (arguments.size() == 1 && arguments.get(0) instanceof AIdentifierExpression) {
            AIdentifierExpression identifier = (AIdentifierExpression) arguments.get(0);
            String identifierString = Utils.getTIdentifierListAsString(identifier.getIdentifier());
            rule.setClassification(identifierString);
        } else {
            errorList.add(new CheckException("Expected exactly one identifier after CLASSIFICATION.", pOperationAttribute));
        }
    } else {
        errorList.add(new CheckException("CLASSIFICATION is not an attribute of a FUNCTION or COMPUTATION operation.", pOperationAttribute));
    }
    return;
}
Also used : ARuleOperation(de.be4.classicalb.core.parser.node.ARuleOperation) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression)

Example 3 with RuleOperation

use of de.be4.classicalb.core.parser.rules.RuleOperation in project probparsers by bendisposto.

the class RulesProject method checkReferencedRuleOperations.

public void checkReferencedRuleOperations() {
    if (this.hasErrors()) {
        return;
    }
    final HashMap<String, RulesParseUnit> map = new HashMap<>();
    for (IModel model : bModels) {
        RulesParseUnit parseUnit = (RulesParseUnit) model;
        map.put(parseUnit.getMachineName(), parseUnit);
    }
    for (IModel model : bModels) {
        if (model instanceof RulesParseUnit) {
            RulesParseUnit rulesParseUnit = (RulesParseUnit) model;
            Set<AIdentifierExpression> referencedRuleOperations = rulesParseUnit.getRulesMachineChecker().getReferencedRuleOperations();
            final HashSet<String> knownRules = new HashSet<>();
            for (RuleOperation ruleOperation : rulesParseUnit.getRulesMachineChecker().getRuleOperations()) {
                knownRules.add(ruleOperation.getName());
            }
            for (RulesMachineReference rulesMachineReference : rulesParseUnit.getMachineReferences()) {
                String referenceName = rulesMachineReference.getName();
                RulesParseUnit otherParseUnit = map.get(referenceName);
                for (RuleOperation ruleOperation : otherParseUnit.getRulesMachineChecker().getRuleOperations()) {
                    knownRules.add(ruleOperation.getName());
                }
            }
            for (AIdentifierExpression aIdentifierExpression : referencedRuleOperations) {
                String ruleName = Utils.getAIdentifierAsString(aIdentifierExpression);
                if (!knownRules.contains(ruleName)) {
                    this.bExceptionList.add(new BException(rulesParseUnit.getPath(), new CheckException("Unknown rule '" + ruleName + "'.", aIdentifierExpression)));
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) BException(de.be4.classicalb.core.parser.exceptions.BException) HashSet(java.util.HashSet)

Example 4 with RuleOperation

use of de.be4.classicalb.core.parser.rules.RuleOperation in project probparsers by bendisposto.

the class RulesProject method checkDependsOnRules.

private void checkDependsOnRules(AbstractOperation operation) {
    boolean errorOccured = false;
    for (AIdentifierExpression aIdentifierExpression : operation.getDependsOnRulesList()) {
        final String name = aIdentifierExpression.getIdentifier().get(0).getText();
        if (allOperations.containsKey(name)) {
            AbstractOperation abstractOperation = allOperations.get(name);
            if (!(abstractOperation instanceof RuleOperation)) {
                this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Operation '" + name + "' is not a RULE operation.", aIdentifierExpression)));
                errorOccured = true;
            }
        } else {
            errorOccured = true;
            this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Unknown operation: '" + name + "'.", aIdentifierExpression)));
        }
    }
    if (!errorOccured) {
        checkVisibilityOfAIdentifierList(operation, operation.getDependsOnRulesList());
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 5 with RuleOperation

use of de.be4.classicalb.core.parser.rules.RuleOperation 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)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)8 ARuleOperation (de.be4.classicalb.core.parser.node.ARuleOperation)4 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)3 RuleOperation (de.be4.classicalb.core.parser.rules.RuleOperation)3 BException (de.be4.classicalb.core.parser.exceptions.BException)2 AbstractOperation (de.be4.classicalb.core.parser.rules.AbstractOperation)2 RuleResult (de.prob.model.brules.RuleResult)2 RuleResults (de.prob.model.brules.RuleResults)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AFunctionOperation (de.be4.classicalb.core.parser.node.AFunctionOperation)1 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)1 APredicateAttributeOperationAttribute (de.be4.classicalb.core.parser.node.APredicateAttributeOperationAttribute)1 PPredicate (de.be4.classicalb.core.parser.node.PPredicate)1 ComputationOperation (de.be4.classicalb.core.parser.rules.ComputationOperation)1 RulesProject (de.be4.classicalb.core.parser.rules.RulesProject)1 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)1 IEvalElement (de.prob.animator.domainobjects.IEvalElement)1 ResultSummary (de.prob.model.brules.RuleResults.ResultSummary)1 RulesMachineRun (de.prob.model.brules.RulesMachineRun)1