Hi,

I am trying to use ANTLR and StringTemplate to write an eclipse plugin that
does language transformation. I have a view that takes the text from an
editor and puts the output in another textbox. The problem is that within
the plugin, I don't have access to the template file (EvalPolicy.stg below)
directly. I can get an IFile and read from it but it isn't compatible with
the FileReader and so, I can't pass it to the StringTemplateGroup.

groupFileR = new FileReader(FILEPATH);
StringTemplateGroup templates = new StringTemplateGroup(groupFileR);
// doesn't work because FILEPATH is within a jar etc etc.

I tried reading the whole file in the string and then passing it to the
constructor of StringTemplateGroup but I get the error:

Can't find template policyType.st; group hierarchy is [group EvalPolicy;
showType(type) ::= "something type <type>"
policyType(ptype) ::= <<
<ptype>
>>


Here's what I have in the plugin code

Bundle bundle = Platform.getBundle("ape");
Path path = new Path("src/EvalPolicy.stg");
URL fileURL = FileLocator.find(bundle, path, null);
 InputStream is = null;

try {
is = fileURL.openStream();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}

StringBuilder sb = new StringBuilder();
String line;

try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
is.close();
} catch (IOException e) {
e.printStackTrace();
}

strTemplateGroup = sb.toString();

StringTemplateGroup templates = new StringTemplateGroup(strTemplateGroup);


So, is it possible to create a FileReader through an IFile? If not, how can
I properly pass the string to the overloaded StringTemplateGroup(String)
constructor?

Thanks for the help,

Nauman

PhD Candidate
University of Peshawar
Peshawar, Pakistan

Blog: http://recluze.wordpress.com
Art gallery: http://flickr.com/recluze

Contact number: Use email.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to