String fileName = "JapePlusExtended_" + grammarfile.getName().replaceAll("\\.jape$","") + Gate.genSym() + ".jape";
//System.out.println("Generated file name: "+fileName);
try {
generatedFileURL = new File(tmpDir,fileName).toURI().toURL();
} catch (MalformedURLException ex) {
throw new ResourceInstantiationException("Cannot create generated file URL for "+tmpDir+" / "+fileName);
}
}
String jape = "";
try {
jape = readURL2String(originalURL,encoding);
} catch (IOException ex) {
throw new ResourceInstantiationException("Could not read grammar file "+originalURL,ex);
}
//System.out.println("Got jape file: \n"+jape);
ST template = new ST(jape,'$','$');
//System.out.println("Created template");
//System.out.println("regenerating: variables="+variables);
//System.out.println("regenerating: parameters="+parameters);
//System.out.println("regenerating: vs="+vs);
for(Object key : vs.keySet()) {
if(key instanceof String) {
//System.out.println("Setting key/val: "+key+"/"+vs.get(key));
template.add((String)key, vs.get(key));
} else {
System.err.println("Ignored parameter for template (not a String): "+
key+"="+vs.get(key).toString());
}
}
String result = template.render();
//System.out.println("Rendered template: \n"+result);
File generatedFile = Files.fileFromURL(generatedFileURL);
System.out.println("Generated grammar file: "+generatedFile);
try {
FileUtils.writeStringToFile(generatedFile, result, encoding);
} catch (IOException ex) {
throw new ResourceInstantiationException("Could not write to file "+generatedFile,ex);
}
return generatedFileURL;
}