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