Search in sources :

Example 26 with PExpression

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

the class RulesMachineChecker method caseAVarSubstitution.

@Override
public void caseAVarSubstitution(AVarSubstitution node) {
    final HashSet<String> variables = new HashSet<>();
    LinkedList<PExpression> identifiers = node.getIdentifiers();
    for (PExpression e : identifiers) {
        if (e instanceof AIdentifierExpression) {
            AIdentifierExpression id = (AIdentifierExpression) e;
            String name = id.getIdentifier().get(0).getText();
            variables.add(name);
        } else {
            errorList.add(new CheckException("There must be a list of identifiers in VAR substitution.", node));
        }
    }
    this.identifierScope.createNewScope(new LinkedList<PExpression>(node.getIdentifiers()), true);
    node.getSubstitution().apply(this);
    this.identifierScope.removeScope();
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression) HashSet(java.util.HashSet)

Example 27 with PExpression

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

the class RulesMachineChecker method checkStringFormatOperator.

private void checkStringFormatOperator(AOperatorExpression node, final LinkedList<PExpression> parameters) {
    PExpression firstParam = parameters.get(0);
    Integer count = countPlaceHoldersInExpression(firstParam);
    if (count != null && count != parameters.size() - 1) {
        this.errorList.add(new CheckException("The number of arguments (" + (parameters.size() - 1) + ") does not match the number of placeholders (" + count + ") in the string.", node));
    }
    LinkedList<PExpression> identifiers = node.getIdentifiers();
    for (PExpression pExpression : identifiers) {
        pExpression.apply(this);
    }
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 28 with PExpression

use of de.be4.classicalb.core.parser.node.PExpression 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 29 with PExpression

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

the class RulesMachineChecker method caseAForallSubMessageSubstitution.

@Override
public void caseAForallSubMessageSubstitution(AForallSubMessageSubstitution node) {
    if (!isInRule()) {
        errorList.add(new CheckException("RULE_FORALL used outside of a RULE operation", node));
        return;
    }
    this.identifierScope.createNewScope(new LinkedList<PExpression>(node.getIdentifiers()));
    node.getWhere().apply(this);
    node.getExpect().apply(this);
    node.getMessage().apply(this);
    this.identifierScope.removeScope();
    checkErrorType(node.getErrorType());
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 30 with PExpression

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

the class RulesMachineChecker method inAOperationCallSubstitution.

@Override
public void inAOperationCallSubstitution(AOperationCallSubstitution node) {
    LinkedList<TIdentifierLiteral> opNameList = node.getOperation();
    if (opNameList.size() > 1) {
        errorList.add(new CheckException("Renaming of operation names is not allowed.", node));
    }
    List<PExpression> copy = new ArrayList<>(node.getResultIdentifiers());
    checkThatIdentifiersAreLocalVariables(copy);
    if (currentOperation != null) {
        currentOperation.addFunctionCall(opNameList.get(0));
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Aggregations

PExpression (de.be4.classicalb.core.parser.node.PExpression)50 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)28 ArrayList (java.util.ArrayList)27 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)21 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 Test (org.junit.Test)6 Node (de.be4.classicalb.core.parser.node.Node)5 LinkedList (java.util.LinkedList)5 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)4 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)4 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)4 PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)4 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)3 ADefinitionExpression (de.be4.classicalb.core.parser.node.ADefinitionExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 Start (de.be4.classicalb.core.parser.node.Start)3 BParser (de.be4.classicalb.core.parser.BParser)2 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)2 AMachineReference (de.be4.classicalb.core.parser.node.AMachineReference)2 AOpSubstitution (de.be4.classicalb.core.parser.node.AOpSubstitution)2