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);
}
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;
}
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)));
}
}
}
}
}
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());
}
}
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);
}
}
Aggregations