Search in sources :

Example 11 with CheckException

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

the class RulesMachineChecker method checkTagsAttribute.

private void checkTagsAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
    final List<String> tags = new ArrayList<>();
    for (PExpression pExpression : arguments) {
        if (pExpression instanceof AIdentifierExpression) {
            final AIdentifierExpression ident = (AIdentifierExpression) pExpression;
            final String identifierAsString = Utils.getTIdentifierListAsString(ident.getIdentifier());
            tags.add(identifierAsString);
        } else if (pExpression instanceof AStringExpression) {
            final AStringExpression stringExpr = (AStringExpression) pExpression;
            tags.add(stringExpr.getContent().getText());
        } else {
            errorList.add(new CheckException("Expected identifier or string after the TAGS attribute.", pOperationAttribute));
        }
    }
    currentOperation.addTags(tags);
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) AStringExpression(de.be4.classicalb.core.parser.node.AStringExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 12 with CheckException

use of de.be4.classicalb.core.parser.exceptions.CheckException 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;
}
Also used : AIntegerExpression(de.be4.classicalb.core.parser.node.AIntegerExpression) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 13 with CheckException

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

the class RulesMachineChecker method checkDependsOnComputationAttribute.

private void checkDependsOnComputationAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
    List<AIdentifierExpression> list = new ArrayList<>();
    for (PExpression pExpression : arguments) {
        if (pExpression instanceof AIdentifierExpression) {
            list.add((AIdentifierExpression) pExpression);
        } else {
            errorList.add(new CheckException("Expected a list of identifiers after DEPENDS_ON_COMPUTATION.", pOperationAttribute));
        }
    }
    currentOperation.addAllComputationDependencies(list);
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) ArrayList(java.util.ArrayList) PExpression(de.be4.classicalb.core.parser.node.PExpression)

Example 14 with CheckException

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

the class RulesMachineChecker method checkReplacesAttribute.

private void checkReplacesAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
    if (arguments.size() != 1 || !(arguments.get(0) instanceof AIdentifierExpression)) {
        errorList.add(new CheckException("Expected exactly one identifier after REPLACES.", pOperationAttribute));
        return;
    }
    final AIdentifierExpression idExpr = (AIdentifierExpression) arguments.get(0);
    currentOperation.addReplacesIdentifier(idExpr);
    return;
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression)

Example 15 with CheckException

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

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