Search in sources :

Example 21 with PExpression

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

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

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

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

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

the class RulesMachineChecker method checkOperationExpressionAttribute.

private void checkOperationExpressionAttribute(OccurredAttributes occurredAttributes, POperationAttribute pOperationAttribute) throws AssertionError {
    AOperationAttribute attribute = (AOperationAttribute) pOperationAttribute;
    LinkedList<PExpression> arguments = attribute.getArguments();
    String name = attribute.getName().getText();
    occurredAttributes.add(name, pOperationAttribute);
    switch(name) {
        case RulesGrammar.DEPENDS_ON_RULE:
            checkDependsOnRuleAttribute(pOperationAttribute, arguments);
            return;
        case RulesGrammar.DEPENDS_ON_COMPUTATION:
            checkDependsOnComputationAttribute(pOperationAttribute, arguments);
            return;
        case RulesGrammar.RULEID:
            checkRuleIdAttribute(pOperationAttribute, arguments);
            return;
        case RulesGrammar.ERROR_TYPES:
            checkErrorTypesAttribute(pOperationAttribute, arguments);
            return;
        case RulesGrammar.CLASSIFICATION:
            checkClassificationAttribute(pOperationAttribute, arguments);
            return;
        case RulesGrammar.TAGS:
            checkTagsAttribute(pOperationAttribute, arguments);
            return;
        case RulesGrammar.REPLACES:
            checkReplacesAttribute(pOperationAttribute, arguments);
            return;
        default:
            throw new AssertionError("Unexpected operation attribute: " + name);
    }
}
Also used : AOperationAttribute(de.be4.classicalb.core.parser.node.AOperationAttribute) 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