Search in sources :

Example 1 with PSubstitution

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

the class CreateFreetypeTest method createSimpleAdd.

private AOperation createSimpleAdd(String name) {
    final ASetExtensionExpression newVal = new ASetExtensionExpression(createIdentifiers(CONS_EMPTY));
    final PSubstitution subst = createAssignment(VAR_NAME, new AUnionExpression(createIdentifier(VAR_NAME), newVal));
    return new AOperation(EMPTY_EXPRS, createIdLits(name), EMPTY_EXPRS, subst);
}
Also used : AUnionExpression(de.be4.classicalb.core.parser.node.AUnionExpression) ASetExtensionExpression(de.be4.classicalb.core.parser.node.ASetExtensionExpression) AOperation(de.be4.classicalb.core.parser.node.AOperation) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution)

Example 2 with PSubstitution

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

the class ASTBuilder method createSequenceSubstitution.

public static PSubstitution createSequenceSubstitution(PSubstitution sub1, PSubstitution sub2, PSubstitution... subs) {
    List<PSubstitution> subList = new ArrayList<>();
    subList.add(sub1);
    subList.add(sub2);
    for (PSubstitution pSubstitution : subs) {
        subList.add(pSubstitution);
    }
    return new ASequenceSubstitution(subList);
}
Also used : PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) ArrayList(java.util.ArrayList) ASequenceSubstitution(de.be4.classicalb.core.parser.node.ASequenceSubstitution)

Example 3 with PSubstitution

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

the class OpSubstitutions method setTypeSubstDef.

private void setTypeSubstDef(final AFuncOpSubstitution node, final String idString) {
    final AExpressionDefinitionDefinition oldDefinition = (AExpressionDefinitionDefinition) definitions.getDefinition(idString);
    final Node defRhs = oldDefinition.getRhs();
    final PSubstitution rhsSubst;
    if (defRhs instanceof AFunctionExpression) {
        final AFunctionExpression rhsFunction = (AFunctionExpression) defRhs;
        rhsSubst = new AOpSubstitution(rhsFunction.getIdentifier(), new LinkedList<PExpression>(rhsFunction.getParameters()));
        rhsSubst.setStartPos(rhsFunction.getStartPos());
        rhsSubst.setEndPos(rhsFunction.getEndPos());
    } else if (defRhs instanceof AIdentifierExpression) {
        final AIdentifierExpression rhsIdent = (AIdentifierExpression) defRhs;
        rhsSubst = new AOpSubstitution(rhsIdent, new LinkedList<PExpression>());
        rhsSubst.setStartPos(rhsIdent.getStartPos());
        rhsSubst.setEndPos(rhsIdent.getEndPos());
    } else {
        // some other expression was parsed (NOT allowed)
        throw new VisitorException(new CheckException("Expecting operation", node));
    }
    final TIdentifierLiteral oldDefId = oldDefinition.getName();
    final TDefLiteralSubstitution defId = new TDefLiteralSubstitution(oldDefId.getText(), oldDefId.getLine(), oldDefId.getPos());
    final ASubstitutionDefinitionDefinition substDef = new ASubstitutionDefinitionDefinition(defId, new LinkedList<PExpression>(oldDefinition.getParameters()), rhsSubst);
    substDef.setStartPos(oldDefinition.getStartPos());
    substDef.setEndPos(oldDefinition.getEndPos());
    definitions.replaceDefinition(idString, Type.Substitution, substDef);
    oldDefinition.replaceBy(substDef);
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TDefLiteralSubstitution(de.be4.classicalb.core.parser.node.TDefLiteralSubstitution) AIdentifierExpression(de.be4.classicalb.core.parser.node.AIdentifierExpression) Node(de.be4.classicalb.core.parser.node.Node) PositionedNode(de.hhu.stups.sablecc.patch.PositionedNode) ASubstitutionDefinitionDefinition(de.be4.classicalb.core.parser.node.ASubstitutionDefinitionDefinition) PExpression(de.be4.classicalb.core.parser.node.PExpression) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) LinkedList(java.util.LinkedList) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) AFunctionExpression(de.be4.classicalb.core.parser.node.AFunctionExpression) AExpressionDefinitionDefinition(de.be4.classicalb.core.parser.node.AExpressionDefinitionDefinition) AOpSubstitution(de.be4.classicalb.core.parser.node.AOpSubstitution) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException)

Example 4 with PSubstitution

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

the class RulesTransformation method outARuleFailSubSubstitution.

