use of de.be4.classicalb.core.parser.node.AIdentifierExpression 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.node.AIdentifierExpression in project probparsers by bendisposto.
the class RulesProject method checkVisibilityOfAIdentifierList.
private void checkVisibilityOfAIdentifierList(AbstractOperation operation, List<AIdentifierExpression> dependencyList) {
List<TIdentifierLiteral> tidentifierList = new ArrayList<>();
for (AIdentifierExpression aIdentifier : dependencyList) {
tidentifierList.add(aIdentifier.getIdentifier().get(0));
}
checkVisibilityOfTIdentifierList(operation, tidentifierList);
}
use of de.be4.classicalb.core.parser.node.AIdentifierExpression 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.AIdentifierExpression in project probparsers by bendisposto.
the class RulesTransformation method translateGetRuleCounterExamplesOperator.
private void translateGetRuleCounterExamplesOperator(AOperatorExpression node) {
final PExpression pExpression = node.getIdentifiers().get(0);
final AIdentifierExpression id = (AIdentifierExpression) pExpression;
final String ruleName = id.getIdentifier().get(0).getText();
final 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;
final String name = id.getIdentifier().get(0).getText() + RULE_COUNTER_EXAMPLE_VARIABLE_SUFFIX;
if (node.getIdentifiers().size() == 1) {
final AIdentifierExpression ctVariable = createIdentifier(name, pExpression);
final ARangeExpression range = createPositinedNode(new ARangeExpression(ctVariable), node);
node.replaceBy(range);
} else {
PExpression funcCall = getSetOfErrorMessagesByErrorType(name, node.getIdentifiers().get(1), rule.getNumberOfErrorTypes());
node.replaceBy(funcCall);
}
return;
}
use of de.be4.classicalb.core.parser.node.AIdentifierExpression in project probparsers by bendisposto.
the class SourcePositionsTest method testVariablesSourcePositions.
@Test
public void testVariablesSourcePositions() throws Exception {
final String testMachine = "MACHINE test\n" + "VARIABLES\n" + " xx,\n" + " yy\n" + "INVARIANT xx:INT & yy:INT\n" + "INITIALISATION xx,yy:=0,0\n" + "END\n";
final Start result = getAst(testMachine);
final AAbstractMachineParseUnit machine = (AAbstractMachineParseUnit) result.getPParseUnit();
AVariablesMachineClause variables = null;
for (final PMachineClause clause : machine.getMachineClauses()) {
if (clause instanceof AVariablesMachineClause) {
variables = (AVariablesMachineClause) clause;
break;
}
}
if (variables == null) {
fail("variables clause not found");
}
final LinkedList<PExpression> ids = variables.getIdentifiers();
assertEquals(2, ids.size());
final AIdentifierExpression x = (AIdentifierExpression) ids.get(0);
final AIdentifierExpression y = (AIdentifierExpression) ids.get(1);
// VARIABLES block
assertEquals(2, variables.getStartPos().getLine());
assertEquals(1, variables.getStartPos().getPos());
assertEquals(4, variables.getEndPos().getLine());
assertEquals(7, variables.getEndPos().getPos());
// variable x declaration
assertEquals(3, x.getStartPos().getLine());
assertEquals(3, x.getStartPos().getPos());
assertEquals(3, x.getEndPos().getLine());
assertEquals(5, x.getEndPos().getPos());
// variable y declaration
assertEquals(4, y.getStartPos().getLine());
assertEquals(5, y.getStartPos().getPos());
assertEquals(4, y.getEndPos().getLine());
assertEquals(7, y.getEndPos().getPos());
}
Aggregations