use of de.be4.classicalb.core.parser.node.PExpression in project probparsers by bendisposto.
the class OpSubstitutions method replaceWithDefExpression.
private ADefinitionExpression replaceWithDefExpression(final Node node, TIdentifierLiteral identifier, final List<PExpression> paramList) {
final ADefinitionExpression newNode = new ADefinitionExpression();
newNode.setDefLiteral(identifier);
if (paramList != null) {
newNode.setParameters(paramList);
}
final PositionedNode posNode = node;
final PositionedNode newPosNode = newNode;
newPosNode.setStartPos(posNode.getStartPos());
newPosNode.setEndPos(posNode.getEndPos());
node.replaceBy(newNode);
return newNode;
}
use of de.be4.classicalb.core.parser.node.PExpression in project probparsers by bendisposto.
the class OpSubstitutions method caseAFunctionExpression.
@Override
public void caseAFunctionExpression(final AFunctionExpression node) {
if (node.getIdentifier() != null) {
node.getIdentifier().apply(this);
}
if (node.getIdentifier() instanceof ADefinitionExpression && ((ADefinitionExpression) node.getIdentifier()).getParameters().isEmpty()) {
final LinkedList<PExpression> paramList = new LinkedList<>(node.getParameters());
final TIdentifierLiteral identifier = ((ADefinitionExpression) node.getIdentifier()).getDefLiteral();
if (paramList.size() <= definitions.getParameterCount(identifier.getText())) {
/*
* The parameters seem to belong to this definition, so we need
* to replace the FunctionExpression by a
* DefinitionFunctionExpression. If not enough parameters were
* given this will be found by a later check, i.e.
* DefinitionUsageCheck.
*/
final ADefinitionExpression newNode = replaceWithDefExpression(node, identifier, paramList);
final List<PExpression> copy = newNode.getParameters();
for (final PExpression e : copy) {
e.apply(this);
}
return;
}
}
/*
* Reached in case that: Identifier of this FunctionExpression is not a
* definition or there were more parameters than the definition needs
* (by declaration), so we asume the parameters belong to some other
* construct (for example a function a level higher in the AST).
*/
final List<PExpression> copy = node.getParameters();
for (final PExpression e : copy) {
e.apply(this);
}
}
use of de.be4.classicalb.core.parser.node.PExpression in project probparsers by bendisposto.
the class ASTPrologTest method testPartition.
@Test
public void testPartition() {
final PExpression set = createId("set");
final PExpression one = new AIntegerExpression(new TIntegerLiteral("1"));
final PExpression two = new AIntegerExpression(new TIntegerLiteral("2"));
final PExpression three = new AIntegerExpression(new TIntegerLiteral("3"));
final APartitionPredicate pred = new APartitionPredicate(set, Arrays.asList(one, two, three));
final String expected = "partition($,identifier($,set),[integer($,1),integer($,2),integer($,3)])";
checkAST(0, expected, pred);
}
use of de.be4.classicalb.core.parser.node.PExpression in project probparsers by bendisposto.
the class CreateFreetypeTest method createAdd.
private AOperation createAdd(String name, String param, PExpression type, String cons) {
final AMemberPredicate pre = new AMemberPredicate(createIdentifier(param), type);
final ASetExtensionExpression newVal = new ASetExtensionExpression(Arrays.<PExpression>asList(new AFunctionExpression(createIdentifier(cons), createIdentifiers(param))));
final PSubstitution subst = new APreconditionSubstitution(pre, createAssignment(VAR_NAME, new AUnionExpression(createIdentifier(VAR_NAME), newVal)));
return new AOperation(EMPTY_EXPRS, createIdLits(name), createIdentifiers(param), subst);
}
use of de.be4.classicalb.core.parser.node.PExpression in project probparsers by bendisposto.
the class RulesMachineChecker method countPlaceHoldersInExpression.
private Integer countPlaceHoldersInExpression(PExpression param) {
if (param instanceof AConcatExpression) {
AConcatExpression con = (AConcatExpression) param;
Integer left = countPlaceHoldersInExpression(con.getLeft());
Integer right = countPlaceHoldersInExpression(con.getRight());
if (left == null || right == null) {
return null;
} else {
return left + right;
}
} else if (param instanceof AStringExpression) {
AStringExpression string = (AStringExpression) param;
String content = string.getContent().getText();
String subString = "~w";
return countOccurrences(content, subString);
} else {
return null;
}
}
Aggregations