@Override
public void outARuleFailSubSubstitution(ARuleFailSubSubstitution node) {
    addForceDefinition(iDefinitions);
    Node newNode = null;
    if (!node.getIdentifiers().isEmpty()) {
        newNode = createPositinedNode(createCounterExampleSubstitutions(node.getIdentifiers(), node.getWhen(), null, node.getMessage(), node.getErrorType()), node);
    } else {
        // default value if no value is provided
        int errorType = 1;
        if (node.getErrorType() != null) {
            errorType = Integer.parseInt(node.getErrorType().getText());
        }
        PSubstitution sub = createCounterExampleSubstitution(errorType, createSetOfPExpression(node.getMessage(), node.getMessage()), false);
        if (node.getWhen() != null) {
            // there is a when predicate but no parameters
            newNode = new AIfSubstitution(node.getWhen(), sub, new ArrayList<PSubstitution>(), null);
        } else {
            // no parameters and no when predicate
            newNode = sub;
        }
    }
    node.replaceBy(newNode);
}
Also used : NodeCloner.cloneNode(de.be4.classicalb.core.parser.util.NodeCloner.cloneNode) ArrayList(java.util.ArrayList)

Example 5 with PSubstitution

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

the class ASTPrologTest method testEvent.

@Test
public void testEvent() throws BCompoundException {
    final AEventBModelParseUnit model = new AEventBModelParseUnit();
    model.setName(new TIdentifierLiteral("mm"));
    final AEventsModelClause events = new AEventsModelClause();
    model.setModelClauses(Arrays.asList((PModelClause) events));
    AEvent event = new AEvent();
    events.setEvent(Arrays.asList((PEvent) event));
    event.setEventName(new TIdentifierLiteral("testevent"));
    event.setVariables(Arrays.asList(createId("param")));
    event.setGuards(Arrays.asList((PPredicate) new ATruthPredicate()));
    PSubstitution subst1 = new AAssignSubstitution(Arrays.asList(createId("x")), Arrays.asList(createId("param")));
    event.setAssignments(Arrays.asList(subst1));
    PWitness witness = new AWitness(new TIdentifierLiteral("ab"), new AEqualPredicate(createId("ab"), createId("y")));
    event.setWitness(Arrays.asList(witness));
    event.setRefines(Arrays.asList(new TIdentifierLiteral("abstract1"), new TIdentifierLiteral("abstract2")));
    checkAST(0, "event_b_model($,mm,[events($,[" + "event($,testevent,[abstract1,abstract2],[identifier($,param)],[truth($)],[]," + "[assign($,[identifier($,x)],[identifier($,param)])]," + "[witness($,identifier(%,ab),equal($,identifier($,ab),identifier($,y)))])])])", model);
}
Also used : AEqualPredicate(de.be4.classicalb.core.parser.node.AEqualPredicate) PModelClause(de.be4.classicalb.core.parser.node.PModelClause) PPredicate(de.be4.classicalb.core.parser.node.PPredicate) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) PEvent(de.be4.classicalb.core.parser.node.PEvent) AEventBModelParseUnit(de.be4.classicalb.core.parser.node.AEventBModelParseUnit) AWitness(de.be4.classicalb.core.parser.node.AWitness) PSubstitution(de.be4.classicalb.core.parser.node.PSubstitution) PWitness(de.be4.classicalb.core.parser.node.PWitness) AEvent(de.be4.classicalb.core.parser.node.AEvent) ATruthPredicate(de.be4.classicalb.core.parser.node.ATruthPredicate) AEventsModelClause(de.be4.classicalb.core.parser.node.AEventsModelClause) AAssignSubstitution(de.be4.classicalb.core.parser.node.AAssignSubstitution) Test(org.junit.Test)

Aggregations

PSubstitution (de.be4.classicalb.core.parser.node.PSubstitution)7 ArrayList (java.util.ArrayList)4 AOperation (de.be4.classicalb.core.parser.node.AOperation)3 PExpression (de.be4.classicalb.core.parser.node.PExpression)3 PPredicate (de.be4.classicalb.core.parser.node.PPredicate)3 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)3 AEvent (de.be4.classicalb.core.parser.node.AEvent)2 AEventsModelClause (de.be4.classicalb.core.parser.node.AEventsModelClause)2 AFunctionExpression (de.be4.classicalb.core.parser.node.AFunctionExpression)2 APreconditionSubstitution (de.be4.classicalb.core.parser.node.APreconditionSubstitution)2 ASetExtensionExpression (de.be4.classicalb.core.parser.node.ASetExtensionExpression)2 AUnionExpression (de.be4.classicalb.core.parser.node.AUnionExpression)2 AWitness (de.be4.classicalb.core.parser.node.AWitness)2 PEvent (de.be4.classicalb.core.parser.node.PEvent)2 PWitness (de.be4.classicalb.core.parser.node.PWitness)2 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)1 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)1 AAssignSubstitution (de.be4.classicalb.core.parser.node.AAssignSubstitution)1 AEqualPredicate (de.be4.classicalb.core.parser.node.AEqualPredicate)1 AEventBModelParseUnit (de.be4.classicalb.core.parser.node.AEventBModelParseUnit)1