Search in sources :

Example 16 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException 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 17 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException 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 18 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException 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 19 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.

the class RulesMachineChecker method runChecks.

public void runChecks() throws BCompoundException {
    start.apply(this);
    if (!errorList.isEmpty()) {
        final List<BException> bExceptionList = new ArrayList<>();
        final String filePath = file == null ? "UnknownFile" : file.getAbsolutePath();
        for (CheckException checkException : errorList) {
            final BException bException = new BException(filePath, checkException);
            bExceptionList.add(bException);
        }
        throw new BCompoundException(bExceptionList);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) ArrayList(java.util.ArrayList) BException(de.be4.classicalb.core.parser.exceptions.BException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException)

Example 20 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException in project probparsers by bendisposto.

the class RulesMachineChecker method caseAMachineHeader.

@Override
public void caseAMachineHeader(AMachineHeader node) {
    if (!node.getParameters().isEmpty()) {
        errorList.add(new CheckException("A RULES_MACHINE must not have any machine parameters", node));
    }
    LinkedList<TIdentifierLiteral> nameList = node.getName();
    if (nameList.size() > 1) {
        errorList.add(new CheckException("Renaming of a RULES_MACHINE name is not allowed.", node));
    }
    this.nameLiteral = nameList.get(0);
    this.machineName = nameLiteral.getText();
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)78 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)19 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)17 PExpression (de.be4.classicalb.core.parser.node.PExpression)16 Test (org.junit.Test)15 BException (de.be4.classicalb.core.parser.exceptions.BException)14 ArrayList (java.util.ArrayList)13 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)12 Ast2String (util.Ast2String)10 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)9 Node (de.be4.classicalb.core.parser.node.Node)8 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)8 File (java.io.File)8 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 ARuleOperation (de.be4.classicalb.core.parser.node.ARuleOperation)4 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)4 Helpers.getTreeAsString (util.Helpers.getTreeAsString)4 Type (de.be4.classicalb.core.parser.IDefinitions.Type)3 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)3