Search in sources :

Example 21 with AIdentifierExpression

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

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

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

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

the class RulesProject method checkReferencedRuleOperations.

public void checkReferencedRuleOperations() {
    if (this.hasErrors()) {
        return;
    }
    final HashMap<String, RulesParseUnit> map = new HashMap<>();
    for (IModel model : bModels) {
        RulesParseUnit parseUnit = (RulesParseUnit) model;
        map.put(parseUnit.getMachineName(), parseUnit);
    }
    for (IModel model : bModels) {
        if (model instanceof RulesParseUnit) {
            RulesParseUnit rulesParseUnit = (RulesParseUnit) model;
            Set<AIdentifierExpression> referencedRuleOperations = rulesParseUnit.getRulesMachineChecker().getReferencedRuleOperations();
            final HashSet<String> knownRules = new HashSet<>();
            for (RuleOperation ruleOperation : rulesParseUnit.getRulesMachineChecker().getRuleOperations()) {
                knownRules.add(ruleOperation.getName());
            }
            for (RulesMachineReference rulesMachineReference : rulesParseUnit.getMachineReferences()) {
                String referenceName = rulesMachineReference.getName();
                RulesParseUnit otherParseUnit = map.get(referenceName);
                for (RuleOperation ruleOperation : otherParseUnit.getRulesMachineChecker().getRuleOperations()) {
                    knownRules.add(ruleOperation.getName());
                }
            }
            for (AIdentifierExpression aIdentifierExpression : referencedRuleOperations) {
                String ruleName = Utils.getAIdentifierAsString(aIdentifierExpression);
                if (!knownRules.contains(ruleName)) {
                    this.bExceptionList.add(new BException(rulesParseUnit.getPath(), new CheckException("Unknown rule '" + ruleName + "'.", aIdentifierExpression)));
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) BException(de.be4.classicalb.core.parser.exceptions.BException) HashSet(java.util.HashSet)

Example 25 with AIdentifierExpression

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

the class RulesProject method checkDependsOnComputations.

private void checkDependsOnComputations(AbstractOperation operation) {
    boolean errorOccured = false;
    for (AIdentifierExpression aIdentifierExpression : operation.getDependsOnComputationList()) {
        final String name = aIdentifierExpression.getIdentifier().get(0).getText();
        if (allOperations.containsKey(name)) {
            AbstractOperation abstractOperation = allOperations.get(name);
            if (!(abstractOperation instanceof ComputationOperation)) {
                this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Identifier '" + name + "' is not a COMPUTATION.", aIdentifierExpression)));
                errorOccured = true;
            }
        } else {
            errorOccured = true;
            this.bExceptionList.add(new BException(operation.getFileName(), new CheckException("Unknown operation: '" + name + "'.", aIdentifierExpression)));
        }
    }
    if (!errorOccured) {
        checkVisibilityOfAIdentifierList(operation, operation.getDependsOnComputationList());
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) BException(de.be4.classicalb.core.parser.exceptions.BException)

Aggregations

AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)43 PExpression (de.be4.classicalb.core.parser.node.PExpression)27 ArrayList (java.util.ArrayList)25 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)22 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)14 Node (de.be4.classicalb.core.parser.node.Node)5 Test (org.junit.Test)5 BException (de.be4.classicalb.core.parser.exceptions.BException)4 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 AExpressionDefinitionDefinition (de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition)3 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)3 AIntegerExpression (de.be4.classicalb.core.parser.node.AIntegerExpression)3 AStringExpression (de.be4.classicalb.core.parser.node.AStringExpression)3 BParser (de.be4.classicalb.core.parser.BParser)2 IDefinitions (de.be4.classicalb.core.parser.IDefinitions)2 Type (de.be4.classicalb.core.parser.IDefinitions.Type)2 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)2 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)2