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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations