*
* @param model Path to the *.model file that contains the Aterm model.
* @param transformationPath Path to the *.str transformation.
*/
private static IStrategoTerm executeTransformation(RelativePath model, RelativePath transformationPath, IStrategoTerm toplevelDecl, Environment environment, STRCommands str, Driver driver) throws IOException, TokenExpectedException, BadTokenException, InvalidParseTableException, SGLRException {
IStrategoTerm modelTerm = ATermCommands.atermFromFile(model.getAbsolutePath());
String strat = "main-" + FileCommands.dropExtension(transformationPath.getRelativePath()).replace('/', '_');
Result transformationResult = ModuleSystemCommands.locateResult(FileCommands.dropExtension(transformationPath.getRelativePath()), environment);
Path trans = str.compile(transformationPath, strat, transformationResult.getTransitiveFileDependencies());
IStrategoTerm transformationInput =
ATermCommands.makeTuple(
modelTerm,
ATermCommands.makeString(FileCommands.dropExtension(model.getRelativePath()), null),
ATermCommands.makeString(FileCommands.dropExtension(transformationPath.getRelativePath()), null));
try {
IStrategoTerm transformedTerm = str.assimilate(strat, trans, transformationInput);
return transformedTerm;
} catch (StrategoException e) {
String msg = "Failed to apply transformation " + transformationPath.getRelativePath() + " to model " + model.getRelativePath() + ": " + e.getMessage();
driver.setErrorMessage(toplevelDecl, msg);
throw new StrategoException(msg);